Re: [libvirt] [PATCH 04/49] list: Add helpers for listing storage pool objects

2012-07-20 Thread Eric Blake
On 07/20/2012 08:24 AM, Osier Yang wrote:
> src/conf/virobjectlist.c: Add virStoragePoolMatch to filter the
> pools; Add virStoragePoolList to iterate over the pool objects
> with filter.
> 
> src/conf/virobjectlist.h: Declare virStoragePoolMatch,
> virStoragePoolList, and the macros for filters.
> 
> src/libvirt_private.syms: Export helper virStoragePoolList.
> ---
>  src/conf/virobjectlist.c |  118 
> ++
>  src/conf/virobjectlist.h |   36 ++
>  src/libvirt_private.syms |1 +
>  3 files changed, 155 insertions(+), 0 deletions(-)
> 

>  
> +#define MATCH(FLAG) (flags & (FLAG))
> +static bool
> +virStoragePoolMatch (virStoragePoolObjPtr poolobj,

No space before (.

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 03/49] list: Define new API virStorageListALlStoragePools

2012-07-20 Thread Eric Blake
On 07/20/2012 08:24 AM, Osier Yang wrote:
> 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.

> +++ b/include/libvirt/libvirt.h.in
> @@ -2471,6 +2471,38 @@ int 
> virConnectListDefinedStoragePools(virConnectPtr conn,
>int maxnames);
>  
>  /*
> + * virConnectListAllStoragePoolsFlags:
> + *
> + * Flags used to filter the returned pools. Flags in each group
> + * are exclusive attribute for a pool.

In virConnectListAllDomainsFlags, we used a different wording:

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.

> +++ b/src/libvirt.c
> @@ -11215,6 +11215,83 @@ virStoragePoolGetConnect (virStoragePoolPtr pool)
>  }
>  
>  /**
> + * virConnectListAllStoragePools:
> + * @conn: Pointer to the hypervisor connection.
> + * @pools: Pointer to a variable to store the array containing storage pool
> + * objects or NULL if the list is not required (just returns number
> + * of pools).
> + * @flags: bitwise-OR of virConnectListAllStoragePoolsFlags.
> + *
> + * Collect the list of storage pools, and allocate an array to store those
> + * objects. This API solves the race inherent between 
> virConnectListStoragePools
> + * and virConnectListDefinedStoragePools.

It would also be worth enhancing the documentation of those two
functions to point out the race, and cross-reference to this function.
For a prior example, see how commit 747f64ee did things.

> + *
> + * By default, this API covers all storage pools; it is also possible
> + * to return the filtered objects with flags. Filters are provided in groups,
> + * where each group contains bits that describe mutually exclusive attributes
> + * of a storage pool.

The wording in the prior example was:

Normally, all storage pools are returned; however, @flags can be used to
filter the results for a smaller list of targeted pools.  The valid
flags are divided into groups, where each group contains bits that
describe mutually exclusive attributes of a pool, and where all bits
within a group describe all possible pools.

> + *
> + * The first group of @flags is VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE and
> + * VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE to fitler the pools by state.

s/fitler/filter/


> @@ -11256,9 +11333,11 @@ error:
>   * @names: array of char * to fill with pool names (allocated by caller)
>   * @maxnames: size of the names array
>   *
> - * Provides the list of names of active storage pools
> - * upto maxnames. If there are more than maxnames, the
> - * remaining names will be silently ignored.
> + * Provides the list of names of active storage pools upto maxnames.

s/upto/up to/

> + * If there are more than maxnames, the remaining names will be silently
> + * ignored.
> + *
> + * For more control over the results, see virConnectListAllStoragePools().
>   *
>   * Returns 0 on success, -1 on error

This lists the cross-reference, but not the fact that there is an
inherent race.  Based on the prior example, this should be something like:

Returns the number of pools found or -1 in case of error.  Note that
this command is inherently racy; a pool can be started between a call to
virConnectNumOfStoragePools() and this call; you are only guaranteed
that all currently active pools were listed if the return is less than
@maxnames.

> +++ b/src/libvirt_public.syms
> @@ -544,4 +544,9 @@ LIBVIRT_0.9.13 {
>  virDomainSnapshotRef;
>  } LIBVIRT_0.9.11;
>  
> +LIBVIRT_0.9.14 {
> +global:
> +virConnectListAllStoragePools;
> +} LIBVIRT_0.9.13;

Merge conflict with Guido's patch a91067f.  Should be easy to resolve.

-- 
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] build: regenerate .png files

2012-07-20 Thread Eric Blake
We don't expect people to have tools installed to regenerate .png
from .fig by default.  However, since commit 5eb3df8, several
.fig files were updated without regenerating the .png file, and
as a result, 'make dist' ends up regenerating those five files,
or worse, failing because of missing tools.

Additionally, the generation of .png files is nondeterministic
(the resulting files contain a timestamp), which means prior to
this patch, running 'make dist' from two checkouts will end up
producing different tarball contents (two 'make dist' runs will
always produce different tar files, since tarballs also contain
timestamps; but unpacking the tarballs and doing a recursive
diff will show if the contents are unchanged).

Running 'make *.png' in the docs directory and committing the
result means the timestamps are now up-to-date, and 'make dist'
no longer has anything to do.  This gets us closer to the goal
of two checkouts being able to produce the same tarball.

* docs/libvirt-*.png: Regenerate.
---

Found when testing 'make dist' on a machine without ImageMagick
installed (for the 'convert' program).

 docs/libvirt-daemon-arch.png  |  Bin 16479 -> 11624 bytes
 docs/libvirt-driver-arch.png  |  Bin 16835 -> 12555 bytes
 docs/libvirt-net-logical.png  |  Bin 7387 -> 11243 bytes
 docs/libvirt-net-physical.png |  Bin 10666 -> 11336 bytes
 docs/libvirt-object-model.png |  Bin 14327 -> 9559 bytes
 5 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/docs/libvirt-daemon-arch.png b/docs/libvirt-daemon-arch.png
index 
b7ed2f689112e45ffd5b108ed7a03f9808618d96..621a55cdbfebf968ed079e3940b5bd3da22321a1
 100644
GIT binary patch
literal 11624

[actual patch stripped for mailing list length limits - it's just
a regeneration of binary files]

-- 
1.7.10.4

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


Re: [libvirt] [PATCH 00/13] Support hypervisor-threads-pin in vcpupin.

2012-07-20 Thread tangchen
Hi eric,

Would you please take sometime to have a look at these patches ?

Thanks. :)

On 07/10/2012 02:28 PM, tangchen wrote:
> Hi~
> 
> Users can use vcpupin command to bind a vcpu thread to a specific physical 
> cpu.
> But besides vcpu threads, there are alse some other threads created by qemu 
> (known as hypervisor threads) that could not be explicitly bound to physical 
> cpus.
> 
> The first 3 patches are from Wen Congyang, which implement Cgroup for 
> differrent
> hypervisors.
> 
> The other 10 patches implemented hypervisor threads binding, in two ways:
>   1) Use sched_setaffinity() function;
>   2) Use cpuset cgroup.
> 
> 
> A new xml element is introduced, and vcpupin command is improved, see below.
> 
> 1. Introduce new xml elements:
>   
> ..
> 
>   
> 
> 
> 2. Improve vcpupin command to support hypervisor threads binding.
> 
> For example, vm1 has the following configuration:
>   
> 
> 
> 
>   
> 
>   1) query all threads pining
> 
>  # vcpupin vm1
>  VCPU: CPU Affinity
>  --
> 0: 0
> 1: 1
> 
>  Hypervisor: CPU Affinity
>  --
> *: 1
> 
>   2) query hypervisor threads pining only
> 
>  # vcpupin vm1 --hypervisor
>  Hypervisor: CPU Affinity
>  --
> *: 1
> 
>   3) change hypervisor threads pining
> 
>  # vcpupin vm1 --hypervisor 0-1
> 
>  # vcpupin vm1 --hypervisor
>  Hypervisor: CPU Affinity
>  --
> *: 0-1
> 
>  # taskset -p 397
>  pid 397's current affinity mask: 3
> 
> 
> Note: If users want to pin a vcpu thread to pcpu, --vcpu option could no 
> longer be omitted.
> 
> 
> Tang Chen (10):
>   Enable cpuset cgroup and synchronous vcpupin info to cgroup.
>   Support hypervisorpin xml parse.
>   Introduce qemuSetupCgroupHypervisorPin and synchronize hypervisorpin
> info to cgroup.
>   Add qemuProcessSetHypervisorAffinites and set hypervisor threads
> affinities
>   Introduce virDomainHypervisorPinAdd and virDomainHypervisorPinDel
> functions
>   Introduce qemudDomainPinHypervisorFlags and
> qemudDomainGetHypervisorPinInfo in qemu driver.
>   Introduce remoteDomainPinHypervisorFlags and
> remoteDomainGetHypervisorPinInfo functions in remote driver.
>   Introduce remoteDispatchDomainPinHypervisorFlags and
> remoteDispatchDomainGetHypervisorPinInfo functions.
>   Introduce virDomainPinHypervisorFlags and
> virDomainGetHypervisorPinInfo functions.
>   Improve vcpupin to support hypervisorpin dynically.
> 
> Wen Congyang (3):
>   Introduce the function virCgroupForHypervisor
>   Introduce the function virCgroupMoveTask
>   create a new cgroup and move all hypervisor threads to the new cgroup
> 
>  .gnulib |2 +-
>  daemon/remote.c |  103 +
>  docs/schemas/domaincommon.rng   |7 +
>  include/libvirt/libvirt.h.in|   10 +
>  src/conf/domain_conf.c  |  173 ++-
>  src/conf/domain_conf.h  |7 +
>  src/driver.h|   13 ++
>  src/libvirt.c   |  147 +
>  src/libvirt_private.syms|7 +
>  src/libvirt_public.syms |2 +
>  src/qemu/qemu_cgroup.c  |  147 -
>  src/qemu/qemu_cgroup.h  |5 +
>  src/qemu/qemu_driver.c  |  261 
> ++-
>  src/qemu/qemu_process.c |   60 +-
>  src/remote/remote_driver.c  |  102 +
>  src/remote/remote_protocol.x|   23 +-
>  src/remote_protocol-structs |   24 +++
>  src/util/cgroup.c   |  204 +-
>  src/util/cgroup.h   |   15 ++
>  tests/qemuxml2argvdata/qemuxml2argv-cputune.xml |1 +
>  tests/vcpupin   |6 +-
>  tools/virsh.c   |  147 -
>  tools/virsh.pod |   16 +-
>  23 files changed, 1405 insertions(+), 77 deletions(-)
> 

-- 
Best Regards,
Tang chen

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


Re: [libvirt] [PATCH] tests: reduce length of nodeinfodata test names

2012-07-20 Thread Laine Stump
On 07/20/2012 03:34 PM, Eric Blake wrote:
> Commit ddd6bef4 fixed an issue where 'make dist' failed to create
> a tarball because we have files with relative names longer than
> 100 bytes by the time you include a 'libvirt-0.9.13' prefix, by
> switching to the ustart format.  Unfortunately, even with ustar
> format, the use of 'tar -ch' with symbolic links that resolve to
> a file name too long also fails (omitting the -h works, but automake
> automatically passes -h); such symlinks were added in commit
> 6dcf98c, which resulted in 'make dist' breaking again.  The solution
> is to rename the offending symlinks to something shorter, by
> shortening the entire nodeinfodata naming scheme.

As the first person (I think) who encountered this problem, I can verify
that Eric has shortened the paths enough for the build to be successful.
(Thanks!)

In case anyone was curious, it turns out that, while ustar format
lengthens the "name" field of the header from 100 bytes to 255 bytes, it
doesn't do anything for the "link_name" field, which remains at the
traditional tar's 100 bytes. When you tell tar "-h" to follow symlinks
and dump the file they point to rather than just recording the link, the
way that tar does this is to resolve the link, then do a lookup in the
list of files that have already been dumped into the tarfile; if a match
is found, the full name (as recorded the first time it was dumped) of
the originally dumped file is written to the "link_name" field rather
than storing another entire copy of the file into the tarfile. So,
"name" contains the full name of the symlink, and "link_name" contains
the full name of the original file. The result is that the full path of
the file pointed to by the symlink cannot be > 100 characters.

(Even in the case that the original symlink was a very short relative
link, that could resolve to a very long pathname. This explains why
there was no failure when "-h" wasn't specified - in that case
"link_name" of the failures cases was a "very short relative link", so
it was successful.)

>
> * tests/nodeinfotest.c (mymain): Shorten test names.
> (linuxTestNodeInfo): Accommodate new names.
> * tests/nodeinfodata/*: Rename files accordingly.
> ---
>
> This LOOKS huge, but is really just a couple of 'git mv' commands
> and a change to nodeinfotest.c.  Scroll to the bottom for the
> real change; I've shortened boring parts of this mail to get past
> the 100k mail cap enforced by the list.
>
>  ...fs-test-1-ppc.cpuinfo => linux-ppc-test1.cpuinfo} |0
>  ...1-cpu-ppc-output.txt => linux-ppc-test1.expected} |0
>  .../cpu/cpu0/online  |0
> ...
>  ...5-cpu-x86-output.txt => linux-x86-test5.expected} |0
>  ...fs-test-6-x86.cpuinfo => linux-x86-test6.cpuinfo} |0
>  ...6-cpu-x86-output.txt => linux-x86-test6.expected} |0
>  tests/nodeinfotest.c |   18 
> +-
>  447 files changed, 9 insertions(+), 9 deletions(-)
>  rename tests/nodeinfodata/{linux-nodeinfo-sysfs-test-1-ppc.cpuinfo => 
> linux-ppc-test1.cpuinfo} (100%)
> ...
> rename from tests/nodeinfodata/linux-nodeinfo-sysfs-test-5-cpu-x86-output.txt
> rename to tests/nodeinfodata/linux-x86-test5.expected
> diff --git a/tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-x86.cpuinfo 
> b/tests/nodeinfodata/linux-x86-test6.cpuinfo
> similarity index 100%
> rename from tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-x86.cpuinfo
> rename to tests/nodeinfodata/linux-x86-test6.cpuinfo
> diff --git 
> a/tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-cpu-x86-output.txt 
> b/tests/nodeinfodata/linux-x86-test6.expected
> similarity index 100%
> rename from tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-cpu-x86-output.txt
> rename to tests/nodeinfodata/linux-x86-test6.expected
> diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
> index 851acd0..c44cc8a 100644
> --- a/tests/nodeinfotest.c
> +++ b/tests/nodeinfotest.c
> @@ -100,9 +100,9 @@ linuxTestNodeInfo(const void *data)
>  if (virAsprintf(&sysfs_dir, "%s/nodeinfodata/linux-%s",
>  abs_srcdir, test) < 0 ||
>  virAsprintf(&cpuinfo, "%s/nodeinfodata/linux-%s-%s.cpuinfo",
> -abs_srcdir, test, arch) < 0 ||
> -virAsprintf(&output, "%s/nodeinfodata/linux-%s-cpu-%s-output.txt",
> -abs_srcdir, test, arch) < 0) {
> +abs_srcdir, arch, test) < 0 ||
> +virAsprintf(&output, "%s/nodeinfodata/linux-%s-%s.expected",
> +abs_srcdir, arch, test) < 0) {
>  goto cleanup;
>  }
>
> @@ -123,14 +123,14 @@ mymain(void)
>  int ret = 0;
>  int i;
>  const char *nodeData[] = {
> -"nodeinfo-sysfs-test-1",
> +"test1",
>  # if !(defined(__powerpc__) ||  \
> defined(__powerpc64__))
> -"nodeinfo-sysfs-test-2",
> -"nodeinfo-sysfs-test-3",
> -"nodeinfo-sysfs-test-4",
> -"nodeinfo-sysfs-test-5",
> -"n

[libvirt] [PATCH] build: update to latest gnulib, for secure tarball

2012-07-20 Thread Eric Blake
Pick up some build fixes in the latest gnulib.  In particular,
we want to ensure that official tarballs are secure, but don't
want to penalize people who don't run 'make dist', since fixed
automake still hasn't hit common platforms like Fedora 17.

* .gnulib: Update to latest, for Automake CVE-2012-3386 detection.
* bootstrap: Resync from gnulib.
* bootstrap.conf (gnulib_extra_files): Drop missing, since gnulib
has dropped it in favor of Automake's version.
* cfg.mk (local-checks-to-skip): Conditionally skip the security
check in cases where it doesn't matter.
---

I'm stoked!  I figured out how to upgrade to the latest automake
and make our release process secure (tested with 'make dist' on
a system with insecure automake), without penalizing normal
development (tested with 'make check' on the same system).

* .gnulib a02ba4b...6c37e0a (76):
  > verify: document conflict with -Wnested-externs
  > maint.mk: forbid exit(-1)
  > fsusage: port back to Solaris
  > gnu-web-doc-update: fix error messages
  > gnu-web-doc-update: check the requirements.
  > maint.mk: minor simplification.
  > gitlog-to-changelog: VPATH build issues.
  > fpending: Assume AC_CHECK_DECLS_ONCE invocation, like in fpending.m4.
  > pthread_sigmask: fix bug on FreeBSD 9
  > README-release: make it more legible
  > autoupdate
  > maint: require that each sc_... command start with "@"
  > maint.mk: add leading "@" to quiet new "make syntax-check" rule
  > autoupdate
  > maint.mk: new syntax check for HAVE_DECL checks
  > argp: make HAVE_DECL usage consistent
  > stat-time: relax license to LGPLv2+
  > strndup: fix m4 usage error
  > maint: enable the sc_avoid_if_before_free syntax-check rule
  > gettext: do not assume '#define ... defined ...' behavior
  > getloadavg: clean out old Emacs and Autoconf cruft
  > bootstrap: let warn be like tests/init.sh's warn_
  > getopt: Simplify after Emacs changed.
  > maint.mk: add sc_vulnerable_makefile_CVE-2012-3386
  > maint.mk: _sc_search_regexp, sc_vulnerable_makefile_CVE-2009-4029: fix
  > getloadavg, getopt: fix commentary re configure.in
  > timespec: mark functions with const attributes
  > canonicalize[-lgpl]: handle "guessing" values when cross-building
  > canonicalize: make the right guess when cross-compiling to GNU
  > update from texinfo
  > timespec-sub: avoid duplicate include
  > bootstrap: use a more consistent error reporting scheme
  > sys_time: allow too-wide tv_sec
  > pthread: check for both pthread_create and pthread_join
  > parse-datetime: doc tuneup
  > do-release-commit-and-tag: fix the previous commit
  > do-release-commit-and-tag: fix typo
  > pthread: check for pthread_create, not pthread_join
  > parse-datetime: fix failure to diagnose invalid input
  > bootstrap: do not require now-removed build-aux/missing
  > alloca: add support for HP NonStop TNS/E native
  > fsusage: remove code not needed on non GNU/Linux systems.
  > fsusage: include files needed for glibc 2.6 fallback
  > fsusage: avoid needless check on GNU/Linux
  > log: Fix an autoconf >= 2.64 warning.
  > autoupdate
  > autoupdate
  > log10f: Fix possible configuration problem.
  > Fix typo in ChangeLog entry.
  > remove: No longer override on all platforms. Fixes bug from 2012-03-20.
  > config: drop scripts that automake says are not independent
  > root-uid: new module
  > regex: use locale-independent comparison for codeset name
  > getopt-posix: No longer guarantee that option processing is resettable.
  > argp, regex: Ensure strcasecmp gets declared.
  > autoupdate
  > ptsname_r: Fix typo in last commit.
  > ptsname_r: Make it consistent with ptsname on AIX.
  > ptsname_r: Make it consistent with ptsname on OSF/1.
  > ttyname_r: Fix result on OSF/1, Solaris.
  > ptsname_r: Add support for Solaris.
  > ptsname_r: Fix test failure on native Windows.
  > ptsname_r: Fix test failures on IRIX, Solaris.
  > ptsname test: Extend test.
  > time: fix obsolete comment
  > getopt-gnu: Handle suboptimal getopt_long's abbreviation handling.
  > time_r: fix typo that always overrode localtime_r decl
  > Write "Mac OS X" instead of "MacOS X".
  > grantpt: Relax requirement regarding invalid file descriptors.
  > fbufmode test: Don't test unportable behaviour.
  > gnulib-tool: Refactor inctests variable.
  > gnulib-tool: --create-[mega]testdir, --[mega]test implies --with-tests.
  > parse-duration test: Avoid spurious output.
  > testing: fix typo in here doc
  > maint: disable the strncpy prohibition
  > Fix misspellings in comments.

 .gnulib|2 +-
 bootstrap  |  118 +---
 bootstrap.conf |1 -
 cfg.mk |   11 ++
 4 files changed, 81 insertions(+), 51 deletions(-)

diff --git a/.gnulib b/.gnulib
index a02ba4b..6c37e0a 16
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit a02ba4bf889fee4622db87f185c3d0af84d74ae7
+Subproject commit 6c37e0a73c7c1b6fe6eac4d794e2e65791a2700d
diff --git a/bootstrap b/bootstrap
index ce37a2c..e3e270

Re: [libvirt] [PATCH 03/13] Rewrite virAtomic APIs using GLib's atomic ops code

2012-07-20 Thread Eric Blake
On 07/20/2012 04:26 PM, Eric Blake wrote:
> +#  define virAtomicIntGet(atomic)   \
> +(__extension__ ({   \
> +verify (sizeof(*(atomic)) == sizeof(int));  \

> within functions, use this instead:
> 
> (void)verify_true(...)

Or this, to give a better error message where possible:

(void) verify_expr (sizeof(*(atomic)) == sizeof(int), "wrong size");

> 
> The cast to void is unfortunately necessary to avoid a -Wall of
> 'statement with no effect'.

Likewise true of verify_expr().

-- 
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 03/13] Rewrite virAtomic APIs using GLib's atomic ops code

2012-07-20 Thread Eric Blake
On 07/20/2012 12:36 AM, Hu Tao wrote:

 +#  define virAtomicIntGet(atomic)   \
 +(__extension__ ({   \
 +verify (sizeof(*(atomic)) == sizeof(int));  \
 +(void) (0 ? *(atomic) ^ *(atomic) : 0); \
 +__sync_synchronize ();  \
 +(int) *(atomic);\
 +}))
>>
>>>
>>> The `verify' lines cause building warnings:
>>>
>>> cc1: warnings being treated as errors
>>> util/virobject.c: In function 'virClassNew':
>>> util/virobject.c:74:99: error: nested extern declaration of 
>>> '_gl_verify_function2' [-Wnested-externs]
>>
>> Which version of gcc?

It turns out this is a problem with any gcc older than 4.6 (that is,
newer gcc with static_assert support no longer triggers this problematic
nested extern).  I was unable to come up with a way to avoid triggering
-Wnested-externs on older gcc without creating conflicting definitions.
 However, it's easy to work around in libvirt.  If -Wnested-externs is
in effect, then restrict the use of verify(...) to the top level
(outside of functions), and within functions, use this instead:

(void)verify_true(...)

The cast to void is unfortunately necessary to avoid a -Wall of
'statement with no effect'.

-- 
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 v3 0/2] ESX: Add routines to interface driver

2012-07-20 Thread Ata E Husain Bohra
Repost of https://www.redhat.com/archives/libvir-list/2012-July/msg00990.html.
Thanks Eric for pointing the message-ID issue with earlier post.

Ata E Husain Bohra (2):
  ESX: Add routines to interface driver
  Use ATTRIBUTE_UNUSED for unused variable.

 src/esx/esx_interface_driver.c |  500 +++-
 src/esx/esx_vi.c   |  126 ++
 src/esx/esx_vi.h   |   10 +
 src/esx/esx_vi_generator.input |  227 ++
 src/esx/esx_vi_generator.py|   31 ++-
 src/esx/esx_vi_types.c |   18 +-
 6 files changed, 907 insertions(+), 5 deletions(-)

-- 
1.7.9.5

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


[libvirt] [PATCH 2/2] Use ATTRIBUTE_UNUSED for unused variable.

2012-07-20 Thread Ata E Husain Bohra
---
 src/esx/esx_interface_driver.c |   14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c
index b1ba5e2..01caed0 100644
--- a/src/esx/esx_interface_driver.c
+++ b/src/esx/esx_interface_driver.c
@@ -107,10 +107,8 @@ cleanup:
 
 
 static int
-esxNumOfDefinedInterfaces(virConnectPtr conn)
+esxNumOfDefinedInterfaces(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
-conn->interfacePrivateData = NULL;
-
 // ESX interfaces are always active
 return 0;
 }
@@ -162,14 +160,10 @@ esxListInterfaces(virConnectPtr conn, char **names, int 
maxnames)
 
 
 static int
-esxListDefinedInterfaces(virConnectPtr conn, char **names, int maxnames)
+esxListDefinedInterfaces(virConnectPtr conn ATTRIBUTE_UNUSED,
+ char **names ATTRIBUTE_UNUSED,
+ int maxnames ATTRIBUTE_UNUSED)
 {
-conn->interfacePrivateData = conn->privateData;
-*names = NULL;
-
-/* keeps compiler happy */
-VIR_DEBUG("max interfaces: %d", maxnames);
-
 // ESX interfaces are always active
 return 0;
 }
-- 
1.7.9.5

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


[libvirt] [PATCH 1/2] ESX: Add routines to interface driver

2012-07-20 Thread Ata E Husain Bohra
Add following routines to esx_interface_driver:
esxNumOfInterfaces,
esxNumOfDefinedInterfaces,
esxListInterfaces,
esxListDefinedInterfaces,
esxInterfaceLookupByMACString,
esxInterfaceGetXMLDesc,
esxInterfaceUndefine,
esxInterfaceCreate,
esxInterfaceDestroy

Signed-off-by: Ata E Husain Bohra 
---
 src/esx/esx_interface_driver.c |  506 +++-
 src/esx/esx_vi.c   |  126 ++
 src/esx/esx_vi.h   |   10 +
 src/esx/esx_vi_generator.input |  227 ++
 src/esx/esx_vi_generator.py|   31 ++-
 src/esx/esx_vi_types.c |   18 +-
 6 files changed, 913 insertions(+), 5 deletions(-)

diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c
index 5713137..b1ba5e2 100644
--- a/src/esx/esx_interface_driver.c
+++ b/src/esx/esx_interface_driver.c
@@ -23,6 +23,9 @@
  */
 
 #include 
+#include 
+#include 
+#include 
 
 #include "internal.h"
 #include "util.h"
@@ -34,6 +37,7 @@
 #include "esx_vi.h"
 #include "esx_vi_methods.h"
 #include "esx_util.h"
+#include "interface_conf.h"
 
 #define VIR_FROM_THIS VIR_FROM_ESX
 
@@ -67,10 +71,508 @@ esxInterfaceClose(virConnectPtr conn)
 
 
 
+static int
+esxNumOfInterfaces(virConnectPtr conn)
+{
+esxPrivate *priv = conn->interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+int count = 0;
+
+if (esxVI_EnsureSession(priv->primary) < 0 ||
+esxVI_LookupVirtualNicList(priv->primary, &virtualNicList) < 0) {
+goto cleanup;
+}
+
+if (virtualNicList == NULL) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+_("Could not retrieve vNic List"));
+
+goto cleanup;
+}
+
+for (virtualNic = virtualNicList;
+ virtualNic != NULL;
+ virtualNic = virtualNic->_next) {
+count++;
+}
+
+cleanup:
+
+esxVI_HostVirtualNic_Free(&virtualNicList);
+
+return count;
+}
+
+
+
+static int
+esxNumOfDefinedInterfaces(virConnectPtr conn)
+{
+conn->interfacePrivateData = NULL;
+
+// ESX interfaces are always active
+return 0;
+}
+
+
+
+static int
+esxListInterfaces(virConnectPtr conn, char **names, int maxnames)
+{
+esxPrivate *priv = conn->interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+int result = -1;
+int i = 0;
+
+if (esxVI_EnsureSession(priv->primary) < 0 ||
+esxVI_LookupVirtualNicList(priv->primary,
+   &virtualNicList) < 0) {
+goto cleanup;
+}
+
+if (virtualNicList == NULL) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+_("Could not retrieve vNIC List"));
+goto cleanup;
+}
+
+for (i= 0, virtualNic = virtualNicList;
+ virtualNic != NULL && i < maxnames;
+ ++i, virtualNic = virtualNic->_next) {
+names[i] = strdup(virtualNic->device);
+
+if (names[i] == NULL) {
+for(;i >=0;--i) {
+VIR_FREE(names[i]);
+}
+virReportOOMError();
+goto cleanup;
+}
+}
+
+result = i;
+ cleanup:
+esxVI_HostVirtualNic_Free(&virtualNicList);
+
+return result;
+}
+
+
+
+static int
+esxListDefinedInterfaces(virConnectPtr conn, char **names, int maxnames)
+{
+conn->interfacePrivateData = conn->privateData;
+*names = NULL;
+
+/* keeps compiler happy */
+VIR_DEBUG("max interfaces: %d", maxnames);
+
+// ESX interfaces are always active
+return 0;
+}
+
+
+
+static virInterfacePtr
+esxInterfaceLookupByName(virConnectPtr conn, const char *name)
+{
+esxPrivate *priv = conn->interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+virInterfacePtr ret = NULL;
+
+if (esxVI_EnsureSession(priv->primary) < 0 ||
+esxVI_LookupVirtualNicList(priv->primary,
+   &virtualNicList) < 0) {
+goto cleanup;
+}
+
+if (virtualNicList == 0) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+_("Could not retrieve vNIC List"));
+goto cleanup;
+}
+
+
+for(virtualNic = virtualNicList;
+virtualNic != NULL;
+virtualNic = virtualNic->_next) {
+if (STREQ(virtualNic->device, name)) {
+if (virtualNic->spec == NULL ||
+virtualNic->spec->mac == NULL) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+  _("Malformed HostVirtualNicSpec"));
+goto cleanup;
+}
+
+ret = virGetInterface(conn, virtualNic->device, 
virtualNic->spec->mac);
+break;
+}
+}
+
+ cleanup:
+esxVI_HostVirtualNic_Free(&virtualNicList);
+
+return ret;
+}
+
+
+
+static virInterfacePtr
+esxInterfaceLookupByMACString(virConnectPtr conn, const c

[libvirt] [PATCH] tests: avoid seclabeltest crash

2012-07-20 Thread Eric Blake
Commit a56c347 introduced a use of random numbers into seclabel
handling, but failed to initialize the random number generator
in the testsuite.

* tests/seclabeltest.c (main): Initialize randomness.
---

Pushing under the build-breaker rule to avoid a SIGSEGV.  I don't
know if Dan's pending patches for one-shot initializer cleanups
will be impacted or make this harder to forget in the future.

 tests/seclabeltest.c |   11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tests/seclabeltest.c b/tests/seclabeltest.c
index 2f65ec1..7283ca1 100644
--- a/tests/seclabeltest.c
+++ b/tests/seclabeltest.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include "security/security_driver.h"
+#include "virrandom.h"

 int
 main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
@@ -13,10 +14,14 @@ main (int argc ATTRIBUTE_UNUSED, char **argv 
ATTRIBUTE_UNUSED)
 virSecurityManagerPtr mgr;
 const char *doi, *model;

+if (virThreadInitialize() < 0 ||
+virRandomInitialize(time(NULL) ^ getpid()))
+exit(1);
+
 mgr = virSecurityManagerNew(NULL, "QEMU", false, true, false);
 if (mgr == NULL) {
 fprintf (stderr, "Failed to start security driver");
-exit (-1);
+exit(1);
 }

 model = virSecurityManagerGetModel(mgr);
@@ -24,7 +29,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
 {
 fprintf (stderr, "Failed to copy secModel model: %s",
  strerror (errno));
-exit (-1);
+exit(1);
 }

 doi = virSecurityManagerGetDOI(mgr);
@@ -32,7 +37,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
 {
 fprintf (stderr, "Failed to copy secModel DOI: %s",
  strerror (errno));
-exit (-1);
+exit(1);
 }

 virSecurityManagerFree(mgr);
-- 
1.7.10.4

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


Re: [libvirt] [PATCHv2 1/5] Add virDomainGetHostname

2012-07-20 Thread Guido Günther
On Wed, Jul 18, 2012 at 09:19:05PM +0100, Daniel P. Berrange wrote:
> On Sun, Jul 15, 2012 at 11:45:05PM +0200, Guido Günther wrote:
> > to query a guests's hostname. Containers like LXC and OpenVZ allow to
> > set a hostname different from the hosts name and QEMU's guest agent
> > could provide similar functionality.
> > ---
> >  include/libvirt/libvirt.h.in |2 ++
> >  src/driver.h |6 ++
> >  src/libvirt.c|   45 
> > ++
> >  src/libvirt_public.syms  |5 +
> >  4 files changed, 58 insertions(+)
> 
> ACK
I've applied the whole series with your suggestions.
Thanks,
 -- Guido

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


Re: [libvirt] [PATCH] tests: reduce length of nodeinfodata test names

2012-07-20 Thread Daniel P. Berrange
On Fri, Jul 20, 2012 at 01:34:36PM -0600, Eric Blake wrote:
> Commit ddd6bef4 fixed an issue where 'make dist' failed to create
> a tarball because we have files with relative names longer than
> 100 bytes by the time you include a 'libvirt-0.9.13' prefix, by
> switching to the ustart format.  Unfortunately, even with ustar
> format, the use of 'tar -ch' with symbolic links that resolve to
> a file name too long also fails (omitting the -h works, but automake
> automatically passes -h); such symlinks were added in commit
> 6dcf98c, which resulted in 'make dist' breaking again.  The solution
> is to rename the offending symlinks to something shorter, by
> shortening the entire nodeinfodata naming scheme.
> 
> * tests/nodeinfotest.c (mymain): Shorten test names.
> (linuxTestNodeInfo): Accommodate new names.
> * tests/nodeinfodata/*: Rename files accordingly.
> ---
> 
> This LOOKS huge, but is really just a couple of 'git mv' commands
> and a change to nodeinfotest.c.  Scroll to the bottom for the
> real change; I've shortened boring parts of this mail to get past
> the 100k mail cap enforced by the list.
> 
>  ...fs-test-1-ppc.cpuinfo => linux-ppc-test1.cpuinfo} |0
>  ...1-cpu-ppc-output.txt => linux-ppc-test1.expected} |0
>  .../cpu/cpu0/online  |0
> ...
>  ...5-cpu-x86-output.txt => linux-x86-test5.expected} |0
>  ...fs-test-6-x86.cpuinfo => linux-x86-test6.cpuinfo} |0
>  ...6-cpu-x86-output.txt => linux-x86-test6.expected} |0
>  tests/nodeinfotest.c |   18 
> +-
>  447 files changed, 9 insertions(+), 9 deletions(-)
>  rename tests/nodeinfodata/{linux-nodeinfo-sysfs-test-1-ppc.cpuinfo => 
> linux-ppc-test1.cpuinfo} (100%)
> ...
> rename from tests/nodeinfodata/linux-nodeinfo-sysfs-test-5-cpu-x86-output.txt
> rename to tests/nodeinfodata/linux-x86-test5.expected
> diff --git a/tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-x86.cpuinfo 
> b/tests/nodeinfodata/linux-x86-test6.cpuinfo
> similarity index 100%
> rename from tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-x86.cpuinfo
> rename to tests/nodeinfodata/linux-x86-test6.cpuinfo
> diff --git 
> a/tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-cpu-x86-output.txt 
> b/tests/nodeinfodata/linux-x86-test6.expected
> similarity index 100%
> rename from tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-cpu-x86-output.txt
> rename to tests/nodeinfodata/linux-x86-test6.expected
> diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
> index 851acd0..c44cc8a 100644
> --- a/tests/nodeinfotest.c
> +++ b/tests/nodeinfotest.c
> @@ -100,9 +100,9 @@ linuxTestNodeInfo(const void *data)
>  if (virAsprintf(&sysfs_dir, "%s/nodeinfodata/linux-%s",
>  abs_srcdir, test) < 0 ||
>  virAsprintf(&cpuinfo, "%s/nodeinfodata/linux-%s-%s.cpuinfo",
> -abs_srcdir, test, arch) < 0 ||
> -virAsprintf(&output, "%s/nodeinfodata/linux-%s-cpu-%s-output.txt",
> -abs_srcdir, test, arch) < 0) {
> +abs_srcdir, arch, test) < 0 ||
> +virAsprintf(&output, "%s/nodeinfodata/linux-%s-%s.expected",
> +abs_srcdir, arch, test) < 0) {
>  goto cleanup;
>  }
> 
> @@ -123,14 +123,14 @@ mymain(void)
>  int ret = 0;
>  int i;
>  const char *nodeData[] = {
> -"nodeinfo-sysfs-test-1",
> +"test1",
>  # if !(defined(__powerpc__) ||  \
> defined(__powerpc64__))
> -"nodeinfo-sysfs-test-2",
> -"nodeinfo-sysfs-test-3",
> -"nodeinfo-sysfs-test-4",
> -"nodeinfo-sysfs-test-5",
> -"nodeinfo-sysfs-test-6",
> +"test2",
> +"test3",
> +"test4",
> +"test5",
> +"test6",
>  # endif
>  };


ACK

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 v8 8/8] parallels: implement VM creation

2012-07-20 Thread Dmitry Guryanov

On 07/20/2012 07:41 PM, Peter Krempa wrote:

On 07/04/12 19:42, Dmitry Guryanov wrote:

To create a new VM in PARALLELS we should issue "prlctl create" command,
and give path to the directory, where VM should be created. VM's
storage will be in that directory later. So in this first version
find out location of first VM's hard disk and create VM there.

Signed-off-by: Dmitry Guryanov 
---
  src/parallels/parallels_driver.c  |   78 
-

  src/parallels/parallels_driver.h  |4 ++
  src/parallels/parallels_storage.c |6 +--
  3 files changed, 82 insertions(+), 6 deletions(-)

diff --git a/src/parallels/parallels_driver.c 
b/src/parallels/parallels_driver.c

index 8c8ddd8..3993228 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1117,6 +1117,74 @@ parallelsApplyChanges(virDomainObjPtr dom, 
virDomainDefPtr newdef)

  return 0;
  }

+static int
+parallelsCreateVm(virConnectPtr conn, virDomainDefPtr def)
+{
+parallelsConnPtr privconn = conn->privateData;
+int i;
+virStorageVolDefPtr privvol = NULL;
+virStoragePoolObjPtr pool = NULL;
+virStorageVolPtr vol = NULL;
+char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+for (i = 0; i < def->ndisks; i++) {
+if (def->disks[i]->device != VIR_DOMAIN_DISK_DEVICE_DISK)
+continue;
+
+vol = parallelsStorageVolumeLookupByPathLocked(conn, 
def->disks[i]->src);

+if (!vol) {
+parallelsError(VIR_ERR_INVALID_ARG,
+ _("Can't find volume with path '%s'"),
+ def->disks[i]->src);
+return -1;
+}
+break;
+}
+
+if (!vol) {
+parallelsError(VIR_ERR_INVALID_ARG,
+ _("Can't create VM without hard disks"));


I'm not quite sure how this is with Parallels Virtuozzo, but it's a 
not-so-uncommon use-case to have a diskless machine. (PXE booted with 
network storage?)


It's not possible to select location of the VM, if the initial XML 
config doesn't include some disks.


We can create VM in default location instead of reporting an error, I 
can change the behaviour in

next version of these patches.





+return -1;
+}
+
+pool = virStoragePoolObjFindByName(&privconn->pools, vol->pool);
+if (!pool) {
+parallelsError(VIR_ERR_INVALID_ARG,
+ _("Can't find storage pool with name '%s'"),
+ vol->pool);
+goto error;
+}
+
+privvol = virStorageVolDefFindByPath(pool, def->disks[i]->src);
+if (!privvol) {
+parallelsError(VIR_ERR_INVALID_ARG,
+ _("Can't find storage volume definition for path 
'%s'"),

+ def->disks[i]->src);
+goto error2;
+}
+
+virUUIDFormat(def->uuid, uuidstr);
+
+if (parallelsCmdRun(PRLCTL, "create", def->name, "--dst",
+  pool->def->target.path, "--no-hdd",
+  "--uuid", uuidstr, NULL) < 0)
+goto error2;
+
+if (parallelsCmdRun(PRLCTL, "set", def->name, "--vnc-mode", 
"auto", NULL) < 0)

+goto error2;
+
+virStoragePoolObjUnlock(pool);
+virUnrefStorageVol(vol);
+
+return 0;
+
+  error2:
+virStoragePoolObjUnlock(pool);
+  error:
+virUnrefStorageVol(vol);
+return -1;
+}
+
  static virDomainPtr
  parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
  {
@@ -1153,8 +1221,16 @@ parallelsDomainDefineXML(virConnectPtr conn, 
const char *xml)


  def = NULL;
  } else {
-parallelsError(VIR_ERR_NO_SUPPORT, _("Not implemented yet"));
+if (parallelsCreateVm(conn, def))
  goto cleanup;
+if (parallelsLoadDomains(privconn, def->name))
+goto cleanup;
+dom = virDomainFindByName(&privconn->domains, def->name);
+if (!dom) {
+parallelsError(VIR_ERR_INTERNAL_ERROR,
+ _("Domain is not defined after creation"));
+goto cleanup;
+}
  }

  event = virDomainEventNewFromObj(dom,
diff --git a/src/parallels/parallels_driver.h 
b/src/parallels/parallels_driver.h

index 6f06ac8..e32ad55 100644
--- a/src/parallels/parallels_driver.h
+++ b/src/parallels/parallels_driver.h
@@ -67,5 +67,9 @@ int parallelsCmdRun(const char *binary, ...) 
ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENT

  char * parallelsAddFileExt(const char *path, const char *ext);
  void parallelsDriverLock(parallelsConnPtr driver);
  void parallelsDriverUnlock(parallelsConnPtr driver);
+virStorageVolPtr parallelsStorageVolumeLookupByPathLocked(virConnectPtr
+ conn,
+ const char
+ *path);


Again, please use a separate header for the driver-internal definitions.



  #endif
diff --git a/src/parallels/parallels_storage.c 
b/src/parallels/parallels_storage.c

index 5a5b366..c86ddaf 100644
--- a/src/parallels/parallels_storage.c
+++ b/src/parallels/parallels_storage.c
@@ -41,10 +41,6 @@ static virStorageVolDefPtr 
parallelsStorageVolumeDefine(virStoragePoolObjPtr poo

 

[libvirt] [PATCH] tests: reduce length of nodeinfodata test names

2012-07-20 Thread Eric Blake
Commit ddd6bef4 fixed an issue where 'make dist' failed to create
a tarball because we have files with relative names longer than
100 bytes by the time you include a 'libvirt-0.9.13' prefix, by
switching to the ustart format.  Unfortunately, even with ustar
format, the use of 'tar -ch' with symbolic links that resolve to
a file name too long also fails (omitting the -h works, but automake
automatically passes -h); such symlinks were added in commit
6dcf98c, which resulted in 'make dist' breaking again.  The solution
is to rename the offending symlinks to something shorter, by
shortening the entire nodeinfodata naming scheme.

* tests/nodeinfotest.c (mymain): Shorten test names.
(linuxTestNodeInfo): Accommodate new names.
* tests/nodeinfodata/*: Rename files accordingly.
---

This LOOKS huge, but is really just a couple of 'git mv' commands
and a change to nodeinfotest.c.  Scroll to the bottom for the
real change; I've shortened boring parts of this mail to get past
the 100k mail cap enforced by the list.

 ...fs-test-1-ppc.cpuinfo => linux-ppc-test1.cpuinfo} |0
 ...1-cpu-ppc-output.txt => linux-ppc-test1.expected} |0
 .../cpu/cpu0/online  |0
...
 ...5-cpu-x86-output.txt => linux-x86-test5.expected} |0
 ...fs-test-6-x86.cpuinfo => linux-x86-test6.cpuinfo} |0
 ...6-cpu-x86-output.txt => linux-x86-test6.expected} |0
 tests/nodeinfotest.c |   18 +-
 447 files changed, 9 insertions(+), 9 deletions(-)
 rename tests/nodeinfodata/{linux-nodeinfo-sysfs-test-1-ppc.cpuinfo => 
linux-ppc-test1.cpuinfo} (100%)
...
rename from tests/nodeinfodata/linux-nodeinfo-sysfs-test-5-cpu-x86-output.txt
rename to tests/nodeinfodata/linux-x86-test5.expected
diff --git a/tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-x86.cpuinfo 
b/tests/nodeinfodata/linux-x86-test6.cpuinfo
similarity index 100%
rename from tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-x86.cpuinfo
rename to tests/nodeinfodata/linux-x86-test6.cpuinfo
diff --git a/tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-cpu-x86-output.txt 
b/tests/nodeinfodata/linux-x86-test6.expected
similarity index 100%
rename from tests/nodeinfodata/linux-nodeinfo-sysfs-test-6-cpu-x86-output.txt
rename to tests/nodeinfodata/linux-x86-test6.expected
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index 851acd0..c44cc8a 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -100,9 +100,9 @@ linuxTestNodeInfo(const void *data)
 if (virAsprintf(&sysfs_dir, "%s/nodeinfodata/linux-%s",
 abs_srcdir, test) < 0 ||
 virAsprintf(&cpuinfo, "%s/nodeinfodata/linux-%s-%s.cpuinfo",
-abs_srcdir, test, arch) < 0 ||
-virAsprintf(&output, "%s/nodeinfodata/linux-%s-cpu-%s-output.txt",
-abs_srcdir, test, arch) < 0) {
+abs_srcdir, arch, test) < 0 ||
+virAsprintf(&output, "%s/nodeinfodata/linux-%s-%s.expected",
+abs_srcdir, arch, test) < 0) {
 goto cleanup;
 }

@@ -123,14 +123,14 @@ mymain(void)
 int ret = 0;
 int i;
 const char *nodeData[] = {
-"nodeinfo-sysfs-test-1",
+"test1",
 # if !(defined(__powerpc__) ||  \
defined(__powerpc64__))
-"nodeinfo-sysfs-test-2",
-"nodeinfo-sysfs-test-3",
-"nodeinfo-sysfs-test-4",
-"nodeinfo-sysfs-test-5",
-"nodeinfo-sysfs-test-6",
+"test2",
+"test3",
+"test4",
+"test5",
+"test6",
 # endif
 };

-- 
1.7.10.4

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


Re: [libvirt] [PATCH v2 3/3] Use a hash table for storing MCS labels

2012-07-20 Thread Daniel P. Berrange
On Fri, Jul 20, 2012 at 11:15:58AM -0600, Eric Blake wrote:
> On 07/20/2012 10:59 AM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" 
> > 
> > Instead of using an O(n) efficiency linked list for storing
> > MCS labels, use a hash table. Instead of having the list
> > be global, put it in the SELinux driver private data struct
> > to ensure uniqueness across different instances of the driver
> 
> Goodness on two fronts - improved efficiency and re-entrancy :)

I expanded the commit message to mention the thread safety aspect
of this.

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 v2 1/3] Use standard naming prefix for SELinux driver function names

2012-07-20 Thread Daniel P. Berrange
On Fri, Jul 20, 2012 at 11:06:40AM -0600, Eric Blake wrote:
> On 07/20/2012 10:59 AM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" 
> > 
> > The function names in the SELinux driver all start with
> > SELinux or 'mcs' as a prefix. Sanitize this so that they
> > all use 'virSecuritySELinux' as the prefix
> > 
> > Signed-off-by: Daniel P. Berrange 
> > ---
> >  src/security/security_selinux.c |  394 
> > ---
> >  1 file changed, 198 insertions(+), 196 deletions(-)
> 
> Mechanical.  ACK.
> 
> > @@ -487,12 +489,12 @@ SELinuxSecurityDriverClose(virSecurityManagerPtr mgr)
> >  }
> >  
> >  
> > -static const char *SELinuxSecurityGetModel(virSecurityManagerPtr mgr 
> > ATTRIBUTE_UNUSED)
> > +static const char 
> > *virSecuritySELinuxSecurityGetModel(virSecurityManagerPtr mgr 
> > ATTRIBUTE_UNUSED)
> 
> For hunks like this, do you want to reformat to:
> 
> static const char *
> virSecuritySELinuxSecurityGetModel(virSecurityManagerPtr mgr
> ATTRIBUTE_UNUSED)
> 
> to avoid the long lines?  But that's cosmetic, and doesn't get in the
> way of my ack.

Yes, I've fixed the long lines here

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/5 v2] Add public API to register a callback to be invoked on connection close

2012-07-20 Thread Eric Blake
On 07/20/2012 08:21 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> Define a new virConnectSetCloseCallback() public API which allows
> registering a callback to be invoked when the connection to a
> hypervisor is closed. The callback is provided with the reason for
> the close, which may be 'error', 'eof' or 'keepalive'.
> 
> Signed-off-by: Daniel P. Berrange 
> ---
>  include/libvirt/libvirt.h.in |   40 +---
>  src/datatypes.c  |4 +++
>  src/datatypes.h  |5 
>  src/libvirt.c|   60 
> ++
>  src/libvirt_public.syms  |6 +
>  5 files changed, 105 insertions(+), 10 deletions(-)
> 
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index e34438c..85d8c8a 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -49,6 +49,17 @@ extern "C" {
>   * defines VIR_ENUM_SENTINELS.  Enumerations for bit values do not
>   * have a *_LAST value, but additional bits may be defined.  */
>  
> +/*
> + * virFreeCallback:
> + * @opaque: opaque user data provided at registration
> + *
> + * Type for a domain event callback when the event is deregistered and
> + * need to be freed, @opaque is provided along with the callback at
> + * registration time
> + */
> +typedef void (*virFreeCallback)(void *opaque);

We're now using this for more than just domain events; the comment needs
a slight update.  Maybe:

Type for a callback cleanup function to be paired with a callback.  This
function will be called as a final chance to clean up the @opaque
registered with the primary callback, at the time when the primary
callback is deregistered.

> +++ b/src/datatypes.c
> @@ -115,6 +115,10 @@ virReleaseConnect(virConnectPtr conn) {
>  
>  virMutexLock(&conn->lock);
>  
> +if (conn->closeOpaque &&
> +conn->closeFreeCallback)
> +conn->closeFreeCallback(conn->closeOpaque);

I'm still not sure I like filtering on NULL opaque.  Our other uses of a
virFreeCallback include src/fdstream.c:virFDStreamRemoveCallback, and
there we call fdst->ff without regards to whether fdst->opaque is null.

> +int virConnectSetCloseCallback(virConnectPtr conn,
> +   virConnectCloseFunc cb,
> +   void *opaque,
> +   virFreeCallback freecb)
> +{
> +VIR_DEBUG("conn=%p", conn);
> +
> +virResetLastError();
> +
> +if (!VIR_IS_CONNECT(conn)) {
> +virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
> +virDispatchError(NULL);
> +return -1;
> +}
> +
> +virMutexLock(&conn->lock);
> +
> +if (conn->closeCallback) {
> +virLibConnError(VIR_ERR_OPERATION_INVALID, "%s",
> +_("A close callback is already registered"));
> +goto error;
> +}

Do we want to allow deregistration of a close callback (we have
virConnectDomainEventDeregister, after all).

-- 
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 02/49] list: Rename virdomainlist.[ch] for common use

2012-07-20 Thread Eric Blake
On 07/20/2012 08:24 AM, Osier Yang wrote:
> Except objects of domains, domain snapshots, we will also add APIs
> to list objects like storage pools, storage vols, network, interface,
> etc. And it's deserved to have the small helper functions in a
> common file instead of in separate files.
> 
> This patch renames virdomainlist.[ch] to virobjectlist.[ch], and
> also renames the macros to filter domain objects more specificly.

s/specificly/specifically/

> 
> src/conf/virdomainlist.c: Renamed to src/conf/virobjectlist.c
> src/conf/virdomainlist.h: Renamed to src/conf/virobjectlist.h

Looks reasonable.

> @@ -31,7 +33,7 @@
>  #include "datatypes.h"
>  #include "virterror_internal.h"
>  
> -#define VIR_FROM_THIS VIR_FROM_DOMAIN
> +#define VIR_FROM_THIS VIR_FROM_NONE

I'm debating whether:

s/VIR_FROM_NONE/VIR_FROM_CONF/

makes sense.  Or maybe you keep the file organized in sections, and
between each section, you:

#undef VIR_FROM_THIS
#define VIR_FROM_THIS VIR_FROM_SECRET
// secret listing
#undef VIR_FROM_THIS
#define VIR_FROM_THIS VIR_FROM_DOMAIN_SNAPSHOT
// snapshot listing

and so forth.  That way, the error messages will be a bit better.

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 v2 3/3] Use a hash table for storing MCS labels

2012-07-20 Thread Eric Blake
On 07/20/2012 10:59 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> Instead of using an O(n) efficiency linked list for storing
> MCS labels, use a hash table. Instead of having the list
> be global, put it in the SELinux driver private data struct
> to ensure uniqueness across different instances of the driver

Goodness on two fronts - improved efficiency and re-entrancy :)

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 v2 2/3] Fix error handling when adding MCS labels

2012-07-20 Thread Eric Blake
On 07/20/2012 10:59 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> When adding MCS labels, OOM was not being handled correctly.
> In addition when reserving an existing label, no check was
> made to see if it was already reserved
> 
> Signed-off-by: Daniel P. Berrange 
> ---
>  src/security/security_selinux.c |   41 
> ++-
>  1 file changed, 32 insertions(+), 9 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 v2 1/3] Use standard naming prefix for SELinux driver function names

2012-07-20 Thread Eric Blake
On 07/20/2012 10:59 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> The function names in the SELinux driver all start with
> SELinux or 'mcs' as a prefix. Sanitize this so that they
> all use 'virSecuritySELinux' as the prefix
> 
> Signed-off-by: Daniel P. Berrange 
> ---
>  src/security/security_selinux.c |  394 
> ---
>  1 file changed, 198 insertions(+), 196 deletions(-)

Mechanical.  ACK.

> @@ -487,12 +489,12 @@ SELinuxSecurityDriverClose(virSecurityManagerPtr mgr)
>  }
>  
>  
> -static const char *SELinuxSecurityGetModel(virSecurityManagerPtr mgr 
> ATTRIBUTE_UNUSED)
> +static const char *virSecuritySELinuxSecurityGetModel(virSecurityManagerPtr 
> mgr ATTRIBUTE_UNUSED)

For hunks like this, do you want to reformat to:

static const char *
virSecuritySELinuxSecurityGetModel(virSecurityManagerPtr mgr
ATTRIBUTE_UNUSED)

to avoid the long lines?  But that's cosmetic, and doesn't get in the
way of my 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 v2 1/3] Use standard naming prefix for SELinux driver function names

2012-07-20 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

The function names in the SELinux driver all start with
SELinux or 'mcs' as a prefix. Sanitize this so that they
all use 'virSecuritySELinux' as the prefix

Signed-off-by: Daniel P. Berrange 
---
 src/security/security_selinux.c |  394 ---
 1 file changed, 198 insertions(+), 196 deletions(-)

diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index a9e704d..b9ca973 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -64,16 +64,18 @@ struct _virSecuritySELinuxCallbackData {
The data struct of used mcs should be replaced with a better data structure 
in the future
 */
 
-struct MCS {
+typedef struct virSecuritySELinuxMCS virSecuritySELinuxMCS;
+typedef virSecuritySELinuxMCS *virSecuritySELinuxMCSPtr;
+struct virSecuritySELinuxMCS {
 char *mcs;
-struct MCS *next;
+virSecuritySELinuxMCSPtr next;
 };
-static struct MCS *mcsList = NULL;
+static virSecuritySELinuxMCSPtr mcsList = NULL;
 
 static int
-mcsAdd(const char *mcs)
+virSecuritySELinuxMCSAdd(const char *mcs)
 {
-struct MCS *ptr;
+virSecuritySELinuxMCSPtr ptr;
 
 for (ptr = mcsList; ptr; ptr = ptr->next) {
 if (STREQ(ptr->mcs, mcs))
@@ -88,10 +90,10 @@ mcsAdd(const char *mcs)
 }
 
 static int
-mcsRemove(const char *mcs)
+virSecuritySELinuxMCSRemove(const char *mcs)
 {
-struct MCS *prevptr = NULL;
-struct MCS *ptr = NULL;
+virSecuritySELinuxMCSPtr prevptr = NULL;
+virSecuritySELinuxMCSPtr ptr = NULL;
 
 for (ptr = mcsList; ptr; ptr = ptr->next) {
 if (STREQ(ptr->mcs, mcs)) {
@@ -110,7 +112,7 @@ mcsRemove(const char *mcs)
 }
 
 static char *
-SELinuxGenNewContext(const char *oldcontext, const char *mcs)
+virSecuritySELinuxGenNewContext(const char *oldcontext, const char *mcs)
 {
 char *newcontext = NULL;
 char *scontext = strdup(oldcontext);
@@ -129,7 +131,7 @@ err:
 
 #ifdef HAVE_SELINUX_LXC_CONTEXTS_PATH
 static int
-SELinuxLXCInitialize(virSecurityManagerPtr mgr)
+virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr)
 {
 virConfValuePtr scon = NULL;
 virConfValuePtr tcon = NULL;
@@ -192,7 +194,7 @@ error:
 }
 #else
 static int
-SELinuxLXCInitialize(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED)
+virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED)
 {
 virReportSystemError(ENOSYS, "%s",
  _("libselinux does not support LXC contexts path"));
@@ -202,7 +204,7 @@ SELinuxLXCInitialize(virSecurityManagerPtr mgr 
ATTRIBUTE_UNUSED)
 
 
 static int
-SELinuxQEMUInitialize(virSecurityManagerPtr mgr)
+virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr)
 {
 char *ptr;
 virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(mgr);
@@ -249,20 +251,20 @@ error:
 
 
 static int
-SELinuxInitialize(virSecurityManagerPtr mgr)
+virSecuritySELinuxInitialize(virSecurityManagerPtr mgr)
 {
 VIR_DEBUG("SELinuxInitialize %s", virSecurityManagerGetDriver(mgr));
 if (STREQ(virSecurityManagerGetDriver(mgr),  "LXC")) {
-return SELinuxLXCInitialize(mgr);
+return virSecuritySELinuxLXCInitialize(mgr);
 } else {
-return SELinuxQEMUInitialize(mgr);
+return virSecuritySELinuxQEMUInitialize(mgr);
 }
 }
 
 
 static int
-SELinuxGenSecurityLabel(virSecurityManagerPtr mgr,
-virDomainDefPtr def)
+virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr mgr,
+   virDomainDefPtr def)
 {
 int rc = -1;
 char *mcs = NULL;
@@ -273,7 +275,7 @@ SELinuxGenSecurityLabel(virSecurityManagerPtr mgr,
 const char *range;
 virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(mgr);
 
-VIR_DEBUG("SELinuxGenSecurityLabel %s", virSecurityManagerGetDriver(mgr));
+VIR_DEBUG("driver=%s", virSecurityManagerGetDriver(mgr));
 if ((def->seclabel.type == VIR_DOMAIN_SECLABEL_DYNAMIC) &&
 !def->seclabel.baselabel &&
 def->seclabel.model) {
@@ -303,7 +305,7 @@ SELinuxGenSecurityLabel(virSecurityManagerPtr mgr,
 return rc;
 }
 
-VIR_DEBUG("SELinuxGenSecurityLabel %d", def->seclabel.type);
+VIR_DEBUG("type=%d", def->seclabel.type);
 
 switch (def->seclabel.type) {
 case VIR_DOMAIN_SECLABEL_STATIC:
@@ -343,12 +345,12 @@ SELinuxGenSecurityLabel(virSecurityManagerPtr mgr,
 goto cleanup;
 }
 }
-} while (mcsAdd(mcs) == -1);
+} while (virSecuritySELinuxMCSAdd(mcs) == -1);
 
 def->seclabel.label =
-SELinuxGenNewContext(def->seclabel.baselabel ?
- def->seclabel.baselabel :
- data->domain_context, mcs);
+virSecuritySELinuxGenNewContext(def->seclabel.baselabel ?
+def->seclabel.baselabel :
+data->domain_context, mcs);
 if (

[libvirt] [PATCH v2 0/3] Misc changes to SELinux driver

2012-07-20 Thread Daniel P. Berrange
This is a repost of

  https://www.redhat.com/archives/libvir-list/2012-May/msg01186.html

No changes except to rebase.

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


[libvirt] [PATCH v2 2/3] Fix error handling when adding MCS labels

2012-07-20 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

When adding MCS labels, OOM was not being handled correctly.
In addition when reserving an existing label, no check was
made to see if it was already reserved

Signed-off-by: Daniel P. Berrange 
---
 src/security/security_selinux.c |   41 ++-
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index b9ca973..34e1b7c 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -72,6 +72,9 @@ struct virSecuritySELinuxMCS {
 };
 static virSecuritySELinuxMCSPtr mcsList = NULL;
 
+/*
+ * Returns 0 on success, 1 if already reserved, or -1 on fatal error
+ */
 static int
 virSecuritySELinuxMCSAdd(const char *mcs)
 {
@@ -79,11 +82,17 @@ virSecuritySELinuxMCSAdd(const char *mcs)
 
 for (ptr = mcsList; ptr; ptr = ptr->next) {
 if (STREQ(ptr->mcs, mcs))
-return -1;
+return 1;
 }
-if (VIR_ALLOC(ptr) < 0)
+if (VIR_ALLOC(ptr) < 0) {
+virReportOOMError();
 return -1;
-ptr->mcs = strdup(mcs);
+}
+if (!(ptr->mcs = strdup(mcs))) {
+virReportOOMError();
+VIR_FREE(ptr);
+return -1;
+}
 ptr->next = mcsList;
 mcsList = ptr;
 return 0;
@@ -325,7 +334,8 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr 
mgr,
 break;
 
 case VIR_DOMAIN_SECLABEL_DYNAMIC:
-do {
+for (;;) {
+int rv;
 c1 = virRandomBits(10);
 c2 = virRandomBits(10);
 
@@ -345,7 +355,11 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr 
mgr,
 goto cleanup;
 }
 }
-} while (virSecuritySELinuxMCSAdd(mcs) == -1);
+if ((rv = virSecuritySELinuxMCSAdd(mcs)) < 0)
+goto cleanup;
+if (rv == 0)
+break;
+}
 
 def->seclabel.label =
 virSecuritySELinuxGenNewContext(def->seclabel.baselabel ?
@@ -418,6 +432,7 @@ 
virSecuritySELinuxReserveSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSE
 security_context_t pctx;
 context_t ctx = NULL;
 const char *mcs;
+int rv;
 
 if (def->seclabel.type == VIR_DOMAIN_SECLABEL_STATIC)
 return 0;
@@ -431,19 +446,27 @@ 
virSecuritySELinuxReserveSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSE
 ctx = context_new(pctx);
 freecon(pctx);
 if (!ctx)
-goto err;
+goto error;
 
 mcs = context_range_get(ctx);
 if (!mcs)
-goto err;
+goto error;
+
+if ((rv = virSecuritySELinuxMCSAdd(mcs)) < 0)
+goto error;
 
-virSecuritySELinuxMCSAdd(mcs);
+if (rv == 1) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("MCS level for existing domain label %s already 
reserved"),
+   (char*)pctx);
+goto error;
+}
 
 context_free(ctx);
 
 return 0;
 
-err:
+error:
 context_free(ctx);
 return -1;
 }
-- 
1.7.10.4

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


[libvirt] [PATCH v2 3/3] Use a hash table for storing MCS labels

2012-07-20 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Instead of using an O(n) efficiency linked list for storing
MCS labels, use a hash table. Instead of having the list
be global, put it in the SELinux driver private data struct
to ensure uniqueness across different instances of the driver

Signed-off-by: Daniel P. Berrange 
---
 src/security/security_selinux.c |   82 +++
 1 file changed, 31 insertions(+), 51 deletions(-)

diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 34e1b7c..3f9b65d 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -32,6 +32,7 @@
 #include "hostusb.h"
 #include "storage_file.h"
 #include "virfile.h"
+#include "virhash.h"
 #include "virrandom.h"
 #include "util.h"
 #include "conf.h"
@@ -50,6 +51,7 @@ struct _virSecuritySELinuxData {
 char *domain_context;
 char *file_context;
 char *content_context;
+virHashTablePtr mcs;
 };
 
 struct _virSecuritySELinuxCallbackData {
@@ -60,64 +62,31 @@ struct _virSecuritySELinuxCallbackData {
 #define SECURITY_SELINUX_VOID_DOI   "0"
 #define SECURITY_SELINUX_NAME "selinux"
 
-/* TODO
-   The data struct of used mcs should be replaced with a better data structure 
in the future
-*/
-
-typedef struct virSecuritySELinuxMCS virSecuritySELinuxMCS;
-typedef virSecuritySELinuxMCS *virSecuritySELinuxMCSPtr;
-struct virSecuritySELinuxMCS {
-char *mcs;
-virSecuritySELinuxMCSPtr next;
-};
-static virSecuritySELinuxMCSPtr mcsList = NULL;
-
 /*
  * Returns 0 on success, 1 if already reserved, or -1 on fatal error
  */
 static int
-virSecuritySELinuxMCSAdd(const char *mcs)
+virSecuritySELinuxMCSAdd(virSecurityManagerPtr mgr,
+ const char *mcs)
 {
-virSecuritySELinuxMCSPtr ptr;
+virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(mgr);
 
-for (ptr = mcsList; ptr; ptr = ptr->next) {
-if (STREQ(ptr->mcs, mcs))
-return 1;
-}
-if (VIR_ALLOC(ptr) < 0) {
-virReportOOMError();
-return -1;
-}
-if (!(ptr->mcs = strdup(mcs))) {
-virReportOOMError();
-VIR_FREE(ptr);
+if (virHashLookup(data->mcs, mcs))
+return 1;
+
+if (virHashAddEntry(data->mcs, mcs, (void*)0x1) < 0)
 return -1;
-}
-ptr->next = mcsList;
-mcsList = ptr;
+
 return 0;
 }
 
-static int
-virSecuritySELinuxMCSRemove(const char *mcs)
+static void
+virSecuritySELinuxMCSRemove(virSecurityManagerPtr mgr,
+const char *mcs)
 {
-virSecuritySELinuxMCSPtr prevptr = NULL;
-virSecuritySELinuxMCSPtr ptr = NULL;
-
-for (ptr = mcsList; ptr; ptr = ptr->next) {
-if (STREQ(ptr->mcs, mcs)) {
-if (prevptr)
-prevptr->next = ptr->next;
-else {
-mcsList = ptr->next;
-}
-VIR_FREE(ptr->mcs);
-VIR_FREE(ptr);
-return 0;
-}
-prevptr = ptr;
-}
-return -1;
+virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(mgr);
+
+virHashRemoveEntry(data->mcs, mcs);
 }
 
 static char *
@@ -191,6 +160,10 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr)
  selinux_lxc_contexts_path());
 goto error;
 }
+
+if (!(data->mcs = virHashCreate(10, NULL)))
+goto error;
+
 virConfFree(selinux_conf);
 return 0;
 
@@ -199,6 +172,7 @@ error:
 VIR_FREE(data->domain_context);
 VIR_FREE(data->file_context);
 VIR_FREE(data->content_context);
+virHashFree(data->mcs);
 return -1;
 }
 #else
@@ -249,12 +223,16 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr 
mgr)
 *ptr = '\0';
 }
 
+if (!(data->mcs = virHashCreate(10, NULL)))
+goto error;
+
 return 0;
 
 error:
 VIR_FREE(data->domain_context);
 VIR_FREE(data->file_context);
 VIR_FREE(data->content_context);
+virHashFree(data->mcs);
 return -1;
 }
 
@@ -355,7 +333,7 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr 
mgr,
 goto cleanup;
 }
 }
-if ((rv = virSecuritySELinuxMCSAdd(mcs)) < 0)
+if ((rv = virSecuritySELinuxMCSAdd(mgr, mcs)) < 0)
 goto cleanup;
 if (rv == 0)
 break;
@@ -452,7 +430,7 @@ 
virSecuritySELinuxReserveSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSE
 if (!mcs)
 goto error;
 
-if ((rv = virSecuritySELinuxMCSAdd(mcs)) < 0)
+if ((rv = virSecuritySELinuxMCSAdd(mgr, mcs)) < 0)
 goto error;
 
 if (rv == 1) {
@@ -504,6 +482,8 @@ virSecuritySELinuxSecurityDriverClose(virSecurityManagerPtr 
mgr)
 if (!data)
 return 0;
 
+virHashFree(data->mcs);
+
 VIR_FREE(data->domain_context);
 VIR_FREE(data->file_context);
 VIR_FREE(data->content_context);
@@ -1193,7 +1173,7 @@ 
virSecuritySELinuxRestoreSecurityAllLabel(virSecurityMan

Re: [libvirt] [PATCH 01/49] Fix indentions

2012-07-20 Thread Daniel P. Berrange
On Fri, Jul 20, 2012 at 10:15:29AM -0600, Eric Blake wrote:
> On 07/20/2012 08:24 AM, Osier Yang wrote:
> > Some of the macros use tab, while the left use spaces, this patch
> > change it to always use the spaces. And a few aligning fixes.
> > ---
> >  src/datatypes.h |   86 
> > +++---
> >  1 files changed, 43 insertions(+), 43 deletions(-)
> 
> ACK.
> 
> > 
> > diff --git a/src/datatypes.h b/src/datatypes.h
> > index fc284d2..01a8544 100644
> > --- a/src/datatypes.h
> > +++ b/src/datatypes.h
> > @@ -33,8 +33,8 @@
> >   * magic value used to protect the API when pointers to connection 
> > structures
> >   * are passed down by the users.
> >   */
> > -# define VIR_CONNECT_MAGIC 0x4F23DEAD
> > -# define VIR_IS_CONNECT(obj)   ((obj) && 
> > (obj)->magic==VIR_CONNECT_MAGIC)
> > +# define VIR_CONNECT_MAGIC   0x4F23DEAD
> > +# define VIR_IS_CONNECT(obj) ((obj) && (obj)->magic==VIR_CONNECT_MAGIC)
> 
> Conflicts with Dan's series to use virObject.

Push this patch now independantly of the rest of this huge series.
I'll sort out conflicts when I rebase my virObject code next week.


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 01/49] Fix indentions

2012-07-20 Thread Eric Blake
On 07/20/2012 08:24 AM, Osier Yang wrote:
> Some of the macros use tab, while the left use spaces, this patch
> change it to always use the spaces. And a few aligning fixes.
> ---
>  src/datatypes.h |   86 +++---
>  1 files changed, 43 insertions(+), 43 deletions(-)

ACK.

> 
> diff --git a/src/datatypes.h b/src/datatypes.h
> index fc284d2..01a8544 100644
> --- a/src/datatypes.h
> +++ b/src/datatypes.h
> @@ -33,8 +33,8 @@
>   * magic value used to protect the API when pointers to connection structures
>   * are passed down by the users.
>   */
> -# define VIR_CONNECT_MAGIC   0x4F23DEAD
> -# define VIR_IS_CONNECT(obj) ((obj) && (obj)->magic==VIR_CONNECT_MAGIC)
> +# define VIR_CONNECT_MAGIC   0x4F23DEAD
> +# define VIR_IS_CONNECT(obj) ((obj) && (obj)->magic==VIR_CONNECT_MAGIC)

Conflicts with Dan's series to use virObject.

-- 
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 3/5] Add callback to virNetClient to be invoked on connection close

2012-07-20 Thread Eric Blake
On 07/20/2012 08:18 AM, Daniel P. Berrange wrote:
>>> @@ -463,6 +480,9 @@ void virNetClientFree(virNetClientPtr client)
>>>  return;
>>>  }
>>>  
>>> +if (client->closeFf && client->closeOpaque)
>>> +client->closeFf(client->closeOpaque);
>>
>> Again, you should not be forcing closeOpaque to be non-NULL.  It's
>> opaque, after all.
> 
> If opaque is NULL, then there's nothing that needs free'ing.

Maybe nothing to free, but there may still be side effects (such as
logging) in the closeFf that the caller still wants to have happen.

-- 
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 3/3] Replace use of custom macros with virReportError in the Xen drivers

2012-07-20 Thread Peter Krempa

On 07/20/12 16:11, Daniel P. Berrange wrote:

From: "Daniel P. Berrange" 

Update the legacy Xen drivers to use virReportError instead of
the statsError, virXenInotifyError, virXenStoreError,
virXendError, xenUnifiedError, xenXMError custom macros

Signed-off-by: Daniel P. Berrange 
---
  cfg.mk   |7 -
  src/xen/block_stats.c|   54 +++---
  src/xen/xen_driver.c |  114 ++--
  src/xen/xen_hypervisor.c |  158 
  src/xen/xen_inotify.c|   48 +++--
  src/xen/xend_internal.c  |  462 +++---
  src/xen/xm_internal.c|  134 +++---
  src/xen/xs_internal.c|   40 ++--
  8 files changed, 489 insertions(+), 528 deletions(-)



I reviewed the xen_hypervisor file and hope you didn't change anything 
in the other files so


ACK

Peter

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


[libvirt] Mutt patch colour highlighting

2012-07-20 Thread Daniel P. Berrange
On Fri, Jul 20, 2012 at 09:46:42AM -0600, Eric Blake wrote:
> > One remark up there, but no biggie.
> 
> I had to hunt for that remark among 70k of verbatim patch.  Not only is
> it okay to trim portions of the patch that you are happy with, but
> trimming actually helps focus on the problems.  Just be sure you leave
> enough context to help the readers pinpoint where the problem was (as I
> did here, by including the @@ line at the start of the problematic hunk).

I completely agree with your point, but if you have a good mutt
colour setup, it is fairly easy to scan through large mails and
distinguish new text vs quoted text at a glance. I even have
some magic settings to highlight patches in email

  http://berrange.fedorapeople.org/mutt-patch-colour.jpeg

In my .muttrc:

# General colour settings
color attachment brightmagenta black
#color body white black
color bold green black
color header brightyellow black ^(From|Subject):
color hdrdefault yellow black
#color index white black
#color indicator brightyellow red
color indicator brightyellow red
color markers brightcyan black
color message brightcyan black
color normal white black
color quoted brightblue black
color search green black
color signature red black
color status yellow blue
color tilde magenta black
color tree magenta black
color underline green black

# Patch file highlighting
color body green black "^diff \-.*"
color body green black "^index [a-f0-9].*"
color body green black "^\-\-\- .*"
color body green black "^[\+]{3} .*"
color body cyan black "^[\+][^\+]+.*"
color body red  black "^\-[^\-]+.*"
color body brightblue black "^@@ .*"

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 2/3] Make sure xenHypervisorInit correctly reports errors

2012-07-20 Thread Peter Krempa

On 07/20/12 16:11, Daniel P. Berrange wrote:

From: "Daniel P. Berrange" 

The xenHypervisorInit method was called from two different
locations, during initial driver registration and also while
opening a Xen connection. The former can't report any useful
errors to the end user/app, so remove it. To ensure thread
safety use a VIR_ONCE_GLOBAL_INIT call to invoke
xenHypervisorInit from the xenHypervisorOpen method.
---
  src/xen/xen_driver.c |3 ---
  src/xen/xen_hypervisor.c |   31 ++-
  2 files changed, 10 insertions(+), 24 deletions(-)



This version definitely looks better. ACK.

Peter

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


Re: [libvirt] [PATCH 1/3] Ensure failure to talk to Xen hypervisor is fatal when privileged

2012-07-20 Thread Peter Krempa

On 07/20/12 16:11, Daniel P. Berrange wrote:

From: "Daniel P. Berrange" 

As per the comment, the Xen hypervisor driver is considered to
be mandatory when running privileged. When it fails to open,
we should thus return an error, not ignore it.
---
  src/xen/xen_driver.c |2 ++
  1 file changed, 2 insertions(+)



ACK.

Peter

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


Re: [libvirt] [PATCH 02/50] list: Expose pool type via virStoragePoolGetInfo

2012-07-20 Thread Eric Blake
On 07/20/2012 07:23 AM, Daniel P. Berrange wrote:
>> I guess I'm missing something important here... If libvirtd is old enough not
>> to support listAllStoragePools, how it can be new enough to support the new
>> API which would return pool type?
> 
> Yeah, this just doesn't make any sense. All filtering should be done in
> the libvirtd server side for new enough libvirt. Nothing should be done
> client side, for old or new libvirtd.

Not quite true.  For domains and snapshots, we added some client-side
filtering into virsh _in the cases where the filtering was easy using
older API_.  For example, when listing snapshot parents, virsh will do
getXML scraping to determine that information from older libvirt that
lacked virDomainSnapshotGetParent.

The rule of thumb in virsh is that if you can easily determine using
older API (such as dumpxml, O(1) per guest that you are querying)
whether to filter, then when new virsh finds out that it is talking to
an old server that can't do server-side filtering, then virsh can still
do the filtering client-side.  But if the information was not available
in older API, then virsh should fail loudly if the filtering attempt
cannot be honored due to older server.  For example, with snapshots, I
added the ability to filter on whether a snapshot has children, but
getting that information from older API is a prohibitively expensive -
it is O(n^2) API calls per snapshot making filtering an O(n^3) operation
if I were to attempt it on every snapshot, so that is failed instead of
attempting a fallback.

-- 
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 17/23] Replace use of VMX_ERROR with virReportError

2012-07-20 Thread Eric Blake
On 07/20/2012 07:34 AM, Martin Kletzander wrote:
> On 07/18/2012 08:40 PM, Daniel P. Berrange wrote:
>> From: "Daniel P. Berrange" 
>>
>> Update the VMX shared code to use virReportError instead of
>> the VMX_ERROR custom macro
>>

>> @@ -3676,9 +3672,9 @@ virVMXFormatSerial(virVMXContext *ctx, 
>> virDomainChrDefPtr def,
>>  break;
>>  
>>default:
>> -VMX_ERROR(VIR_ERR_CONFIG_UNSUPPORTED,
>> -  _("Unsupported character device TCP protocol '%s'"),
>> -  virDomainChrTcpProtocolTypeToString(
>> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>> +   _("Unsupported character device TCP protocol 
>> '%s'"),
>> +   virDomainChrTcpProtocolTypeToString(
>>def->source.data.tcp.protocol));
> 
> I'd probably indent the "def->source..." line differently so it's more
> visible that it is one level deeper.
> 

> 
> One remark up there, but no biggie.

I had to hunt for that remark among 70k of verbatim patch.  Not only is
it okay to trim portions of the patch that you are happy with, but
trimming actually helps focus on the problems.  Just be sure you leave
enough context to help the readers pinpoint where the problem was (as I
did here, by including the @@ line at the start of the problematic hunk).

-- 
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 v8 8/8] parallels: implement VM creation

2012-07-20 Thread Peter Krempa

On 07/04/12 19:42, Dmitry Guryanov wrote:

To create a new VM in PARALLELS we should issue "prlctl create" command,
and give path to the directory, where VM should be created. VM's
storage will be in that directory later. So in this first version
find out location of first VM's hard disk and create VM there.

Signed-off-by: Dmitry Guryanov 
---
  src/parallels/parallels_driver.c  |   78 -
  src/parallels/parallels_driver.h  |4 ++
  src/parallels/parallels_storage.c |6 +--
  3 files changed, 82 insertions(+), 6 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index 8c8ddd8..3993228 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1117,6 +1117,74 @@ parallelsApplyChanges(virDomainObjPtr dom, 
virDomainDefPtr newdef)
  return 0;
  }

+static int
+parallelsCreateVm(virConnectPtr conn, virDomainDefPtr def)
+{
+parallelsConnPtr privconn = conn->privateData;
+int i;
+virStorageVolDefPtr privvol = NULL;
+virStoragePoolObjPtr pool = NULL;
+virStorageVolPtr vol = NULL;
+char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+for (i = 0; i < def->ndisks; i++) {
+if (def->disks[i]->device != VIR_DOMAIN_DISK_DEVICE_DISK)
+continue;
+
+vol = parallelsStorageVolumeLookupByPathLocked(conn, 
def->disks[i]->src);
+if (!vol) {
+parallelsError(VIR_ERR_INVALID_ARG,
+ _("Can't find volume with path '%s'"),
+ def->disks[i]->src);
+return -1;
+}
+break;
+}
+
+if (!vol) {
+parallelsError(VIR_ERR_INVALID_ARG,
+ _("Can't create VM without hard disks"));


I'm not quite sure how this is with Parallels Virtuozzo, but it's a 
not-so-uncommon use-case to have a diskless machine. (PXE booted with 
network storage?)



+return -1;
+}
+
+pool = virStoragePoolObjFindByName(&privconn->pools, vol->pool);
+if (!pool) {
+parallelsError(VIR_ERR_INVALID_ARG,
+ _("Can't find storage pool with name '%s'"),
+ vol->pool);
+goto error;
+}
+
+privvol = virStorageVolDefFindByPath(pool, def->disks[i]->src);
+if (!privvol) {
+parallelsError(VIR_ERR_INVALID_ARG,
+ _("Can't find storage volume definition for path '%s'"),
+ def->disks[i]->src);
+goto error2;
+}
+
+virUUIDFormat(def->uuid, uuidstr);
+
+if (parallelsCmdRun(PRLCTL, "create", def->name, "--dst",
+  pool->def->target.path, "--no-hdd",
+  "--uuid", uuidstr, NULL) < 0)
+goto error2;
+
+if (parallelsCmdRun(PRLCTL, "set", def->name, "--vnc-mode", "auto", NULL) 
< 0)
+goto error2;
+
+virStoragePoolObjUnlock(pool);
+virUnrefStorageVol(vol);
+
+return 0;
+
+  error2:
+virStoragePoolObjUnlock(pool);
+  error:
+virUnrefStorageVol(vol);
+return -1;
+}
+
  static virDomainPtr
  parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
  {
@@ -1153,8 +1221,16 @@ parallelsDomainDefineXML(virConnectPtr conn, const char 
*xml)

  def = NULL;
  } else {
-parallelsError(VIR_ERR_NO_SUPPORT, _("Not implemented yet"));
+if (parallelsCreateVm(conn, def))
  goto cleanup;
+if (parallelsLoadDomains(privconn, def->name))
+goto cleanup;
+dom = virDomainFindByName(&privconn->domains, def->name);
+if (!dom) {
+parallelsError(VIR_ERR_INTERNAL_ERROR,
+ _("Domain is not defined after creation"));
+goto cleanup;
+}
  }

  event = virDomainEventNewFromObj(dom,
diff --git a/src/parallels/parallels_driver.h b/src/parallels/parallels_driver.h
index 6f06ac8..e32ad55 100644
--- a/src/parallels/parallels_driver.h
+++ b/src/parallels/parallels_driver.h
@@ -67,5 +67,9 @@ int parallelsCmdRun(const char *binary, ...) 
ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENT
  char * parallelsAddFileExt(const char *path, const char *ext);
  void parallelsDriverLock(parallelsConnPtr driver);
  void parallelsDriverUnlock(parallelsConnPtr driver);
+virStorageVolPtr parallelsStorageVolumeLookupByPathLocked(virConnectPtr
+   conn,
+   const char
+   *path);


Again, please use a separate header for the driver-internal definitions.



  #endif
diff --git a/src/parallels/parallels_storage.c 
b/src/parallels/parallels_storage.c
index 5a5b366..c86ddaf 100644
--- a/src/parallels/parallels_storage.c
+++ b/src/parallels/parallels_storage.c
@@ -41,10 +41,6 @@ static virStorageVolDefPtr 
parallelsStorageVolumeDefine(virStoragePoolObjPtr poo
const char *xmldesc,
const 

Re: [libvirt] [PATCH v8 7/8] parallels: add storage driver

2012-07-20 Thread Peter Krempa

On 07/04/12 19:42, Dmitry Guryanov wrote:

PARALLELS has one serious discrepancy with libvirt: libvirt stores
domain configuration files in one place, and storage files
in other places (with the API of storage pools and storage volumes).
PARALLELS stores all domain data in a single directory, for example, you
may have domain with name fedora-15, which will be located in
'/var/parallels/fedora-15.pvm', and it's hard disk image will be
in '/var/parallels/fedora-15.pvm/harddisk1.hdd'.

I've decided to create storage driver, which produces pseudo-volumes
(xml files with volume description), and they will be 'converted' to
real disk images after attaching to a VM.

So if someone creates VM with one hard disk using virt-manager,
at first virt-manager creates a new volume, and then defines a
domain. We can lookup a volume by path in XML domain definition
and find out location of new domain and size of its hard disk.

Signed-off-by: Dmitry Guryanov 
---


Comments inline.


  po/POTFILES.in|1 +
  src/Makefile.am   |3 +-
  src/parallels/parallels_driver.c  |6 +-
  src/parallels/parallels_driver.h  |5 +
  src/parallels/parallels_storage.c | 1460 +
  src/parallels/parallels_utils.c   |   24 +
  6 files changed, 1496 insertions(+), 3 deletions(-)
  create mode 100644 src/parallels/parallels_storage.c

diff --git a/po/POTFILES.in b/po/POTFILES.in
index dcb0813..240becb 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -66,6 +66,7 @@ src/phyp/phyp_driver.c
  src/parallels/parallels_driver.c
  src/parallels/parallels_driver.h
  src/parallels/parallels_utils.c
+src/parallels/parallels_storage.c
  src/qemu/qemu_agent.c
  src/qemu/qemu_bridge_filter.c
  src/qemu/qemu_capabilities.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 93989c8..6908bb2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -482,7 +482,8 @@ HYPERV_DRIVER_EXTRA_DIST =  
\
  PARALLELS_DRIVER_SOURCES =\
parallels/parallels_driver.h\
parallels/parallels_driver.c\
-   parallels/parallels_utils.c
+   parallels/parallels_utils.c \
+   parallels/parallels_storage.c

  NETWORK_DRIVER_SOURCES =  \
network/bridge_driver.h network/bridge_driver.c
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index 54bdc9a..8c8ddd8 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -65,13 +65,13 @@ static int parallelsStart(virDomainObjPtr privdom);
  static int parallelsKill(virDomainObjPtr privdom);
  static int parallelsStop(virDomainObjPtr privdom);

-static void
+void
  parallelsDriverLock(parallelsConnPtr driver)
  {
  virMutexLock(&driver->lock);
  }

-static void
+void


Looks like these should be squashed into one of the previous patches, 
but I'm not sure if you'll need this.



  parallelsDriverUnlock(parallelsConnPtr driver)
  {
  virMutexUnlock(&driver->lock);
@@ -1226,6 +1226,8 @@ parallelsRegister(void)

  if (virRegisterDriver(¶llelsDriver) < 0)
  return -1;
+if (parallelsStorageRegister())
+return -1;

  return 0;
  }
diff --git a/src/parallels/parallels_driver.h b/src/parallels/parallels_driver.h
index 2b3c956..6f06ac8 100644
--- a/src/parallels/parallels_driver.h
+++ b/src/parallels/parallels_driver.h
@@ -26,6 +26,7 @@

  # include "domain_conf.h"
  # include "storage_conf.h"
+# include "driver.h"
  # include "domain_event.h"

  # include "json.h"
@@ -59,8 +60,12 @@ typedef struct _parallelsConn parallelsConn;
  typedef struct _parallelsConn *parallelsConnPtr;

  int parallelsRegister(void);
+int parallelsStorageRegister(void);

  virJSONValuePtr parallelsParseOutput(const char *binary, ...) 
ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
  int parallelsCmdRun(const char *binary, ...) ATTRIBUTE_NONNULL(1) 
ATTRIBUTE_SENTINEL;
+char * parallelsAddFileExt(const char *path, const char *ext);
+void parallelsDriverLock(parallelsConnPtr driver);
+void parallelsDriverUnlock(parallelsConnPtr driver);


Please include these in some kind of private header file, so you don't 
expose them into other drivers.




  #endif
diff --git a/src/parallels/parallels_storage.c 
b/src/parallels/parallels_storage.c
new file mode 100644
index 000..5a5b366
--- /dev/null
+++ b/src/parallels/parallels_storage.c
@@ -0,0 +1,1460 @@
+/*
+ * parallels_storage.c: core driver functions for managing
+ * Parallels Virtuozzo Server hosts
+ *
+ * Copyright (C) 2012 Parallels, 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 la

Re: [libvirt] [PATCH 03/13] Rewrite virAtomic APIs using GLib's atomic ops code

2012-07-20 Thread Eric Blake
On 07/20/2012 12:36 AM, Hu Tao wrote:
>>> The `verify' lines cause building warnings:
>>>
>>> cc1: warnings being treated as errors
>>> util/virobject.c: In function 'virClassNew':
>>> util/virobject.c:74:99: error: nested extern declaration of 
>>> '_gl_verify_function2' [-Wnested-externs]
>>
>> Which version of gcc?
>>
>> I'll have to see if I can come up with a solution in upstream gnulib
>> that expands verify() in such a way that works with -Wnested-externs.
> 
> $ gcc --version
> gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
> Copyright (C) 2010 Free Software Foundation, Inc.
> 
> 
> This is the gcc shipped with Fedora 14.

You _do_ realize that Fedora 14 is unsupported upstream (right now, the
oldest supported version is Fedora 16).  That said, I still have an F14
VM lying around, so I will try to reproduce this.

-- 
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] Disable NWFilter driver completely when unprivileged

2012-07-20 Thread Michal Privoznik
On 20.07.2012 16:22, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> Running libvirtd unprivileged results in a warning message from
> the NWFilter driver
> 
>   virNWFilterSnoopLeaseFileRefresh:1882 : 
> open("/var/run/libvirt/network/nwfilter.ltmp"): No such file or directory
> 
> Since it requires privileged network access, this driver should
> not even run when unprivileged.
> 
> Signed-off-by: Daniel P. Berrange 
> ---
>  src/nwfilter/nwfilter_driver.c |3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
> index 58d91f9..9034549 100644
> --- a/src/nwfilter/nwfilter_driver.c
> +++ b/src/nwfilter/nwfilter_driver.c
> @@ -68,6 +68,9 @@ static int
>  nwfilterDriverStartup(int privileged) {
>  char *base = NULL;
>  
> +if (!privileged)
> +return 0;
> +
>  if (virNWFilterIPAddrMapInit() < 0)
>  return -1;
>  if (virNWFilterLearnInit() < 0)
> 

ACK

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


[libvirt] [PATCHv3 0/2] Rework of Disk Geometry Support

2012-07-20 Thread Viktor Mihajlovski
Two more changes:
1. Use virReportError instead of custom xxxReportError.
2. Moved the geometry element to diskspec, so it applies to all kind
   of disks.

Please disregard the preceding patches.

J.B. Joret (2):
  Support for Disk Geometry Override
  qemu: Disk Geometry Override Support

 docs/formatdomain.html.in  |   25 +++
 docs/schemas/domaincommon.rng  |   25 +++
 src/conf/domain_conf.c |   71 
 src/conf/domain_conf.h |   17 +
 src/libvirt_private.syms   |2 +
 src/qemu/qemu_command.c|   59 
 .../qemuxml2argv-disk-geometry.args|4 +
 .../qemuxml2argv-disk-geometry.xml |   26 +++
 tests/qemuxml2argvtest.c   |2 +
 9 files changed, 231 insertions(+), 0 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.xml

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


[libvirt] [PATCH 41/49] list: Implement RPC calls for virConnectListAllNWFilters

2012-07-20 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 remoteDispatchConnectListAllNWFilters.

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

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

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

diff --git a/daemon/remote.c b/daemon/remote.c
index 5a16dbe..9de0629 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4226,6 +4226,60 @@ cleanup:
 return rv;
 }
 
+static int
+remoteDispatchConnectListAllNWFilters(virNetServerPtr server ATTRIBUTE_UNUSED,
+  virNetServerClientPtr client,
+  virNetMessagePtr msg ATTRIBUTE_UNUSED,
+  virNetMessageErrorPtr rerr,
+  remote_connect_list_all_nwfilters_args 
*args,
+  remote_connect_list_all_nwfilters_ret 
*ret)
+{
+virNWFilterPtr *filters = NULL;
+int nfilters = 0;
+int i;
+int rv = -1;
+struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
+
+if (!priv->conn) {
+virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+goto cleanup;
+}
+
+if ((nfilters = virConnectListAllNWFilters(priv->conn,
+   args->need_results ? &filters : 
NULL,
+   args->flags)) < 0)
+goto cleanup;
+
+if (filters && nfilters) {
+if (VIR_ALLOC_N(ret->filters.filters_val, nfilters) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret->filters.filters_len = nfilters;
+
+for (i = 0; i < nfilters; i++)
+make_nonnull_nwfilter(ret->filters.filters_val + i, filters[i]);
+} else {
+ret->filters.filters_len = 0;
+ret->filters.filters_val = NULL;
+}
+
+ret->ret = nfilters;
+
+rv = 0;
+
+cleanup:
+if (rv < 0)
+virNetMessageSaveError(rerr);
+if (filters) {
+for (i = 0; i < nfilters; i++)
+virNWFilterFree(filters[i]);
+VIR_FREE(filters);
+}
+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 22aad2f..ee6caf4 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2968,6 +2968,68 @@ done:
 return rv;
 }
 
+static int
+remoteConnectListAllNWFilters(virConnectPtr conn,
+  virNWFilterPtr **filters,
+  unsigned int flags)
+{
+int rv = -1;
+int i;
+virNWFilterPtr *tmp_filters = NULL;
+remote_connect_list_all_nwfilters_args args;
+remote_connect_list_all_nwfilters_ret ret;
+
+struct private_data *priv = conn->privateData;
+
+remoteDriverLock(priv);
+
+args.need_results = !!filters;
+args.flags = flags;
+
+memset(&ret, 0, sizeof(ret));
+if (call(conn,
+ priv,
+ 0,
+ REMOTE_PROC_CONNECT_LIST_ALL_NWFILTERS,
+ (xdrproc_t) xdr_remote_connect_list_all_nwfilters_args,
+ (char *) &args,
+ (xdrproc_t) xdr_remote_connect_list_all_nwfilters_ret,
+ (char *) &ret) == -1)
+goto done;
+
+if (filters) {
+if (VIR_ALLOC_N(tmp_filters, ret.filters.filters_len + 1) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+
+for (i = 0; i < ret.filters.filters_len; i++) {
+tmp_filters[i] = get_nonnull_nwfilter (conn, 
ret.filters.filters_val[i]);
+if (!tmp_filters[i]) {
+virReportOOMError();
+goto cleanup;
+}
+}
+*filters = tmp_filters;
+tmp_filters = NULL;
+}
+
+rv = ret.ret;
+
+cleanup:
+if (tmp_filters) {
+for (i = 0; i < ret.filters.filters_len; i++)
+if (tmp_filters[i])
+virNWFilterFree(tmp_filters[i]);
+VIR_FREE(tmp_filters);
+}
+
+xdr_free((xdrproc_t) xdr_remote_connect_list_all_nwfilters_ret, (char *) 
&ret);
+
+done:
+remoteDriverUnlock(priv);
+return rv;
+}
 
 /*--*/
 
@@ -5801,6 +5863,7 @@ static virNWFilterDriver nwfilter_driver = {
 .undefine = remoteNWFilterUndefine, /* 0.8.0 */
 .numOfNWFilters

[libvirt] [PATCH 49/49] list: Expose virConnectListAllSecrets to Python binding

2012-07-20 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: Implementation for listAllSecrets.

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 b8ab823..4f609ee 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -368,6 +368,12 @@
   
   
 
+
+  returns list of all interfaces
+  
+  
+  
+
 
   Associates a value with a secret.
   
diff --git a/python/libvirt-override-virConnect.py 
b/python/libvirt-override-virConnect.py
index caca982..6bec66d 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -266,3 +266,15 @@
 retlist.append(virNWFilter(self, _obj=filter_ptr))
 
 return retlist
+
+def listAllSecrets(self, flags):
+"""Returns a list of secret objects"""
+ret = libvirtmod.virConnectListAllSecrets(self._o, flags)
+if ret is None:
+raise libvirtError("virConnectListAllSecrets() failed", conn=self)
+
+retlist = list()
+for secret_ptr in ret:
+retlist.append(virSecret(self, _obj=secret_ptr))
+
+return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index bdf5d12..0098773 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -3592,6 +3592,53 @@ libvirt_virConnectListSecrets(PyObject *self 
ATTRIBUTE_UNUSED,
 }
 
 static PyObject *
+libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+PyObject *pyobj_conn;
+PyObject *py_retval = NULL;
+PyObject *tmp = NULL;
+virConnectPtr conn;
+virSecretPtr *secrets = NULL;
+int c_retval = 0;
+int i;
+unsigned int flags;
+
+if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllSecrets",
+  &pyobj_conn, &flags))
+return NULL;
+conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+c_retval = virConnectListAllSecrets(conn, &secrets, 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_virSecretPtrWrap(secrets[i])) ||
+PyList_SetItem(py_retval, i, tmp) < 0) {
+Py_XDECREF(tmp);
+Py_DECREF(py_retval);
+py_retval = NULL;
+goto cleanup;
+}
+/* python steals the pointer */
+secrets[i] = NULL;
+}
+
+cleanup:
+for (i = 0; i < c_retval; i++)
+if (secrets[i])
+virSecretFree(secrets[i]);
+VIR_FREE(secrets);
+return py_retval;
+}
+
+static PyObject *
 libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED,
   PyObject *args) {
 PyObject *py_retval;
@@ -6179,6 +6226,7 @@ static PyMethodDef libvirtMethods[] = {
 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, 
METH_VARARGS, NULL},
 {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID, 
METH_VARARGS, NULL},
 {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets, 
METH_VARARGS, NULL},
+{(char *) "virConnectListAllSecrets", libvirt_virConnectListAllSecrets, 
METH_VARARGS, NULL},
 {(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS, 
NULL},
 {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, 
NULL},
 {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID, METH_VARARGS, 
NULL},
-- 
1.7.7.3

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


[libvirt] [PATCHv3 1/2] Support for Disk Geometry Override

2012-07-20 Thread Viktor Mihajlovski
From: J.B. Joret 

A hypervisor may allow to override the disk geometry of drives.
Qemu, as an example with cyls=,heads=,secs=[,trans=].
This patch extends the domain config to allow the specification of
disk geometry with libvirt.

V2 Changes: Split out qemu specific code, add documentation and schema.

V3 Changes: Moved geometry element to diskspec and use virReportError now.

Signed-off-by: J.B. Joret 
Signed-off-by: Viktor Mihajlovski 
---
 docs/formatdomain.html.in |   25 ++
 docs/schemas/domaincommon.rng |   25 ++
 src/conf/domain_conf.c|   71 +
 src/conf/domain_conf.h|   17 ++
 src/libvirt_private.syms  |2 +
 5 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index b6e0d5d..7f42753 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1222,6 +1222,12 @@
   
   
+ + + + + + ... @@ -1569,6 +1575,25 @@ associated with the Ceph secret object. libvirt 0.9.7 + geometry + The optional geometry element provides the +ability to override geometry settings. This mostly useful for +S390 DASD-disks or older DOS-disks + + cyls + The cyls element is the +number of cylinders. + heads + The heads element is the +number of heads. + secs + The secs element is the +number of sectors per track. + trans + The optional trans element is the +BIOS-Translation-Modus (none, lba or auto) + + Filesystems diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index b7562ad..dd6496e 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -851,6 +851,9 @@ + + + @@ -1053,6 +1056,28 @@ + + + + + + + + + + + + + + +auto +none +lba + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1b5dad9..0c4bdc9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -170,6 +170,12 @@ VIR_ENUM_IMPL(virDomainDiskDevice, VIR_DOMAIN_DISK_DEVICE_LAST, "floppy", "lun") +VIR_ENUM_IMPL(virDomainDiskGeometryTrans, VIR_DOMAIN_DISK_TRANS_LAST, + "default", + "none", + "auto", + "lba") + VIR_ENUM_IMPL(virDomainDiskBus, VIR_DOMAIN_DISK_BUS_LAST, "ide", "fdc", @@ -3343,6 +3349,7 @@ virDomainDiskDefParseXML(virCapsPtr caps, char *source = NULL; char *target = NULL; char *protocol = NULL; +char *trans = NULL; virDomainDiskHostDefPtr hosts = NULL; int nhosts = 0; char *bus = NULL; @@ -3371,6 +3378,11 @@ virDomainDiskDefParseXML(virCapsPtr caps, return NULL; } +def->geometry.cylinders = 0; +def->geometry.heads = 0; +def->geometry.sectors = 0; +def->geometry.trans = VIR_DOMAIN_DISK_TRANS_DEFAULT; + ctxt->node = node; type = virXMLPropString(node, "type"); @@ -3480,6 +3492,40 @@ virDomainDiskDefParseXML(virCapsPtr caps, if (target && STRPREFIX(target, "ioemu:")) memmove(target, target+6, strlen(target)-5); +} else if (xmlStrEqual(cur->name, BAD_CAST "geometry")) { +if (virXPathUInt("string(./geometry/@cyls)", + ctxt, &def->geometry.cylinders) < 0) { +virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("invalid geometry settings (cyls)")); +goto error; +} +if (virXPathUInt("string(./geometry/@heads)", + ctxt, &def->geometry.heads) < 0) { +virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("invalid geometry settings (heads)")); +goto error; +} +if (virXPathUInt("string(./geometry/@secs)", + ctxt, &def->geometry.sectors) < 0) { +virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("invalid geometry settings (secs)")); +goto error; +} +trans = vir

[libvirt] [PATCH 44/49] list: Expose virConnectListAllNWFilters to Python binding

2012-07-20 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:
  * Implementation for listAllNWFilters.

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

diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index a3d6bbb..b8ab823 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -396,6 +396,12 @@
   
   
 
+
+  returns list of all network fitlers
+  
+  
+  
+
 
   Try to lookup a network filter on the given hypervisor based on 
its UUID.
   
diff --git a/python/libvirt-override-virConnect.py 
b/python/libvirt-override-virConnect.py
index c34cd63..caca982 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -255,3 +255,14 @@
 
 return retlist
 
+def listAllNWFilters(self, flags):
+"""Returns a list of network filter objects"""
+ret = libvirtmod.virConnectListAllNWFilters(self._o, flags)
+if ret is None:
+raise libvirtError("virConnectListAllNWFilters() failed", 
conn=self)
+
+retlist = list()
+for filter_ptr in ret:
+retlist.append(virNWFilter(self, _obj=filter_ptr))
+
+return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 6449639..bdf5d12 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -3764,6 +3764,53 @@ libvirt_virConnectListNWFilters(PyObject *self 
ATTRIBUTE_UNUSED,
 }
 
 static PyObject *
+libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED,
+   PyObject *args)
+{
+PyObject *pyobj_conn;
+PyObject *py_retval = NULL;
+PyObject *tmp = NULL;
+virConnectPtr conn;
+virNWFilterPtr *filters = NULL;
+int c_retval = 0;
+int i;
+unsigned int flags;
+
+if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNWFilters",
+  &pyobj_conn, &flags))
+return NULL;
+conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+c_retval = virConnectListAllNWFilters(conn, &filters, 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_virNWFilterPtrWrap(filters[i])) ||
+PyList_SetItem(py_retval, i, tmp) < 0) {
+Py_XDECREF(tmp);
+Py_DECREF(py_retval);
+py_retval = NULL;
+goto cleanup;
+}
+/* python steals the pointer */
+filters[i] = NULL;
+}
+
+cleanup:
+for (i = 0; i < c_retval; i++)
+if (filters[i])
+virNWFilterFree(filters[i]);
+VIR_FREE(filters);
+return py_retval;
+}
+
+static PyObject *
 libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
  PyObject *args) {
 PyObject *py_retval;
@@ -6138,6 +6185,7 @@ static PyMethodDef libvirtMethods[] = {
 {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString, 
METH_VARARGS, NULL},
 {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID, 
METH_VARARGS, NULL},
 {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, 
METH_VARARGS, NULL},
+{(char *) "virConnectListAllNWFilters", 
libvirt_virConnectListAllNWFilters, METH_VARARGS, NULL},
 {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, 
METH_VARARGS, NULL},
 {(char *) "virConnectListDefinedInterfaces", 
libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
 {(char *) "virConnectListAllInterfaces", 
libvirt_virConnectListAllInterfaces, 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 46/49] list: Implement RPC calls for virConnectListAllSecrets

2012-07-20 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 remoteDispatchConnectListAllSecrets.

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

  * src/remote/remote_protocol.x:
New RPC procedure REMOTE_PROC_CONNECT_LIST_ALL_SECRETS 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 9de0629..d381dd9 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4280,6 +4280,60 @@ cleanup:
 return rv;
 }
 
+static int
+remoteDispatchConnectListAllSecrets(virNetServerPtr server ATTRIBUTE_UNUSED,
+virNetServerClientPtr client,
+virNetMessagePtr msg ATTRIBUTE_UNUSED,
+virNetMessageErrorPtr rerr,
+remote_connect_list_all_secrets_args *args,
+remote_connect_list_all_secrets_ret *ret)
+{
+virSecretPtr *secrets = NULL;
+int nsecrets = 0;
+int i;
+int rv = -1;
+struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
+
+if (!priv->conn) {
+virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+goto cleanup;
+}
+
+if ((nsecrets = virConnectListAllSecrets(priv->conn,
+ args->need_results ? &secrets : 
NULL,
+ args->flags)) < 0)
+goto cleanup;
+
+if (secrets && nsecrets) {
+if (VIR_ALLOC_N(ret->secrets.secrets_val, nsecrets) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret->secrets.secrets_len = nsecrets;
+
+for (i = 0; i < nsecrets; i++)
+make_nonnull_secret(ret->secrets.secrets_val + i, secrets[i]);
+} else {
+ret->secrets.secrets_len = 0;
+ret->secrets.secrets_val = NULL;
+}
+
+ret->ret = nsecrets;
+
+rv = 0;
+
+cleanup:
+if (rv < 0)
+virNetMessageSaveError(rerr);
+if (secrets) {
+for (i = 0; i < nsecrets; i++)
+virSecretFree(secrets[i]);
+VIR_FREE(secrets);
+}
+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 ee6caf4..075cec1 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3031,6 +3031,69 @@ done:
 return rv;
 }
 
+static int
+remoteConnectListAllSecrets(virConnectPtr conn,
+virSecretPtr **secrets,
+unsigned int flags)
+{
+int rv = -1;
+int i;
+virSecretPtr *tmp_secrets = NULL;
+remote_connect_list_all_secrets_args args;
+remote_connect_list_all_secrets_ret ret;
+
+struct private_data *priv = conn->privateData;
+
+remoteDriverLock(priv);
+
+args.need_results = !!secrets;
+args.flags = flags;
+
+memset(&ret, 0, sizeof(ret));
+if (call(conn,
+ priv,
+ 0,
+ REMOTE_PROC_CONNECT_LIST_ALL_SECRETS,
+ (xdrproc_t) xdr_remote_connect_list_all_secrets_args,
+ (char *) &args,
+ (xdrproc_t) xdr_remote_connect_list_all_secrets_ret,
+ (char *) &ret) == -1)
+goto done;
+
+if (secrets) {
+if (VIR_ALLOC_N(tmp_secrets, ret.secrets.secrets_len + 1) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+
+for (i = 0; i < ret.secrets.secrets_len; i++) {
+tmp_secrets[i] = get_nonnull_secret (conn, 
ret.secrets.secrets_val[i]);
+if (!tmp_secrets[i]) {
+virReportOOMError();
+goto cleanup;
+}
+}
+*secrets = tmp_secrets;
+tmp_secrets = NULL;
+}
+
+rv = ret.ret;
+
+cleanup:
+if (tmp_secrets) {
+for (i = 0; i < ret.secrets.secrets_len; i++)
+if (tmp_secrets[i])
+virSecretFree(tmp_secrets[i]);
+VIR_FREE(tmp_secrets);
+}
+
+xdr_free((xdrproc_t) xdr_remote_connect_list_all_secrets_ret, (char *) 
&ret);
+
+done:
+remoteDriverUnlock(priv);
+return rv;
+}
+
 /*--*/
 
 static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
@@ -5827,6 +5890,7 @@ static virSecretDriver secret_driver = {
 .close = remoteSecretClose, /* 0.7.1 */
 .numOfSecrets = remoteNumOfSecrets, /* 0.7.1 */
 .l

[libvirt] [PATCH 47/49] list: Implement listAllSecrets

2012-07-20 Thread Osier Yang
Simply returns the object list. No filtering.

src/secret/secret_driver.c: Implement listAllSecrets
---
 src/secret/secret_driver.c |   58 +++-
 1 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index af3bfcf..a2b2383 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -601,7 +601,6 @@ cleanup:
 return -1;
 }
 
-
 static const char *
 secretUsageIDForDef(virSecretDefPtr def)
 {
@@ -620,6 +619,62 @@ secretUsageIDForDef(virSecretDefPtr def)
 }
 }
 
+static int
+secretListAllSecrets(virConnectPtr conn,
+ virSecretPtr **secrets,
+ unsigned int flags) {
+virSecretDriverStatePtr driver = conn->secretPrivateData;
+virSecretPtr *tmp_secrets = NULL;
+int nsecrets = 0;
+virSecretPtr secret = NULL;
+virSecretEntryPtr entry = NULL;
+int i = 0;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+secretDriverLock(driver);
+
+for (entry = driver->secrets; entry != NULL; entry = entry ->next)
+nsecrets++;
+
+if (!secrets) {
+ret = nsecrets;
+goto cleanup;
+}
+
+if (VIR_ALLOC_N(tmp_secrets, nsecrets + 1) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+
+for (entry = driver->secrets; entry != NULL; entry = entry ->next) {
+if (!(secret = virGetSecret(conn,
+entry->def->uuid,
+entry->def->usage_type,
+secretUsageIDForDef(entry->def
+goto cleanup;
+tmp_secrets[i++] = secret;
+}
+
+*secrets = tmp_secrets;
+tmp_secrets = NULL;
+ret = i;
+
+ cleanup:
+secretDriverUnlock(driver);
+if (tmp_secrets) {
+for (i = 0; i < nsecrets; i ++) {
+if (tmp_secrets[i])
+virSecretFree(tmp_secrets[i]);
+}
+}
+VIR_FREE(tmp_secrets);
+
+return ret;
+}
+
+
 static virSecretPtr
 secretLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
 {
@@ -1072,6 +1127,7 @@ static virSecretDriver secretDriver = {
 .close = secretClose, /* 0.7.1 */
 .numOfSecrets = secretNumOfSecrets, /* 0.7.1 */
 .listSecrets = secretListSecrets, /* 0.7.1 */
+.listAllSecrets = secretListAllSecrets, /* 0.9.14 */
 .lookupByUUID = secretLookupByUUID, /* 0.7.1 */
 .lookupByUsage = secretLookupByUsage, /* 0.7.1 */
 .defineXML = secretDefineXML, /* 0.7.1 */
-- 
1.7.7.3

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


[libvirt] [PATCH 43/49] list: Use virConnectListAllNWFilters in virsh

2012-07-20 Thread Osier Yang
tools/virsh.c:
  * vshNWFilterSorter to sort network filters by name

  * vshNWFilterListFree to free the network filter objects list.

  * vshNWFilterListCollect to collect the network filter objects, trying
to use new API first, fall back to older APIs if it's not supported.
---
 tools/virsh.c |  164 ++--
 1 files changed, 134 insertions(+), 30 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 5a5d388..b5c4d97 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -10420,6 +10420,134 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
 return ret;
 }
 
+static int
+vshNWFilterSorter(const void *a, const void *b)
+{
+virNWFilterPtr *fa = (virNWFilterPtr *) a;
+virNWFilterPtr *fb = (virNWFilterPtr *) b;
+
+if (*fa && !*fb)
+return -1;
+
+if (!*fa)
+return *fb != NULL;
+
+return strcasecmp(virNWFilterGetName(*fa),
+  virNWFilterGetName(*fb));
+}
+
+struct vshNWFilterList {
+virNWFilterPtr *filters;
+size_t nfilters;
+};
+typedef struct vshNWFilterList *vshNWFilterListPtr;
+
+static void
+vshNWFilterListFree(vshNWFilterListPtr list)
+{
+int i;
+
+if (list && list->nfilters) {
+for (i = 0; i < list->nfilters; i++) {
+if (list->filters[i])
+virNWFilterFree(list->filters[i]);
+}
+VIR_FREE(list->filters);
+}
+VIR_FREE(list);
+}
+
+static vshNWFilterListPtr
+vshNWFilterListCollect(vshControl *ctl,
+   unsigned int flags)
+{
+vshNWFilterListPtr list = vshMalloc(ctl, sizeof(*list));
+int i;
+int ret;
+virNWFilterPtr filter;
+bool success = false;
+size_t deleted = 0;
+int nfilters = 0;
+char **names = NULL;
+
+/* try the list with flags support (0.9.14 and later) */
+if ((ret = virConnectListAllNWFilters(ctl->conn,
+  &list->filters,
+  flags)) >= 0) {
+list->nfilters = ret;
+goto finished;
+}
+
+/* check if the command is actually supported */
+if (last_error && last_error->code == VIR_ERR_NO_SUPPORT) {
+virFreeError(last_error);
+last_error = NULL;
+goto fallback;
+}
+
+/* there was an error during the call */
+vshError(ctl, "%s", _("Failed to list node filters"));
+goto cleanup;
+
+
+fallback:
+/* fall back to old method (0.9.13 and older) */
+virResetLastError();
+
+nfilters = virConnectNumOfNWFilters(ctl->conn);
+if (nfilters < 0) {
+vshError(ctl, "%s", _("Failed to count network filters"));
+goto cleanup;
+}
+
+if (nfilters == 0)
+return list;
+
+names = vshMalloc(ctl, sizeof(char *) * nfilters);
+
+nfilters = virConnectListNWFilters(ctl->conn, names, nfilters);
+if (nfilters < 0) {
+vshError(ctl, "%s", _("Failed to list network filters"));
+goto cleanup;
+}
+
+list->filters = vshMalloc(ctl, sizeof(virNWFilterPtr) * (nfilters));
+list->nfilters = 0;
+
+/* get the network filters */
+for (i = 0; i < nfilters ; i++) {
+if (!(filter = virNWFilterLookupByName(ctl->conn, names[i])))
+continue;
+list->filters[list->nfilters++] = filter;
+}
+
+/* truncate network filters that weren't found */
+deleted = nfilters - list->nfilters;
+
+finished:
+/* sort the list */
+if (list->filters && list->nfilters)
+qsort(list->filters, list->nfilters,
+  sizeof(*list->filters), vshNWFilterSorter);
+
+/* truncate the list for not found filter objects */
+if (deleted)
+VIR_SHRINK_N(list->filters, list->nfilters, deleted);
+
+success = true;
+
+cleanup:
+for (i = 0; i < nfilters; i++)
+VIR_FREE(names[i]);
+VIR_FREE(names);
+
+if (!success) {
+vshNWFilterListFree(list);
+list = NULL;
+}
+
+return list;
+}
 /*
  * "nwfilter-list" command
  */
@@ -10436,57 +10564,33 @@ static const vshCmdOptDef opts_nwfilter_list[] = {
 static bool
 cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
-int numfilters, i;
-char **names;
+int i;
 char uuid[VIR_UUID_STRING_BUFLEN];
+vshNWFilterListPtr list = NULL;
 
 if (!vshConnectionUsability(ctl, ctl->conn))
 return false;
 
-numfilters = virConnectNumOfNWFilters(ctl->conn);
-if (numfilters < 0) {
-vshError(ctl, "%s", _("Failed to list network filters"));
-return false;
-}
-
-names = vshMalloc(ctl, sizeof(char *) * numfilters);
-
-if ((numfilters = virConnectListNWFilters(ctl->conn, names,
-  numfilters)) < 0) {
-vshError(ctl, "%s", _("Failed to list network filters"));
-VIR_FREE(names);
+if (!(list = vshNWFilterListCollect(ctl, 0)))
 return false;
-}
-
-qsort(&names[0], numfilters, sizeof(char *), vshNameSor

[libvirt] [PATCH 45/49] list: Define new API virConnectListAllSecrets

2012-07-20 Thread Osier Yang
This is to list the secret objects. No flags are supported

include/libvirt/libvirt.h.in: Declare enum virConnectListAllSecretFlags
  and virConnectListAllSecrets.
python/generator.py: Skip auto-generating
src/driver.h: (virDrvConnectListAllSecrets)
src/libvirt.c: Implement the public API
src/libvirt_public.syms: Export the symbol to public
---
 include/libvirt/libvirt.h.in |3 ++
 python/generator.py  |1 +
 src/driver.h |5 
 src/libvirt.c|   50 ++
 src/libvirt_public.syms  |1 +
 5 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index aea4d8a..c67c89b 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3164,6 +3164,9 @@ int virConnectNumOfSecrets  
(virConnectPtr conn);
 int virConnectListSecrets   (virConnectPtr conn,
  char **uuids,
  int maxuuids);
+int virConnectListAllSecrets(virConnectPtr conn,
+ virSecretPtr **secrets,
+ unsigned int flags);
 virSecretPtrvirSecretLookupByUUID(virConnectPtr conn,
   const unsigned char *uuid);
 virSecretPtrvirSecretLookupByUUIDString(virConnectPtr conn,
diff --git a/python/generator.py b/python/generator.py
index 00e242f..447ff47 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -462,6 +462,7 @@ skip_function = (
 'virConnectListAllInterfaces', # overridden in virConnect.py
 'virConnectListAllNodeDevices', # overridden in virConnect.py
 'virConnectListAllNWFilters', # overridden in virConnect.py
+'virConnectListAllSecrets', # 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 5ace502..8c1d799 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1540,6 +1540,10 @@ typedef int
 (*virDrvListSecrets)   (virConnectPtr conn,
 char **uuids,
 int maxuuids);
+typedef int
+(*virDrvListAllSecrets)(virConnectPtr conn,
+virSecretPtr **secrets,
+unsigned int flags);
 
 typedef struct _virSecretDriver virSecretDriver;
 typedef virSecretDriver *virSecretDriverPtr;
@@ -1561,6 +1565,7 @@ struct _virSecretDriver {
 
 virDrvNumOfSecrets  numOfSecrets;
 virDrvListSecrets   listSecrets;
+virDrvListAllSecretslistAllSecrets;
 virDrvSecretLookupByUUIDlookupByUUID;
 virDrvSecretLookupByUsage   lookupByUsage;
 virDrvSecretDefineXML   defineXML;
diff --git a/src/libvirt.c b/src/libvirt.c
index ff02c88..009e99f 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -14350,6 +14350,56 @@ error:
 }
 
 /**
+ * virConnectListAllSecrets:
+ * @conn: Pointer to the hypervisor connection.
+ * @secrets: Pointer to a variable to store the array containing the secret
+ *   objects or NULL if the list is not required (just returns the
+ *   number of secrets).
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Collect the list of secrets, and allocate an array to store those objects.
+ *
+ * Returns the number of secrets found or -1 and sets @secrets to NULL in case
+ * of error.  On success, the array stored into @secrets 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
+ * virSecretFree() on each array element, then calling free() on @secrets.
+ */
+int
+virConnectListAllSecrets(virConnectPtr conn,
+ virSecretPtr **secrets,
+ unsigned int flags)
+{
+VIR_DEBUG("conn=%p, secrets=%p, flags=%x", conn, secrets, flags);
+
+virResetLastError();
+
+if (secrets)
+*secrets = NULL;
+
+if (!VIR_IS_CONNECT(conn)) {
+virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+virDispatchError(NULL);
+return -1;
+}
+
+if (conn->secretDriver &&
+conn->secretDriver->listAllSecrets) {
+int ret;
+ret = conn->secretDriver->listAllSecrets(conn, secrets, flags);
+if (ret < 0)
+goto error;
+return ret;
+}
+
+virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+virDispatchError(conn);
+return -1;
+}
+
+/**
  * virConnectListSecrets:
  * @conn: virConnect connection
  * @uuids: Pointer to an array to store the UUIDs
diff --git 

[libvirt] [PATCH 36/49] list: Implement listAllNodeDevices

2012-07-20 Thread Osier Yang
This simply implements listAllNodeDevices using helper virNodeDeviceList

src/node_device/node_device_driver.h:
  * Declare nodeListAllNodeDevices.

src/node_device/node_device_driver.c:
  * Implement nodeListAllNodeDevices.

src/node_device/node_device_hal.c:
  * Hook listAllNodeDevices to nodeListAllNodeDevices.

src/node_device/node_device_udev.c
  * Hook listAllNodeDevices to nodeListAllNodeDevices.
---
 src/node_device/node_device_driver.c |   16 
 src/node_device/node_device_driver.h |3 +++
 src/node_device/node_device_hal.c|1 +
 src/node_device/node_device_udev.c   |1 +
 4 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/src/node_device/node_device_driver.c 
b/src/node_device/node_device_driver.c
index 83db775..52df49e 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -37,6 +37,7 @@
 #include "node_device_conf.h"
 #include "node_device_hal.h"
 #include "node_device_driver.h"
+#include "virobjectlist.h"
 #include "util.h"
 
 #define VIR_FROM_THIS VIR_FROM_NODEDEV
@@ -183,6 +184,21 @@ nodeListDevices(virConnectPtr conn,
 return -1;
 }
 
+int
+nodeListAllNodeDevices(virConnectPtr conn,
+   virNodeDevicePtr **devices,
+   unsigned int flags)
+{
+virDeviceMonitorStatePtr driver = conn->devMonPrivateData;
+int ret = -1;
+
+virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP, -1);
+
+nodeDeviceLock(driver);
+ret = virNodeDeviceList(conn, driver->devs, devices, flags);
+nodeDeviceUnlock(driver);
+return ret;
+}
 
 virNodeDevicePtr
 nodeDeviceLookupByName(virConnectPtr conn, const char *name)
diff --git a/src/node_device/node_device_driver.h 
b/src/node_device/node_device_driver.h
index 673e95b..deab618 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -73,6 +73,9 @@ int read_wwn_linux(int host, const char *file, char **wwn);
 int nodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags);
 int nodeListDevices(virConnectPtr conn, const char *cap, char **const names,
 int maxnames, unsigned int flags);
+int nodeListAllNodeDevices(virConnectPtr conn,
+   virNodeDevicePtr **devices,
+   unsigned int flags);
 virNodeDevicePtr nodeDeviceLookupByName(virConnectPtr conn, const char *name);
 char *nodeDeviceGetXMLDesc(virNodeDevicePtr dev, unsigned int flags);
 char *nodeDeviceGetParent(virNodeDevicePtr dev);
diff --git a/src/node_device/node_device_hal.c 
b/src/node_device/node_device_hal.c
index 7f8b076..c06f977 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -770,6 +770,7 @@ static virDeviceMonitor halDeviceMonitor = {
 .close = halNodeDrvClose, /* 0.5.0 */
 .numOfDevices = nodeNumOfDevices, /* 0.5.0 */
 .listDevices = nodeListDevices, /* 0.5.0 */
+.listAllNodeDevices = nodeListAllNodeDevices, /* 0.9.14 */
 .deviceLookupByName = nodeDeviceLookupByName, /* 0.5.0 */
 .deviceGetXMLDesc = nodeDeviceGetXMLDesc, /* 0.5.0 */
 .deviceGetParent = nodeDeviceGetParent, /* 0.5.0 */
diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index aa96abd..33dd3e9 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1757,6 +1757,7 @@ static virDeviceMonitor udevDeviceMonitor = {
 .close = udevNodeDrvClose, /* 0.7.3 */
 .numOfDevices = nodeNumOfDevices, /* 0.7.3 */
 .listDevices = nodeListDevices, /* 0.7.3 */
+.listAllNodeDevices = nodeListAllNodeDevices, /* 0.9.14 */
 .deviceLookupByName = nodeDeviceLookupByName, /* 0.7.3 */
 .deviceGetXMLDesc = nodeDeviceGetXMLDesc, /* 0.7.3 */
 .deviceGetParent = nodeDeviceGetParent, /* 0.7.3 */
-- 
1.7.7.3

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


[libvirt] [PATCH 33/49] list: Define new API virConnectListAllNodeDevices

2012-07-20 Thread Osier Yang
This is to list the node device objects, supports to filter the results
by capability types.

include/libvirt/libvirt.h.in: Declare enum virConnectListAllNodeDeviceFlags
  and virConnectListAllNodeDevices.
python/generator.py: Skip auto-generating
src/driver.h: (virDrvConnectListAllNodeDevices)
src/libvirt.c: Implement the public API
src/libvirt_public.syms: Export the symbol to public
---
 include/libvirt/libvirt.h.in |   25 +
 python/generator.py  |1 +
 src/driver.h |4 +++
 src/libvirt.c|   59 ++
 src/libvirt_public.syms  |1 +
 5 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 15e2363..cfdb162 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2750,6 +2750,31 @@ int virNodeListDevices  
(virConnectPtr conn,
  char **const names,
  int maxnames,
  unsigned int flags);
+/*
+ * virConnectListAllNodeDevices:
+ *
+ * Flags used to filter the returned node devices. Flags in each group
+ * are exclusive.
+ */
+typedef enum {
+/* Reserved the first 6 bits for the possibility of persistent
+ * node device support in future.
+ */
+
+VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM= 1 << 6,
+VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV   = 1 << 7,
+VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV   = 1 << 8,
+VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE = 1 << 9,
+VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET   = 1 << 10,
+VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST = 1 << 11,
+VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET   = 1 << 12,
+VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI  = 1 << 13,
+VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE   = 1 << 14,
+} virConnectListAllNodeDeviceFlags;
+
+int virConnectListAllNodeDevices (virConnectPtr conn,
+  virNodeDevicePtr 
**devices,
+  unsigned int flags);
 
 virNodeDevicePtrvirNodeDeviceLookupByName (virConnectPtr conn,
const char *name);
diff --git a/python/generator.py b/python/generator.py
index 51c3fce..6f50fa0 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -460,6 +460,7 @@ skip_function = (
 'virStoragePoolListAllVolumes', # overridden in virStoragePool.py
 'virConnectListAllNetworks', # overridden in virConnect.py
 'virConnectListAllInterfaces', # overridden in virConnect.py
+'virConnectListAllNodeDevices', # 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 335ee86..102684c 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1456,6 +1456,9 @@ typedef int (*virDevMonListDevices)(virConnectPtr conn,
 char **const names,
 int maxnames,
 unsigned int flags);
+typedef int (*virDevMonListAllNodeDevices)(virConnectPtr conn,
+   virNodeDevicePtr **devices,
+   unsigned int flags);
 
 typedef virNodeDevicePtr (*virDevMonDeviceLookupByName)(virConnectPtr conn,
 const char *name);
@@ -1489,6 +1492,7 @@ struct _virDeviceMonitor {
 virDrvClose close;
 virDevMonNumOfDevices   numOfDevices;
 virDevMonListDeviceslistDevices;
+virDevMonListAllNodeDevices listAllNodeDevices;
 virDevMonDeviceLookupByName deviceLookupByName;
 virDevMonDeviceGetXMLDesc   deviceGetXMLDesc;
 virDevMonDeviceGetParentdeviceGetParent;
diff --git a/src/libvirt.c b/src/libvirt.c
index c50bb3d..6d4cd76 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -13559,6 +13559,65 @@ error:
 return -1;
 }
 
+/**
+ * virConnectListAllNodeDevices:
+ * @conn: Pointer to the hypervisor connection.
+ * @devices: Pointer to a variable to store the array containing the node
+ *   device objects or NULL if the list is not required (just returns
+ *   number of node devices).
+ * @flags: bitwise-OR of virConnectListAllNodeDevices.
+ *
+ * Collect the list of node devices, and allocate an array to store those
+ * objects.
+ *
+ * By default, this API covers all node devices; it is also possible to return
+ * the filtered objects with flags. Filters are provided in groups, where each
+ * group contains bits that describe mutually exclusive attributes of a node
+ * device.
+ *
+ * 

[libvirt] [PATCH 40/49] list: Define new API virConnectListAllNWFilters

2012-07-20 Thread Osier Yang
This is to list the network fitler objects. No flags are supported

include/libvirt/libvirt.h.in: Declare enum virConnectListAllNWFilterFlags
  and virConnectListAllNWFilters.
python/generator.py: Skip auto-generating
src/driver.h: (virDrvConnectListAllNWFilters)
src/libvirt.c: Implement the public API
src/libvirt_public.syms: Export the symbol to public
---
 include/libvirt/libvirt.h.in |4 ++-
 python/generator.py  |1 +
 src/driver.h |5 
 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 cfdb162..aea4d8a 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -4041,7 +4041,9 @@ int virConnectNumOfNWFilters 
(virConnectPtr conn);
 int virConnectListNWFilters  (virConnectPtr conn,
   char **const names,
   int maxnames);
-
+int virConnectListAllNWFilters(virConnectPtr conn,
+   virNWFilterPtr **filters,
+   unsigned int flags);
 /*
  * Lookup nwfilter by name or uuid
  */
diff --git a/python/generator.py b/python/generator.py
index 6f50fa0..00e242f 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -461,6 +461,7 @@ skip_function = (
 'virConnectListAllNetworks', # overridden in virConnect.py
 'virConnectListAllInterfaces', # overridden in virConnect.py
 'virConnectListAllNodeDevices', # overridden in virConnect.py
+'virConnectListAllNWFilters', # 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 102684c..5ace502 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1611,6 +1611,10 @@ typedef int
 (*virDrvConnectListNWFilters) (virConnectPtr conn,
char **const names,
int maxnames);
+typedef int
+(*virDrvConnectListAllNWFilters)  (virConnectPtr conn,
+   virNWFilterPtr **filters,
+   unsigned int flags);
 typedef virNWFilterPtr
 (*virDrvNWFilterLookupByName) (virConnectPtr conn,
const char *name);
@@ -1648,6 +1652,7 @@ struct _virNWFilterDriver {
 
 virDrvConnectNumOfNWFilters numOfNWFilters;
 virDrvConnectListNWFilters  listNWFilters;
+virDrvConnectListAllNWFilters  listAllNWFilters;
 virDrvNWFilterLookupByName  nwfilterLookupByName;
 virDrvNWFilterLookupByUUID  nwfilterLookupByUUID;
 virDrvNWFilterDefineXML defineXML;
diff --git a/src/libvirt.c b/src/libvirt.c
index 6d4cd76..ff02c88 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -15931,6 +15931,56 @@ error:
 return -1;
 }
 
+/**
+ * virConnectListAllNWFilters:
+ * @conn: Pointer to the hypervisor connection.
+ * @filters: Pointer to a variable to store the array containing the network
+ *   filter objects or NULL if the list is not required (just returns
+ *   number of network filters).
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Collect the list of network filters, and allocate an array to store those
+ * objects.
+ *
+ * Returns the number of network filters found or -1 and sets @filters to  NULL
+ * in case of error.  On success, the array stored into @filters 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
+ * virNWFilterFree() on each array element, then calling free() on @filters.
+ */
+int
+virConnectListAllNWFilters(virConnectPtr conn,
+   virNWFilterPtr **filters,
+   unsigned int flags)
+{
+VIR_DEBUG("conn=%p, filters=%p, flags=%x", conn, filters, flags);
+
+virResetLastError();
+
+if (filters)
+*filters = NULL;
+
+if (!VIR_IS_CONNECT(conn)) {
+virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+virDispatchError(NULL);
+return -1;
+}
+
+if (conn->nwfilterDriver &&
+conn->nwfilterDriver->listAllNWFilters) {
+int ret;
+ret = conn->nwfilterDriver->listAllNWFilters(conn, filters, flags);
+if (ret < 0)
+goto error;
+return ret;
+}
+
+virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+virDispatchError(conn);
+return -1;
+}
 
 /**
  * virConnectListNWFilters:
diff --git a/src/libvirt_public.syms b/src/libvirt

[libvirt] [PATCH 37/49] list: Expose virConnectListAllNodeDevices to Python binding

2012-07-20 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:
  * Implementation for listAllNodeDevices.

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

diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index ab6f407..a3d6bbb 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -346,6 +346,12 @@
   
   
 
+
+  returns list of all host node devices
+  
+  
+  
+
 
   list the node device's capabilities
   
diff --git a/python/libvirt-override-virConnect.py 
b/python/libvirt-override-virConnect.py
index ffa1a3c..c34cd63 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -242,3 +242,16 @@
 retlist.append(virInterface(self, _obj=ifaceptr))
 
 return retlist
+
+def listAllDevices(self, flags):
+"""Returns a list of host node device objects"""
+ret = libvirtmod.virConnectListAllNodeDevices(self._o, flags)
+if ret is None:
+raise libvirtError("virConnectListAllNodeDevices() failed", 
conn=self)
+
+retlist = list()
+for devptr in ret:
+retlist.append(virNodeDevice(self, _obj=devptr))
+
+return retlist
+
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 98ed40f..6449639 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -3383,6 +3383,53 @@ libvirt_virNodeListDevices(PyObject *self 
ATTRIBUTE_UNUSED,
 }
 
 static PyObject *
+libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+PyObject *pyobj_conn;
+PyObject *py_retval = NULL;
+PyObject *tmp = NULL;
+virConnectPtr conn;
+virNodeDevicePtr *devices = NULL;
+int c_retval = 0;
+int i;
+unsigned int flags;
+
+if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllNodeDevices",
+  &pyobj_conn, &flags))
+return NULL;
+conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+c_retval = virConnectListAllNodeDevices(conn, &devices, 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_virNodeDevicePtrWrap(devices[i])) ||
+PyList_SetItem(py_retval, i, tmp) < 0) {
+Py_XDECREF(tmp);
+Py_DECREF(py_retval);
+py_retval = NULL;
+goto cleanup;
+}
+/* python steals the pointer */
+devices[i] = NULL;
+}
+
+cleanup:
+for (i = 0; i < c_retval; i++)
+if (devices[i])
+virNodeDeviceFree(devices[i]);
+VIR_FREE(devices);
+return py_retval;
+}
+
+static PyObject *
 libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
   PyObject *args) {
 PyObject *py_retval;
@@ -6079,6 +6126,7 @@ static PyMethodDef libvirtMethods[] = {
 {(char *) "virEventInvokeHandleCallback", 
libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL},
 {(char *) "virEventInvokeTimeoutCallback", 
libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL},
 {(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, 
NULL},
+{(char *) "virConnectListAllNodeDevices", 
libvirt_virConnectListAllNodeDevices, METH_VARARGS, NULL},
 {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, 
METH_VARARGS, NULL},
 {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID, METH_VARARGS, 
NULL},
 {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, 
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 34/49] list: Implemente RPC calls for virConnectListAllNodeDevices

2012-07-20 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 remoteDispatchConnectListAllNodeDevices.

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

  * src/remote/remote_protocol.x:
New RPC procedure REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES and
---
 daemon/remote.c  |   53 ++
 src/remote/remote_driver.c   |   64 ++
 src/remote/remote_protocol.x |   14 -
 src/remote_protocol-structs  |   12 
 4 files changed, 142 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index aec7b3c..5a16dbe 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4172,6 +4172,59 @@ cleanup:
 return rv;
 }
 
+static int
+remoteDispatchConnectListAllNodeDevices(virNetServerPtr server 
ATTRIBUTE_UNUSED,
+virNetServerClientPtr client,
+virNetMessagePtr msg ATTRIBUTE_UNUSED,
+virNetMessageErrorPtr rerr,
+
remote_connect_list_all_node_devices_args *args,
+
remote_connect_list_all_node_devices_ret *ret)
+{
+virNodeDevicePtr *devices = NULL;
+int ndevices = 0;
+int i;
+int rv = -1;
+struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
+
+if (!priv->conn) {
+virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+goto cleanup;
+}
+
+if ((ndevices = virConnectListAllNodeDevices(priv->conn,
+ args->need_results ? &devices 
: NULL,
+ args->flags)) < 0)
+goto cleanup;
+
+if (devices && ndevices) {
+if (VIR_ALLOC_N(ret->devices.devices_val, ndevices) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret->devices.devices_len = ndevices;
+
+for (i = 0; i < ndevices; i++)
+make_nonnull_node_device(ret->devices.devices_val + i, devices[i]);
+} else {
+ret->devices.devices_len = 0;
+ret->devices.devices_val = NULL;
+}
+
+ret->ret = ndevices;
+
+rv = 0;
+
+cleanup:
+if (rv < 0)
+virNetMessageSaveError(rerr);
+if (devices) {
+for (i = 0; i < ndevices; i++)
+virNodeDeviceFree(devices[i]);
+VIR_FREE(devices);
+}
+return rv;
+}
 
 /*- Helpers. -*/
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 2b7c05e..22aad2f 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2905,6 +2905,69 @@ done:
 return rv;
 }
 
+static int
+remoteConnectListAllNodeDevices(virConnectPtr conn,
+virNodeDevicePtr **devices,
+unsigned int flags)
+{
+int rv = -1;
+int i;
+virNodeDevicePtr *tmp_devices = NULL;
+remote_connect_list_all_node_devices_args args;
+remote_connect_list_all_node_devices_ret ret;
+
+struct private_data *priv = conn->privateData;
+
+remoteDriverLock(priv);
+
+args.need_results = !!devices;
+args.flags = flags;
+
+memset(&ret, 0, sizeof(ret));
+if (call(conn,
+ priv,
+ 0,
+ REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES,
+ (xdrproc_t) xdr_remote_connect_list_all_node_devices_args,
+ (char *) &args,
+ (xdrproc_t) xdr_remote_connect_list_all_node_devices_ret,
+ (char *) &ret) == -1)
+goto done;
+
+if (devices) {
+if (VIR_ALLOC_N(tmp_devices, ret.devices.devices_len + 1) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+
+for (i = 0; i < ret.devices.devices_len; i++) {
+tmp_devices[i] = get_nonnull_node_device(conn, 
ret.devices.devices_val[i]);
+if (!tmp_devices[i]) {
+virReportOOMError();
+goto cleanup;
+}
+}
+*devices = tmp_devices;
+tmp_devices = NULL;
+}
+
+rv = ret.ret;
+
+cleanup:
+if (tmp_devices) {
+for (i = 0; i < ret.devices.devices_len; i++)
+if (tmp_devices[i])
+virNodeDeviceFree(tmp_devices[i]);
+VIR_FREE(tmp_devices);
+}
+
+xdr_free((xdrproc_t) xdr_remote_connect_list_all_node_devices_ret, (char 
*) &ret);
+
+done:
+remoteDriverUnlock(priv);
+return rv;
+}
+
 
 /*--*/
 
@@ -5717,6 +5780,7 @@ static virDeviceMonitor dev_monitor = {
 .close = remoteDevMonClose, /* 0.5.0 */
 .numOfDevices = remoteNodeNumOfDevices, /* 0.5.0 */
 .listDevices = remoteNodeListDevices, /* 0.5.0 */
+.listAllNodeDevi

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

2012-07-20 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 @@
   
   
 
+
+  returns list of all interfaces
+  
+  
+  
+
 
   Computes the most feature-rich CPU which is compatible with all 
given host CPUs.
   
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 5dd9657..98ed40f 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;
@@ -6045,6 +6092,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


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

2012-07-20 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 @@
   
   
 
+
+  returns list of all networks
+  
+  
+  
+
 
   Try to lookup a domain on the given hypervisor based on its 
UUID.
   
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 322a8d2..5dd9657 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) {
@@ -5939,6 +5986,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 25/49] list: Use virConnectListAllNetworks in virsh

2012-07-20 Thread Osier Yang
tools/virsh.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.c   |  347 +--
 tools/virsh.pod |   12 ++-
 2 files changed, 273 insertions(+), 86 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 9556e16..fb12d80 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -8862,6 +8862,227 @@ cleanup:
 return ret;
 }
 
+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 strcasecmp(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.9.14 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) {
+virFreeError(last_error);
+last_error = NULL;
+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);
+
+virFreeError(last_error);
+last_error = NULL;
+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) */
+virResetLastError();
+
+/* 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,
+  &names[nActiveNets],
+  nInactiveNets) < 0) {
+vshError(ctl, "%s", _("Failed to list inactive netwo

[libvirt] [PATCHv3 2/2] qemu: Disk Geometry Override Support

2012-07-20 Thread Viktor Mihajlovski
From: J.B. Joret 

Qemu command line generation for geometry override and testcases.

V2 Changes: squashed qemu code and testcases.

V3 Changes: use virReportError.

Signed-off-by: J.B. Joret 
Signed-off-by: Viktor Mihajlovski 
---
 src/qemu/qemu_command.c|   59 
 .../qemuxml2argv-disk-geometry.args|4 +
 .../qemuxml2argv-disk-geometry.xml |   26 +
 tests/qemuxml2argvtest.c   |2 +
 4 files changed, 91 insertions(+), 0 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d34af96..30dfcbd 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2016,6 +2016,8 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
 {
 virBuffer opt = VIR_BUFFER_INITIALIZER;
 const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
+const char *trans =
+virDomainDiskGeometryTransTypeToString(disk->geometry.trans);
 int idx = virDiskNameToIndex(disk->dst);
 int busid = -1, unitid = -1;
 
@@ -2218,6 +2220,24 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
 disk->type != VIR_DOMAIN_DISK_TYPE_DIR &&
 qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_FORMAT))
 virBufferAsprintf(&opt, ",format=%s", disk->driverType);
+
+/* generate geometry command string*/
+if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK ||
+disk->type == VIR_DOMAIN_DISK_TYPE_FILE) {
+if (disk->geometry.cylinders > 0 &&
+disk->geometry.heads > 0 &&
+disk->geometry.sectors > 0) {
+
+virBufferAsprintf(&opt, ",cyls=%u,heads=%u,secs=%u",
+  disk->geometry.cylinders,
+  disk->geometry.heads,
+  disk->geometry.sectors);
+
+if (disk->geometry.trans != VIR_DOMAIN_DISK_TRANS_DEFAULT)
+virBufferEscapeString(&opt, ",trans=%s", trans);
+}
+}
+
 if (disk->serial &&
 qemuCapsGet(qemuCaps, QEMU_CAPS_DRIVE_SERIAL)) {
 if (qemuSafeSerialParamValue(disk->serial) < 0)
@@ -6599,6 +6619,7 @@ qemuParseCommandLineDisk(virCapsPtr caps,
 int idx = -1;
 int busid = -1;
 int unitid = -1;
+int trans = VIR_DOMAIN_DISK_TRANS_DEFAULT;
 
 if ((nkeywords = qemuParseKeywords(val,
&keywords,
@@ -6803,6 +6824,44 @@ qemuParseCommandLineDisk(virCapsPtr caps,
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse io mode '%s'"), values[i]);
 }
+} else if (STREQ(keywords[i], "cyls")) {
+if (virStrToLong_ui(values[i], NULL, 10,
+&(def->geometry.cylinders)) < 0) {
+virDomainDiskDefFree(def);
+def = NULL;
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("cannot parse cylinders value'%s'"),
+   values[i]);
+}
+} else if (STREQ(keywords[i], "heads")) {
+if (virStrToLong_ui(values[i], NULL, 10,
+&(def->geometry.heads)) < 0) {
+virDomainDiskDefFree(def);
+def = NULL;
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("cannot parse heads value'%s'"),
+   values[i]);
+}
+} else if (STREQ(keywords[i], "secs")) {
+if (virStrToLong_ui(values[i], NULL, 10,
+&(def->geometry.sectors)) < 0) {
+virDomainDiskDefFree(def);
+def = NULL;
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("cannot parse sectors value'%s'"),
+   values[i]);
+}
+} else if (STREQ(keywords[i], "trans")) {
+def->geometry.trans =
+virDomainDiskGeometryTransTypeFromString(values[i]);
+if ((trans < VIR_DOMAIN_DISK_TRANS_DEFAULT) ||
+(trans >= VIR_DOMAIN_DISK_TRANS_LAST)) {
+virDomainDiskDefFree(def);
+def = NULL;
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("cannot parse translation value'%s'"),
+   values[i]);
+}
 }
 }
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.args 
b/tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.args
new file mode 100644
index 000..7cd6650
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-geometry.args
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
+pc -m 214 -smp 1 -nographic -monitor unix:/

[libvirt] [PATCH 29/49] list: Implemente RPC calls for virConnectListAllInterfaces

2012-07-20 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 d5c4b90..aec7b3c 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4118,6 +4118,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) {
+virNetError(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 afe6e60..2b7c05e 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2842,6 +2842,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;
+}
+
 
 /*--*/
 
@@ -5572,6 +5635,7 @@ static virInterfaceDriver interface_driver = {
 .listInterfaces = remoteListInterfaces, /* 0.7.2 */
 .numOfDefinedInterfaces = remoteNumOfDefinedInterfaces, /* 0.7.2 */
 .listDefinedInterfaces = re

[libvirt] [PATCH 24/49] list: Implement listAllNetworks for test driver

2012-07-20 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 9b528f2..ed8cd47 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3037,6 +3037,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)
 {
@@ -5696,6 +5712,7 @@ static virNetworkDriver testNetworkDriver = {
 .listNetworks = testListNetworks, /* 0.3.2 */
 .numOfDefinedNetworks = testNumDefinedNetworks, /* 0.3.2 */
 .listDefinedNetworks = testListDefinedNetworks, /* 0.3.2 */
+.listAllNetworks = testNetworkListAllNetworks, /* 0.9.14 */
 .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 28/49] list: Define new API virConnectListAllInterfaces

2012-07-20 Thread Osier Yang
This is to list the interface objects, supported filtering flags
are: active|inactive.

include/libvirt/libvirt.h.in: Declare enum virConnectListAllInterfaceFlags
  and virConnectListAllInterfaces.
python/generator.py: Skip auto-generating
src/driver.h: (virDrvConnectListAllInterfaces)
src/libvirt.c: Implement the public API
src/libvirt_public.syms: Export the symbol to public
---
 include/libvirt/libvirt.h.in |   13 +
 python/generator.py  |1 +
 src/driver.h |5 +++
 src/libvirt.c|   59 ++
 src/libvirt_public.syms  |1 +
 5 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 15a9a1b..15e2363 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2303,6 +2303,19 @@ int virConnectNumOfDefinedInterfaces 
(virConnectPtr conn);
 int virConnectListDefinedInterfaces  (virConnectPtr conn,
   char **const names,
   int maxnames);
+/*
+ * virConnectListAllInterfaces:
+ *
+ * Flags used to filter the returned interfaces.
+ */
+typedef enum {
+VIR_CONNECT_LIST_INTERFACES_INACTIVE  = 1 << 0,
+VIR_CONNECT_LIST_INTERFACES_ACTIVE= 1 << 1,
+} virConnectListAllInterfacesFlags;
+
+int virConnectListAllInterfaces (virConnectPtr conn,
+ virInterfacePtr **ifaces,
+ unsigned int flags);
 
 virInterfacePtr virInterfaceLookupByName  (virConnectPtr conn,
const char *name);
diff --git a/python/generator.py b/python/generator.py
index 44b56c2..51c3fce 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -459,6 +459,7 @@ skip_function = (
 'virConnectListAllStoragePools', # overridden in virConnect.py
 'virStoragePoolListAllVolumes', # overridden in virStoragePool.py
 'virConnectListAllNetworks', # overridden in virConnect.py
+'virConnectListAllInterfaces', # 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 68a1f04..335ee86 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1146,6 +1146,10 @@ typedef int
 (*virDrvListDefinedInterfaces)  (virConnectPtr conn,
  char **const names,
  int maxnames);
+typedef int
+(*virDrvListAllInterfaces)  (virConnectPtr conn,
+ virInterfacePtr **ifaces,
+ unsigned int flags);
 typedef virInterfacePtr
 (*virDrvInterfaceLookupByName)  (virConnectPtr conn,
  const char *name);
@@ -1204,6 +1208,7 @@ struct _virInterfaceDriver {
 virDrvListInterfaces listInterfaces;
 virDrvNumOfDefinedInterfaces numOfDefinedInterfaces;
 virDrvListDefinedInterfaces  listDefinedInterfaces;
+virDrvListAllInterfaces  listAllInterfaces;
 virDrvInterfaceLookupByName  interfaceLookupByName;
 virDrvInterfaceLookupByMACString interfaceLookupByMACString;
 virDrvInterfaceGetXMLDescinterfaceGetXMLDesc;
diff --git a/src/libvirt.c b/src/libvirt.c
index 622a590..c50bb3d 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -10507,6 +10507,65 @@ virInterfaceGetConnect (virInterfacePtr iface)
 }
 
 /**
+ * virConnectListAllInterfaces:
+ * @conn: Pointer to the hypervisor connection.
+ * @ifaces: Pointer to a variable to store the array containing the interface
+ *  objects or NULL if the list is not required (just returns number
+ *  of interfaces).
+ * @flags: bitwise-OR of virConnectListAllInterfacesFlags.
+ *
+ * Collect the list of interfaces, and allocate an array to store those
+ * objects. This API solves the race inherent between virConnectListInterfaces
+ * and virConnectListDefinedInterfaces.
+ *
+ * By default, this API covers all interfaces; it is also possible to return
+ * the filtered objects with flags. Filters are provided in groups, where each
+ * group contains bits that describe mutually exclusive attributes of a 
interface.
+ *
+ * The only one group of @flags is VIR_CONNECT_LIST_INTERFACES_INACTIVE and
+ * VIR_CONNECT_LIST_INTERFACES_INACTIVE to fitler the interfaces by state.
+ *
+ * Returns the number of interfaces found or -1 and sets @ifaces to  NULL in 
case
+ * of error.  On success, the array stored into @ifaces is guaranteed to have 
an
+ * extra allocated element set to NULL but not included in the return count,
+ * to make iteration easier.  The

[libvirt] [PATCH 31/49] list: Use virConnectListAllInterfaces in virsh

2012-07-20 Thread Osier Yang
tools/virsh.c:
  * vshInterfaceSorter to sort interfaces by name

  * vshInterfaceListFree to free the interface objects list.

  * vshInterfaceListCollect to collect the interface objects, trying
to use new API first, fall back to older APIs if it's not supported.
---
 tools/virsh.c |  258 -
 1 files changed, 183 insertions(+), 75 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index fb12d80..8e191f4 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -9310,6 +9310,174 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd)
 return true;
 }
 
+static int
+vshInterfaceSorter(const void *a, const void *b)
+{
+virInterfacePtr *ia = (virInterfacePtr *) a;
+virInterfacePtr *ib = (virInterfacePtr *) b;
+
+if (*ia && !*ib)
+return -1;
+
+if (!*ia)
+return *ib != NULL;
+
+return strcasecmp(virInterfaceGetName(*ia),
+  virInterfaceGetName(*ib));
+}
+
+struct vshInterfaceList {
+virInterfacePtr *ifaces;
+size_t nifaces;
+};
+typedef struct vshInterfaceList *vshInterfaceListPtr;
+
+static void
+vshInterfaceListFree(vshInterfaceListPtr list)
+{
+int i;
+
+if (list && list->nifaces) {
+for (i = 0; i < list->nifaces; i++) {
+if (list->ifaces[i])
+virInterfaceFree(list->ifaces[i]);
+}
+VIR_FREE(list->ifaces);
+}
+VIR_FREE(list);
+}
+
+static vshInterfaceListPtr
+vshInterfaceListCollect(vshControl *ctl,
+unsigned int flags)
+{
+vshInterfaceListPtr list = vshMalloc(ctl, sizeof(*list));
+int i;
+int ret;
+char **activeNames = NULL;
+char **inactiveNames = NULL;
+virInterfacePtr iface;
+bool success = false;
+size_t deleted = 0;
+int nActiveIfaces = 0;
+int nInactiveIfaces = 0;
+int nAllIfaces = 0;
+
+/* try the list with flags support (0.9.14 and later) */
+if ((ret = virConnectListAllInterfaces(ctl->conn,
+   &list->ifaces,
+   flags)) >= 0) {
+list->nifaces = ret;
+goto finished;
+}
+
+/* check if the command is actually supported */
+if (last_error && last_error->code == VIR_ERR_NO_SUPPORT) {
+virFreeError(last_error);
+last_error = NULL;
+goto fallback;
+}
+
+/* there was an error during the first or second call */
+vshError(ctl, "%s", _("Failed to list interfaces"));
+goto cleanup;
+
+
+fallback:
+/* fall back to old method (0.9.13 and older) */
+virResetLastError();
+
+if (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE) {
+nActiveIfaces = virConnectNumOfInterfaces(ctl->conn);
+if (nActiveIfaces < 0) {
+vshError(ctl, "%s", _("Failed to list active interfaces"));
+goto cleanup;
+}
+if (nActiveIfaces) {
+activeNames = vshMalloc(ctl, sizeof(char *) * nActiveIfaces);
+
+if ((nActiveIfaces = virConnectListInterfaces(ctl->conn, 
activeNames,
+  nActiveIfaces)) < 0) 
{
+vshError(ctl, "%s", _("Failed to list active interfaces"));
+goto cleanup;
+}
+}
+}
+
+if (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE) {
+nInactiveIfaces = virConnectNumOfDefinedInterfaces(ctl->conn);
+if (nInactiveIfaces < 0) {
+vshError(ctl, "%s", _("Failed to list inactive interfaces"));
+goto cleanup;
+}
+if (nInactiveIfaces) {
+inactiveNames = vshMalloc(ctl, sizeof(char *) * nInactiveIfaces);
+
+if ((nInactiveIfaces =
+ virConnectListDefinedInterfaces(ctl->conn, inactiveNames,
+ nInactiveIfaces)) < 0) {
+vshError(ctl, "%s", _("Failed to list inactive interfaces"));
+goto cleanup;
+}
+}
+}
+
+nAllIfaces = nActiveIfaces + nInactiveIfaces;
+if (nAllIfaces == 0) {
+VIR_FREE(activeNames);
+VIR_FREE(inactiveNames);
+return list;
+}
+
+list->ifaces = vshMalloc(ctl, sizeof(virInterfacePtr) * (nAllIfaces));
+list->nifaces = 0;
+
+/* get active interfaces */
+for (i = 0; i < nActiveIfaces; i++) {
+if (!(iface = virInterfaceLookupByName(ctl->conn, activeNames[i])))
+continue;
+list->ifaces[list->nifaces++] = iface;
+}
+
+/* get inactive interfaces */
+for (i = 0; i < nInactiveIfaces; i++) {
+if (!(iface = virInterfaceLookupByName(ctl->conn, inactiveNames[i])))
+continue;
+list->ifaces[list->nifaces++] = iface;
+}
+
+/* truncate interfaces that weren't found */
+deleted = nAllIfaces - list->nifaces;
+
+finished:
+/* sort the list */
+if (list->ifaces && list->nifaces)
+qsort(list->ifaces, list->nif

[libvirt] [PATCH 27/49] daemon: Fix the wrong macro name

2012-07-20 Thread Osier Yang
WITH_INTERFACE is not defined, it should be WITH_NETCF there to load
the interface driver.

Eric posted patch weeks ago to resolve the problems in the whole
build system, but it's not finalised yet:

https://www.redhat.com/archives/libvir-list/2012-June/msg01299.html

I'm going to simply fix the wrong macro name here so that the
interface driver could loaded, and continue the work on the listing
API for interface driver.
---
 daemon/libvirtd.c   |2 +-
 tests/virdrivermoduletest.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 8c434a0..6dca9b0 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -378,7 +378,7 @@ static void daemonInitialize(void)
 # ifdef WITH_NWFILTER
 virDriverLoadModule("nwfilter");
 # endif
-# ifdef WITH_INTERFACE
+# ifdef WITH_NETCF
 virDriverLoadModule("interface");
 # endif
 # ifdef WITH_QEMU
diff --git a/tests/virdrivermoduletest.c b/tests/virdrivermoduletest.c
index 405574e..d1fd649 100644
--- a/tests/virdrivermoduletest.c
+++ b/tests/virdrivermoduletest.c
@@ -79,7 +79,7 @@ mymain(void)
 #ifdef WITH_NWFILTER
 TEST("nwfilter", NULL);
 #endif
-#ifdef WITH_INTERFACE
+#ifdef WITH_NETCF
 TEST("interface", NULL);
 #endif
 #ifdef WITH_QEMU
-- 
1.7.7.3

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


[libvirt] [PATCH 48/49] list: Use virConnectListAllSecrets in virsh

2012-07-20 Thread Osier Yang
tools/virsh.c:
  * vshSecretSorter to sort secret object by name

  * vshSecretListFree to free the secret objects list.

  * vshSecretListCollect to collect the secret objects, trying to use
new API first, fall back to older APIs if it's not supported.
---
 tools/virsh.c |  192 +
 1 files changed, 153 insertions(+), 39 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index b5c4d97..2c92839 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -495,16 +495,6 @@ _vshStrdup(vshControl *ctl, const char *s, const char 
*filename, int line)
 #define realloc use_vshRealloc_instead_of_realloc
 #define strdup use_vshStrdup_instead_of_strdup
 
-static int
-vshNameSorter(const void *a, const void *b)
-{
-const char **sa = (const char**)a;
-const char **sb = (const char**)b;
-
-/* User visible sort, so we want locale-specific case comparison. */
-return strcasecmp(*sa, *sb);
-}
-
 static double
 prettyCapacity(unsigned long long val,
const char **unit) {
@@ -13987,6 +13977,139 @@ cleanup:
 return ret;
 }
 
+static int
+vshSecretSorter(const void *a, const void *b)
+{
+virSecretPtr *sa = (virSecretPtr *) a;
+virSecretPtr *sb = (virSecretPtr *) b;
+char uuid_sa[VIR_UUID_STRING_BUFLEN];
+char uuid_sb[VIR_UUID_STRING_BUFLEN];
+
+if (*sa && !*sb)
+return -1;
+
+if (!*sa)
+return *sb != NULL;
+
+virSecretGetUUIDString(*sa, uuid_sa);
+virSecretGetUUIDString(*sb, uuid_sb);
+
+return strcasecmp(uuid_sa, uuid_sb);
+}
+
+struct vshSecretList {
+virSecretPtr *secrets;
+size_t nsecrets;
+};
+typedef struct vshSecretList *vshSecretListPtr;
+
+static void
+vshSecretListFree(vshSecretListPtr list)
+{
+int i;
+
+if (list && list->nsecrets) {
+for (i = 0; i < list->nsecrets; i++) {
+if (list->secrets[i])
+virSecretFree(list->secrets[i]);
+}
+VIR_FREE(list->secrets);
+}
+VIR_FREE(list);
+}
+
+static vshSecretListPtr
+vshSecretListCollect(vshControl *ctl,
+ unsigned int flags)
+{
+vshSecretListPtr list = vshMalloc(ctl, sizeof(*list));
+int i;
+int ret;
+virSecretPtr secret;
+bool success = false;
+size_t deleted = 0;
+int nsecrets = 0;
+char **uuids = NULL;
+
+/* try the list with flags support (0.9.14 and later) */
+if ((ret = virConnectListAllSecrets(ctl->conn,
+&list->secrets,
+flags)) >= 0) {
+list->nsecrets = ret;
+goto finished;
+}
+
+/* check if the command is actually supported */
+if (last_error && last_error->code == VIR_ERR_NO_SUPPORT) {
+virFreeError(last_error);
+last_error = NULL;
+goto fallback;
+}
+
+/* there was an error during the call */
+vshError(ctl, "%s", _("Failed to list node secrets"));
+goto cleanup;
+
+
+fallback:
+/* fall back to old method (0.9.13 and older) */
+virResetLastError();
+
+nsecrets = virConnectNumOfSecrets(ctl->conn);
+if (nsecrets < 0) {
+vshError(ctl, "%s", _("Failed to count secrets"));
+goto cleanup;
+}
+
+if (nsecrets == 0)
+return list;
+
+uuids = vshMalloc(ctl, sizeof(char *) * nsecrets);
+
+nsecrets = virConnectListSecrets(ctl->conn, uuids, nsecrets);
+if (nsecrets < 0) {
+vshError(ctl, "%s", _("Failed to list secrets"));
+goto cleanup;
+}
+
+list->secrets = vshMalloc(ctl, sizeof(virSecretPtr) * (nsecrets));
+list->nsecrets = 0;
+
+/* get the secrets */
+for (i = 0; i < nsecrets ; i++) {
+if (!(secret = virSecretLookupByUUIDString(ctl->conn, uuids[i])))
+continue;
+list->secrets[list->nsecrets++] = secret;
+}
+
+/* truncate secrets that weren't found */
+deleted = nsecrets - list->nsecrets;
+
+finished:
+/* sort the list */
+if (list->secrets && list->nsecrets)
+qsort(list->secrets, list->nsecrets,
+  sizeof(*list->secrets), vshSecretSorter);
+
+/* truncate the list for not found secret objects */
+if (deleted)
+VIR_SHRINK_N(list->secrets, list->nsecrets, deleted);
+
+success = true;
+
+cleanup:
+for (i = 0; i < nsecrets; i++)
+VIR_FREE(uuids[i]);
+VIR_FREE(uuids);
+
+if (!success) {
+vshSecretListFree(list);
+list = NULL;
+}
+
+return list;
+}
+
 /*
  * "secret-list" command
  */
@@ -13999,59 +14122,50 @@ static const vshCmdInfo info_secret_list[] = {
 static bool
 cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
-int maxuuids = 0, i;
-char **uuids = NULL;
+int i;
+vshSecretListPtr list = NULL;
+bool ret = false;
 
 if (!vshConnectionUsability(ctl, ctl->conn))
 return false;
 
-maxuuids = virConnectNumOfSecrets(ctl->conn);
-if (maxuuids < 0) {
-vshError(ctl, "%s", _("

[libvirt] [PATCH 42/49] list: Implement listAllNWFilters

2012-07-20 Thread Osier Yang
Simply returns the object list. No filtering.

src/nwfilter/nwfilter_driver.c: Implement listAllNWFilters
---
 src/nwfilter/nwfilter_driver.c |   57 
 1 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 58d91f9..93520e1 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -335,6 +335,62 @@ nwfilterListNWFilters(virConnectPtr conn,
 }
 
 
+static int
+nwfilterListAllNWFilters(virConnectPtr conn,
+ virNWFilterPtr **filters,
+ unsigned int flags) {
+virNWFilterDriverStatePtr driver = conn->nwfilterPrivateData;
+virNWFilterPtr *tmp_filters = NULL;
+int nfilters = 0;
+virNWFilterPtr filter = NULL;
+virNWFilterObjPtr obj = NULL;
+int i;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+nwfilterDriverLock(driver);
+
+if (!filters) {
+ret = driver->nwfilters.count;
+goto cleanup;
+}
+
+if (VIR_ALLOC_N(tmp_filters, driver->nwfilters.count + 1) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+
+for (i = 0 ; i < driver->nwfilters.count; i++) {
+obj = driver->nwfilters.objs[i];
+virNWFilterObjLock(obj);
+if (!(filter = virGetNWFilter(conn, obj->def->name,
+  obj->def->uuid))) {
+virNWFilterObjUnlock(obj);
+goto cleanup;
+}
+virNWFilterObjUnlock(obj);
+tmp_filters[nfilters++] = filter;
+}
+
+*filters = tmp_filters;
+tmp_filters = NULL;
+ret = nfilters;
+
+ cleanup:
+nwfilterDriverUnlock(driver);
+if (tmp_filters) {
+for (i = 0; i < driver->nwfilters.count; i ++) {
+if (tmp_filters[i])
+virNWFilterFree(tmp_filters[i]);
+}
+}
+VIR_FREE(tmp_filters);
+
+return ret;
+}
+
+
 static virNWFilterPtr
 nwfilterDefine(virConnectPtr conn,
const char *xml)
@@ -470,6 +526,7 @@ static virNWFilterDriver nwfilterDriver = {
 .close = nwfilterClose, /* 0.8.0 */
 .numOfNWFilters = nwfilterNumNWFilters, /* 0.8.0 */
 .listNWFilters = nwfilterListNWFilters, /* 0.8.0 */
+.listAllNWFilters = nwfilterListAllNWFilters, /* 0.9.14 */
 .nwfilterLookupByName = nwfilterLookupByName, /* 0.8.0 */
 .nwfilterLookupByUUID = nwfilterLookupByUUID, /* 0.8.0 */
 .defineXML = nwfilterDefine, /* 0.8.0 */
-- 
1.7.7.3

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


[libvirt] [PATCH 22/49] list: Add helpers to list network objects

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

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

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

diff --git a/src/conf/virobjectlist.c b/src/conf/virobjectlist.c
index fb5f974..83b0d9c 100644
--- a/src/conf/virobjectlist.c
+++ b/src/conf/virobjectlist.c
@@ -191,6 +191,37 @@ virStoragePoolMatch (virStoragePoolObjPtr poolobj,
 
 return true;
 }
+
+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
@@ -340,3 +371,62 @@ cleanup:
 VIR_FREE(tmp_pools);
 return ret;
 }
+
+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;
+} else {
+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 < netobjs.count; i++) {
+if (tmp_nets[i])
+virNetworkFree(tmp_nets[i]);
+}
+}
+
+VIR_FREE(tmp_nets);
+return ret;
+}
diff --git a/src/conf/virobjectlist.h b/src/conf/virobjectlist.h
index b93cd19..431635e 100644
--- a/src/conf/virobjectlist.h
+++ b/src/conf/virobjectlist.h
@@ -28,6 +28,7 @@
 # include "virhash.h"
 # include "domain_conf.h"
 # include "storage_conf.h"
+# include "network_conf.h"
 
 # define VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE   \
 (VIR_CONNECT_LIST_DOMAINS_ACTIVE | \
@@ -105,6 +106,23 @@
  VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART  | \
  VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)
 
+# 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 virDomainList(virConnectPtr conn, virHashTablePtr domobjs,
   virDomainPtr **domains, unsigned int flags);
 
@@ -119,4 +137,9 @@ int virStoragePoolList(virConnectPtr conn,
virStoragePoolPtr 

[libvirt] [PATCH 23/49] list: Implement listAllNetworks for network driver

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

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index bb2a765..6a3ed3f 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -47,6 +47,7 @@
 #include "datatypes.h"
 #include "bridge_driver.h"
 #include "network_conf.h"
+#include "virobjectlist.h"
 #include "driver.h"
 #include "buf.h"
 #include "virpidfile.h"
@@ -2201,6 +2202,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)
 {
@@ -2689,6 +2706,7 @@ static virNetworkDriver networkDriver = {
 .listNetworks = networkListNetworks, /* 0.2.0 */
 .numOfDefinedNetworks = networkNumDefinedNetworks, /* 0.2.0 */
 .listDefinedNetworks = networkListDefinedNetworks, /* 0.2.0 */
+.listAllNetworks = networkListAllNetworks, /* 0.9.14 */
 .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 39/49] list: Use virConnectListAllNodeDevices in virsh

2012-07-20 Thread Osier Yang
tools/virsh.c:
  * vshNodeDeviceSorter to sort node devices by name

  * vshNodeDeviceListFree to free the node device objects list.

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

  * Change option --cap to accept multiple capability types.

tools/virsh.pod
  * Update document for --cap
---
 tools/virsh.c   |  301 ---
 tools/virsh.pod |8 +-
 2 files changed, 269 insertions(+), 40 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 8b85a7a..5a5d388 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -63,6 +63,7 @@
 #include "virnetdevbandwidth.h"
 #include "util/bitmap.h"
 #include "conf/domain_conf.h"
+#include "conf/node_device_conf.h"
 #include "virtypedparam.h"
 #include "intprops.h"
 #include "conf/virobjectlist.h"
@@ -14151,6 +14152,187 @@ vshNodeListLookup(int devid, bool parent, void 
*opaque)
 return arrays->names[devid];
 }
 
+static int
+vshNodeDeviceSorter(const void *a, const void *b)
+{
+virNodeDevicePtr *na = (virNodeDevicePtr *) a;
+virNodeDevicePtr *nb = (virNodeDevicePtr *) b;
+
+if (*na && !*nb)
+return -1;
+
+if (!*na)
+return *nb != NULL;
+
+return strcasecmp(virNodeDeviceGetName(*na),
+  virNodeDeviceGetName(*nb));
+}
+
+struct vshNodeDeviceList {
+virNodeDevicePtr *devices;
+size_t ndevices;
+};
+typedef struct vshNodeDeviceList *vshNodeDeviceListPtr;
+
+static void
+vshNodeDeviceListFree(vshNodeDeviceListPtr list)
+{
+int i;
+
+if (list && list->ndevices) {
+for (i = 0; i < list->ndevices; i++) {
+if (list->devices[i])
+virNodeDeviceFree(list->devices[i]);
+}
+VIR_FREE(list->devices);
+}
+VIR_FREE(list);
+}
+
+static vshNodeDeviceListPtr
+vshNodeDeviceListCollect(vshControl *ctl,
+ char **capnames,
+ int ncapnames,
+ unsigned int flags)
+{
+vshNodeDeviceListPtr list = vshMalloc(ctl, sizeof(*list));
+int i;
+int ret;
+virNodeDevicePtr device;
+bool success = false;
+size_t deleted = 0;
+int ndevices = 0;
+char **names = NULL;
+
+/* try the list with flags support (0.9.14 and later) */
+if ((ret = virConnectListAllNodeDevices(ctl->conn,
+&list->devices,
+flags)) >= 0) {
+list->ndevices = ret;
+goto finished;
+}
+
+/* check if the command is actually supported */
+if (last_error && last_error->code == VIR_ERR_NO_SUPPORT) {
+virFreeError(last_error);
+last_error = NULL;
+goto fallback;
+}
+
+/* there was an error during the call */
+vshError(ctl, "%s", _("Failed to list node devices"));
+goto cleanup;
+
+
+fallback:
+/* fall back to old method (0.9.13 and older) */
+virResetLastError();
+
+ndevices = virNodeNumOfDevices(ctl->conn, NULL, 0);
+if (ndevices < 0) {
+vshError(ctl, "%s", _("Failed to count node devices"));
+goto cleanup;
+}
+
+if (ndevices == 0)
+return list;
+
+names = vshMalloc(ctl, sizeof(char *) * ndevices);
+
+ndevices = virNodeListDevices(ctl->conn, NULL, names, ndevices, 0);
+if (ndevices < 0) {
+vshError(ctl, "%s", _("Failed to list node devices"));
+goto cleanup;
+}
+
+list->devices = vshMalloc(ctl, sizeof(virNodeDevicePtr) * (ndevices));
+list->ndevices = 0;
+
+/* get the node devices */
+for (i = 0; i < ndevices ; i++) {
+if (!(device = virNodeDeviceLookupByName(ctl->conn, names[i])))
+continue;
+list->devices[list->ndevices++] = device;
+}
+
+/* truncate domains that weren't found */
+deleted = ndevices - list->ndevices;
+
+if (!capnames)
+goto finished;
+
+/* filter the list if the list was acquired by fallback means */
+for (i = 0; i < list->ndevices; i++) {
+char **caps = NULL;
+int ncaps = 0;
+bool match = false;
+
+device = list->devices[i];
+
+if ((ncaps = virNodeDeviceNumOfCaps(device)) < 0) {
+vshError(ctl, "%s", _("Failed to get capability numbers "
+ "of the device"));
+goto cleanup;
+}
+
+caps = vshMalloc(ctl, sizeof(char *) * ncaps);
+
+if ((ncaps = virNodeDeviceListCaps(device, caps, ncaps)) < 0) {
+vshError(ctl, "%s", _("Failed to get capability names of the 
device"));
+VIR_FREE(caps);
+goto cleanup;
+}
+
+int j, k;
+for (j = 0; j < ncaps; j++) {
+for (k = 0; k < ncapnames; k++) {
+if (STREQ(caps[j], capnames[k])) {
+match = true;
+break;
+}
+}
+}
+
+VIR_FREE(caps)

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

2012-07-20 Thread Osier Yang
tools/virsh.c: New helper function vshStringToArray, use the helper
in cmdUndefine.
---
 tools/virsh.c |  107 +++--
 1 files changed, 66 insertions(+), 41 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 40f3be3..9c3b565 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -3014,6 +3014,51 @@ static const vshCmdOptDef opts_undefine[] = {
 {NULL, 0, 0, NULL}
 };
 
+/*
+ * 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.
+ */
+static 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;
+}
+
 static bool
 cmdUndefine(vshControl *ctl, const vshCmd *cmd)
 {
@@ -3039,21 +3084,21 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
 int running;
 /* list of volumes to remove along with this domain */
 const char *volumes_arg = NULL;
-char *volumes = NULL;
-char **volume_tokens = NULL;
-char *volume_tok = NULL;
-int nvolume_tokens = 0;
+char *volumes_str = NULL;
+char **volumes = NULL;
+char *volume = NULL;
+int volumes_len = 0;
 char *def = NULL;
 char *source = NULL;
 char *target = NULL;
 int vol_i;
-int tok_i;
 xmlDocPtr doc = NULL;
 xmlXPathContextPtr ctxt = NULL;
 xmlNodePtr *vol_nodes = NULL;
 int nvolumes = 0;
 virStorageVolPtr vol = NULL;
 bool vol_del_failed = false;
+int i;
 
 if (managed_save) {
 flags |= VIR_DOMAIN_UNDEFINE_MANAGED_SAVE;
@@ -3072,7 +3117,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
 
 /* check if a string that should contain list of volumes to remove is 
present */
 if (vshCommandOptString(cmd, "storage", &volumes_arg) > 0) {
-volumes = vshStrdup(ctl, volumes_arg);
+volumes_str = vshStrdup(ctl, volumes_arg);
 
 if (remove_all_storage) {
 vshError(ctl, _("Specified both --storage and 
--remove-all-storage"));
@@ -3212,27 +3257,8 @@ out:
 if (remove_storage || remove_all_storage) {
 ret = false;
 
-/* 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_tok++;
-}
-
-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 ((volumes_len = vshStringToArray(volumes_str, &volumes)) < 0)
+goto cleanup;
 
 doc = virXMLParseStringCtxt(def, _("(domain_definition)"), &ctxt);
 if (!doc)
@@ -3268,17 +3294,17 @@ out:
 
 /* lookup if volume was selected by user */
 if (volumes) {
-volume_tok = NULL;
-for (tok_i = 0; tok_i < nvolume_tokens; tok_i++) {
-if (volume_tokens[tok_i] &&
-(STREQ_NULLABLE(volume_tokens[tok_i], target) ||
- STREQ_NULLABLE(volume_tokens[tok_i], source))) {
-volume_tok = volume_tokens[tok_i];
-volume_tokens[tok_i] = NULL;
+volume = NULL;
+for (i = 0; i < volumes_len; i++) {
+if (volumes[i] &&
+(STREQ_NULLABLE(volumes[i], target) ||
+ STREQ_NULLABLE(volumes[i], source))) {
+volume = volumes[i];
+volumes[i] = NULL;
 break;
 }
 }
-if (!volume_tok)
+if (!volume)
 continue;
 }
 
@@ -3311,16 +3337,16 @@ out:
  

[libvirt] [PATCH 38/49] virsh: Fix a bug of nodedev-list

2012-07-20 Thread Osier Yang
Output of commands like '%virsh nodedev-list --tree --cap pci'
could be empty. Remove the useless checking.
---
 tools/virsh.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 8e191f4..8b85a7a 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -14213,9 +14213,8 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 virNodeDeviceFree(dev);
 }
 for (i = 0 ; i < num_devices ; i++) {
-if (parents[i] == NULL &&
-vshTreePrint(ctl, vshNodeListLookup, &arrays, num_devices,
- i) < 0)
+if (vshTreePrint(ctl, vshNodeListLookup,
+ &arrays, num_devices, i) < 0)
 ret = false;
 }
 for (i = 0 ; i < num_devices ; i++) {
-- 
1.7.7.3

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


[libvirt] [PATCH 16/49] list: Implement virStoragePoolListAllVolumes for storage driver

2012-07-20 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 0974879..c630c2e 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1154,6 +1154,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 < obj->volumes.count; i++) {
+if (tmp_vols[i])
+virStorageVolFree(tmp_vols[i]);
+}
+}
+
+if (obj)
+virStoragePoolObjUnlock(obj);
+
+return ret;
+}
 
 static virStorageVolPtr
 storageVolumeLookupByName(virStoragePoolPtr obj,
@@ -2332,6 +2398,7 @@ static virStorageDriver storageDriver = {
 .poolSetAutostart = storagePoolSetAutostart, /* 0.4.0 */
 .poolNumOfVolumes = storagePoolNumVolumes, /* 0.4.0 */
 .poolListVolumes = storagePoolListVolumes, /* 0.4.0 */
+.poolListAllVolumes = storagePoolListAllVolumes, /* 0.9.14 */
 
 .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 20/49] list: Define new API virConnectListAllNetworks

2012-07-20 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|   68 ++
 src/libvirt_public.syms  |1 +
 5 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index c5b16bf..15a9a1b 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2196,6 +2196,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 4b3f7e6..44b56c2 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -458,6 +458,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 ee1341f..68a1f04 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1055,6 +1055,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);
@@ -1113,6 +1117,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 7780534..622a590 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -9588,6 +9588,74 @@ 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.
+ *
+ * By default, this API covers all networks; it is also possible to return
+ * the filtered objects with flags. Filters are provided in groups, where each
+ * group contains bits that describe mutually exclusive attributes of a 
network.
+ *
+ * The first group of @flags is VIR_CONNECT_LIST_NETWORKS_INACTIVE and
+ * VIR_CONNECT_LIST_NETWORKS_INACTIVE to fitler the networks by state.
+ *
+ * The second group of @flags is VIR_CONNECT_LIST_NETWORKS_PERSITENT
+ * and VIR_CONNECT_LIST_NETWORKS_TRANSICIENT,

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

2012-07-20 Thread Osier Yang
tools/virsh.c: Change MATCH for common use. It's safe, only the new
helpers to collect objects use it.
---
 tools/virsh.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 9c3b565..2d4567d 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -84,6 +84,8 @@ static char *progname;
 /* Default escape char Ctrl-] as per telnet */
 #define CTRL_CLOSE_BRACKET "^]"
 
+#define MATCH(FLAG) (flags & (FLAG))
+
 /**
  * The log configuration
  */
@@ -1042,7 +1044,6 @@ vshDomainListFree(vshDomainListPtr domlist)
 VIR_FREE(domlist);
 }
 
-#define MATCH(FLAG) (flags & (FLAG))
 static vshDomainListPtr
 vshDomainListCollect(vshControl *ctl, unsigned int flags)
 {
@@ -1263,7 +1264,6 @@ cleanup:
 VIR_FREE(ids);
 return list;
 }
-#undef MATCH
 
 
 static const vshCmdOptDef opts_list[] = {
-- 
1.7.7.3

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


[libvirt] [PATCH 21/49] list: Implement RPC calls for virConnectListAllNetworks

2012-07-20 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 c1e30c0..d5c4b90 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4064,6 +4064,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) {
+virNetError(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 179e7af..afe6e60 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2779,6 +2779,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;
+}
+
 
 /*--*/
 
@@ -5485,6 +5548,7 @@ static virNetworkDriver network_driver = {
 .listNetworks = remoteListNetworks, /* 0.3.0 */
 .numOfDefinedNetworks = remoteNumOfDefinedNetworks, /* 0.3.0 */
 .listDefinedNetworks = remoteListDefinedNetworks, /* 0.3.0 */
+.listAllNetworks = remoteConnectListAllNetworks, /* 0.9.14 */
 .networkLookupByUUID =

[libvirt] [PATCH 13/49] python: Expose virStorageListAllStoragePools to python binding

2012-07-20 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 @@
   
   
 
+
+  returns list of all storage pools
+  
+  
+  
+
 
   list the storage volumes, stores the pointers to the names in 
@names
   
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 8b41dff..0b1d509 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,
@@ -5874,6 +5920,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


[libvirt] [PATCH 12/49] virsh: Use vshPrint instead of printf

2012-07-20 Thread Osier Yang
---
 tools/virsh.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index ab64918..7d7c9ca 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -18344,7 +18344,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd 
*cmd)
 if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) < 0)
 goto cleanup;
 
-printf("%s\n", result);
+vshPrint(ctl, "%s\n", result);
 
 ret = true;
 
-- 
1.7.7.3

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


[libvirt] [PATCH 35/49] list: Add helpers for listing node devices

2012-07-20 Thread Osier Yang
src/conf/virobjectlist.h:
  * New macro VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP
  * Declare virNodeDeviceList

src/conf/virobjectlist.c:
  * New helpers virNodeDeviceCapMatch, virNodeDeviceMatch.
virNodeDeviceCapMatch looks up the list of all the caps the device
support, to see if the device support the cap type.
  * Implement virNodeDeviceList

src/libvirt_private.syms:
  * Export virNodeDeviceList
---
 src/conf/virobjectlist.c |  103 ++
 src/conf/virobjectlist.h |   17 
 src/libvirt_private.syms |2 +
 3 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/src/conf/virobjectlist.c b/src/conf/virobjectlist.c
index 83b0d9c..55c236c 100644
--- a/src/conf/virobjectlist.c
+++ b/src/conf/virobjectlist.c
@@ -30,6 +30,7 @@
 #include "virhash.h"
 #include "domain_conf.h"
 #include "storage_conf.h"
+#include "node_device_conf.h"
 #include "memory.h"
 #include "datatypes.h"
 #include "virterror_internal.h"
@@ -135,6 +136,20 @@ cleanup:
 }
 #undef MATCH
 
+static bool
+virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj,
+  int type)
+{
+virNodeDevCapsDefPtr cap = NULL;
+
+for (cap = devobj->def->caps; cap; cap = cap->next) {
+if (type == cap->type)
+return true;
+}
+
+return false;
+}
+
 #define MATCH(FLAG) (flags & (FLAG))
 static bool
 virStoragePoolMatch (virStoragePoolObjPtr poolobj,
@@ -222,6 +237,36 @@ virNetworkMatch (virNetworkObjPtr netobj,
 
 return true;
 }
+
+static bool
+virNodeDeviceMatch (virNodeDeviceObjPtr devobj,
+unsigned int flags)
+{
+/* filter by cap type */
+if (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP)) {
+if (!((MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM) &&
+   virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SYSTEM))
||
+  (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV) &&
+   virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_PCI_DEV))   
||
+  (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV) &&
+   virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_USB_DEV))   
||
+  (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE) &&
+   virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_USB_INTERFACE)) 
||
+  (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET) &&
+   virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_NET))   
||
+  (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST) &&
+   virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SCSI_HOST)) 
||
+  (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET) &&
+   virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SCSI_TARGET))   
||
+  (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI) &&
+   virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SCSI))  
||
+  (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE) &&
+   virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_STORAGE
+return false;
+}
+
+return true;
+}
 #undef MATCH
 
 int
@@ -430,3 +475,61 @@ cleanup:
 VIR_FREE(tmp_nets);
 return ret;
 }
+
+int
+virNodeDeviceList(virConnectPtr conn,
+  virNodeDeviceObjList devobjs,
+  virNodeDevicePtr **devices,
+  unsigned int flags)
+{
+virNodeDevicePtr *tmp_devices = NULL;
+virNodeDevicePtr device = NULL;
+int ndevices = 0;
+int ret = -1;
+int i;
+
+if (devices) {
+if (VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+}
+
+for (i = 0; i < devobjs.count; i++) {
+virNodeDeviceObjPtr devobj = devobjs.objs[i];
+virNodeDeviceObjLock(devobj);
+if (virNodeDeviceMatch(devobj, flags)) {
+if (devices) {
+if (!(device = virGetNodeDevice(conn,
+devobj->def->name))) {
+virNodeDeviceObjUnlock(devobj);
+goto cleanup;
+}
+tmp_devices[ndevices++] = device;
+} else {
+ndevices++;
+}
+}
+virNodeDeviceObjUnlock(devobj);
+}
+
+if (tmp_devices) {
+/* trim the array to the final size */
+ignore_value(VIR_REALLOC_N(tmp_devices, ndevices + 1));
+*devices = tmp_devices;
+tmp_devices = NULL;
+}
+
+ret = ndevices;
+
+cleanup:
+if (tmp_devices) {
+for (i = 0; i < devobjs.count; i++) {
+if (tmp_devices[i])
+virNodeDeviceFree(tmp_devices[i]);
+}
+}
+
+VIR_FREE(tmp_devices);
+return ret;
+}
diff --git a/src/conf/virobjectlist.h b/src/conf/virobjectlist.h
index 431635e..e62d454 100644
--- a/src/conf/virobjectlist.h
+++ b/src/conf/virobjectlist.h
@@ -29,6 +29,7 @@
 # include "domain_conf.h"

[libvirt] [PATCH 18/49] list: Use virStoragePoolListAllVolumes in virsh

2012-07-20 Thread Osier Yang
tools/virsh.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.c |  197 +++--
 1 files changed, 150 insertions(+), 47 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 7d7c9ca..9556e16 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -12793,6 +12793,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 strcasecmp(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.9.14 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) {
+virFreeError(last_error);
+last_error = NULL;
+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) */
+virResetLastError();
+
+/* 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
@@ -12814,14 +12941,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;
@@ -12833,6 +12959,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 char *type;
 };
 struct volInfoText *volInfoTexts = NULL;
+vshStorageVolListPtr list = NULL;
 
 /* Check the connection to libvirtd daemon is still working */
 if (!vshConnectionUsability(ctl, ctl->conn))
@@ -12842,38 +12969,16 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 if (!(pool = v

[libvirt] [PATCH 30/49] list: Implement listAllInterfaces

2012-07-20 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 39fa721..ea3eef2 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;
+}
+   

[libvirt] [PATCH 14/49] list: Define new API virStoragePoolListAllVolumes

2012-07-20 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 c7e810e..c5b16bf 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2570,6 +2570,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 5934040..4b3f7e6 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -457,6 +457,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 7e3e8a1..ee1341f 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1284,7 +1284,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,
@@ -1392,6 +1395,7 @@ struct _virStorageDriver {
 virDrvStoragePoolSetAutostart   poolSetAutostart;
 virDrvStoragePoolNumOfVolumes   poolNumOfVolumes;
 virDrvStoragePoolListVolumespoolListVolumes;
+virDrvStoragePoolListAllVolumes poolListAllVolumes;
 
 virDrvStorageVolLookupByNamevolLookupByName;
 virDrvStorageVolLookupByKey volLookupByKey;
diff --git a/src/libvirt.c b/src/libvirt.c
index 541b1c3..7780534 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -12385,6 +12385,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-

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

2012-07-20 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 @@
 
   list the storage volumes, stores the pointers to the names in 
@names
   
-  
+  
+
+
+  return list of storage volume objects
+  
+  
+  
 
 
   Extract 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.
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 0b1d509..322a8d2 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;
@@ -5923,6 +5972,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_virStoragePoolGetUUID, 
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 00/49 v2] Atomic APIs to list objects

2012-07-20 Thread Osier Yang
v1 - v2:
  * Fix the stupid mistake - changing the public struct, error out
if the new option '--type' for pool-list is specified, and
the libvirt is old enough without listAllStoragePools supported.

Except the already supported APIs for domain and domain snapshot,
this series add the APIs for the left objects, including storage
pool, storage vol, network, interface, node device, nwfilter, and
secret.

  * Storage pool:
- Support filtering the returned pool objects by active|inactive,
  persistent|transient, autostart|no-autostart, and pool types.
- New options for virsh, --type to accept multiple pool types.

  * Storage vol:
- Simply returns all the vol objects of a pool.

  * Network:
- Support filtering the results using flags active|inactive,
  persistent|transient, autostart|no-autostart
- New options for virsh.

  * Interface:
- Support filtering the results using flags active|inactive.
  It's still O(n) underlying, as interface driver doesn't manage
  the objects itself, but using netcf lib instead. And netcf
  APIs don't support returning the struct yet.

  * Node Device:
- Support filtering the results using capabilities type of
  the devices.
- Extend --cap to accept multiple capability type.

  * Network Filter:
   - Simply returns all the objects.

  * Secret:
   - Simply returns all the objects.

All the affected commands are tested with both new libvirt with the
APIs support, or old libvirt without the support. But I still may
lose some scenarios. Please review carefully.

Osier Yang (49):
  Fix indentions
  list: Rename virdomainlist.[ch] for common use
  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
  virsh: Use vshPrint instead of printf
  python: Expose virStorageListAllStoragePools to python binding
  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
  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: Fix the wrong macro name
  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
  list: Define new API virConnectListAllNodeDevices
  list: Implemente RPC calls for virConnectListAllNodeDevices
  list: Add helpers for listing node devices
  list: Implement listAllNodeDevices
  list: Expose virConnectListAllNodeDevices to Python binding
  virsh: Fix a bug of nodedev-list
  list: Use virConnectListAllNodeDevices in virsh
  list: Define new API virConnectListAllNWFilters
  list: Implement RPC calls for virConnectListAllNWFilters
  list: Implement listAllNWFilters
  list: Use virConnectListAllNWFilters in virsh
  list: Expose virConnectListAllNWFilters to Python binding
  list: Define new API virConnectListAllSecrets
  list: Implement RPC calls for virConnectListAllSecrets
  list: Implement listAllSecrets
  list: Use virConnectListAllSecrets in virsh
  list: Expose virConnectListAllSecrets to Python binding

 daemon/libvirtd.c |2 +-
 daemon/remote.c   |  382 +
 include/libvirt/libvirt.h.in  |  100 ++-
 python/generator.py   |   11 +-
 python/libvirt-override-api.xml   |   44 +-
 python/libvirt-override-virConnect.py |   72 +
 python/libvirt-override-virStoragePool.py |   11 +
 python/libvirt-override.c |  337 +
 src/Makefile.am   |8 +-
 src/conf/domain_conf.c|2 +-
 src/conf/virdomainlist.c  |  222 ---
 src/conf/virdomainlist.h  |   84 --
 src/conf/virobjectlist.c  |  535 +++
 src/conf/virobjectlist.h  |  162 +++
 src/datatypes.h   |   86 +-
 src/driver.h  |   35 +-
 src/interface/netcf_driver.c  

[libvirt] [PATCH 17/49] list: Implement virStoragePoolListAllVolumes for test driver

2012-07-20 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 21164ca..9b528f2 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4553,6 +4553,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) {
+testError(VIR_ERR_NO_STORAGE_POOL, "%s",
+  _("no storage pool with matching uuid"));
+goto cleanup;
+}
+
+if (!virStoragePoolObjIsActive(pool)) {
+testError(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 < pool->volumes.count; i++) {
+if (tmp_vols[i])
+virStorageVolFree(tmp_vols[i]);
+}
+}
+
+if (pool)
+virStoragePoolObjUnlock(pool);
+
+return ret;
+}
 
 static virStorageVolPtr
 testStorageVolumeLookupByName(virStoragePoolPtr pool,
@@ -5695,6 +5761,7 @@ static virStorageDriver testStorageDriver = {
 .poolSetAutostart = testStoragePoolSetAutostart, /* 0.5.0 */
 .poolNumOfVolumes = testStoragePoolNumVolumes, /* 0.5.0 */
 .poolListVolumes = testStoragePoolListVolumes, /* 0.5.0 */
+.poolListAllVolumes = testStoragePoolListAllVolumes, /* 0.9.14 */
 
 .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 07/49] list: Implement listAllStoragePools for test driver

2012-07-20 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 bf2c1c2..21164ca 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3942,6 +3942,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)
 {
@@ -5660,6 +5676,7 @@ static virStorageDriver testStorageDriver = {
 .listPools = testStorageListPools, /* 0.5.0 */
 .numOfDefinedPools = testStorageNumDefinedPools, /* 0.5.0 */
 .listDefinedPools = testStorageListDefinedPools, /* 0.5.0 */
+.listAllPools = testStorageListAllPools, /* 0.9.14 */
 .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


[libvirt] [PATCH 11/49] list: Use virConnectListAllStoragePools in virsh

2012-07-20 Thread Osier Yang
tools/virsh.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.c   |  442 ++-
 tools/virsh.pod |   24 +++-
 2 files changed, 362 insertions(+), 104 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 2d4567d..ab64918 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -10868,6 +10868,233 @@ 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 strcasecmp(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.9.14 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) {
+virFreeError(last_error);
+last_error = NULL;
+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);
+virFreeError(last_error);
+last_error = NULL;
+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) */
+virResetLastError();
+
+/* 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 to get the number of inactive 
pools"));
+goto cleanup;
+}
+}
+
+nAllPools = nActivePools + 

[libvirt] [PATCH 02/49] list: Rename virdomainlist.[ch] for common use

2012-07-20 Thread Osier Yang
Except objects of domains, domain snapshots, we will also add APIs
to list objects like storage pools, storage vols, network, interface,
etc. And it's deserved to have the small helper functions in a
common file instead of in separate files.

This patch renames virdomainlist.[ch] to virobjectlist.[ch], and
also renames the macros to filter domain objects more specificly.

src/conf/virdomainlist.c: Renamed to src/conf/virobjectlist.c
src/conf/virdomainlist.h: Renamed to src/conf/virobjectlist.h
src/Makefile.am: s/virdomainlist/virobjectlist/g,
 s/DOMAIN_LIST/OBJECT_LIST/g
src/conf/domain_conf.c: Likewise
src/libvirt_private.syms: Likewise
tools/virsh.c: Likewise
src/libxl/libxl_driver.c: s/LIST_FILTERS/LIST_DOMAINS_FILTERS/g
src/lxc/lxc_driver.c: Likewise
src/openvz/openvz_driver.c: Likewise
src/qemu/qemu_driver.c: Likewise
src/test/test_driver.c: Likewise
src/uml/uml_driver.c: Likewise
src/vbox/vbox_tmpl.c: Likewise
src/vmware/vmware_driver.c: Likewise
---
 src/Makefile.am   |8 +++---
 src/conf/domain_conf.c|2 +-
 src/conf/{virdomainlist.c => virobjectlist.c} |   20 +++--
 src/conf/{virdomainlist.h => virobjectlist.h} |   36 +---
 src/libvirt_private.syms  |2 +-
 src/libxl/libxl_driver.c  |4 +-
 src/lxc/lxc_driver.c  |4 +-
 src/openvz/openvz_driver.c|4 +-
 src/qemu/qemu_driver.c|4 +-
 src/test/test_driver.c|4 +-
 src/uml/uml_driver.c  |4 +-
 src/vbox/vbox_tmpl.c  |   10 +++---
 src/vmware/vmware_driver.c|4 +-
 tools/virsh.c |   16 +-
 14 files changed, 63 insertions(+), 59 deletions(-)
 rename src/conf/{virdomainlist.c => virobjectlist.c} (90%)
 rename src/conf/{virdomainlist.h => virobjectlist.h} (71%)

diff --git a/src/Makefile.am b/src/Makefile.am
index a9f8d94..4931381 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -195,9 +195,9 @@ CPU_CONF_SOURCES =  
\
 CONSOLE_CONF_SOURCES = \
conf/virconsole.c conf/virconsole.h
 
-# Domain listing helpers
-DOMAIN_LIST_SOURCES =  \
-   conf/virdomainlist.c conf/virdomainlist.h
+# Object listing helpers
+OBJECT_LIST_SOURCES =  \
+   conf/virobjectlist.c conf/virobjectlist.h
 
 CONF_SOURCES = \
$(NETDEV_CONF_SOURCES)  \
@@ -212,7 +212,7 @@ CONF_SOURCES =  
\
$(SECRET_CONF_SOURCES)  \
$(CPU_CONF_SOURCES) \
$(CONSOLE_CONF_SOURCES) \
-   $(DOMAIN_LIST_SOURCES)
+   $(OBJECT_LIST_SOURCES)
 
 # The remote RPC driver, covering domains, storage, networks, etc
 REMOTE_DRIVER_GENERATED = \
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1b5dad9..f3a7f14 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -51,7 +51,7 @@
 #include "secret_conf.h"
 #include "netdev_vport_profile_conf.h"
 #include "netdev_bandwidth_conf.h"
-#include "virdomainlist.h"
+#include "virobjectlist.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
diff --git a/src/conf/virdomainlist.c b/src/conf/virobjectlist.c
similarity index 90%
rename from src/conf/virdomainlist.c
rename to src/conf/virobjectlist.c
index 2b0b878..91eb660 100644
--- a/src/conf/virdomainlist.c
+++ b/src/conf/virobjectlist.c
@@ -1,5 +1,7 @@
 /**
- * virdomainlist.c: Helpers for listing and filtering domains.
+ *virobjectlist.h: Helpers for listing and filtering objects
+ * like domains, domain snapshots, storage pools,
+ * storage vols, networks, etc.
  *
  * Copyright (C) 2012 Red Hat, Inc.
  *
@@ -22,7 +24,7 @@
 
 #include 
 
-#include "virdomainlist.h"
+#include "virobjectlist.h"
 
 #include "internal.h"
 #include "virhash.h"
@@ -31,7 +33,7 @@
 #include "datatypes.h"
 #include "virterror_internal.h"
 
-#define VIR_FROM_THIS VIR_FROM_DOMAIN
+#define VIR_FROM_THIS VIR_FROM_NONE
 
 struct virDomainListData {
 virConnectPtr conn;
@@ -58,7 +60,7 @@ virDomainListPopulate(void *payload,
 /* check if the domain matches the filter */
 
 /* filter by active state */
-if (MATCH(VIR_CONNECT_LIST_FILTERS_ACTIVE) &&
+if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) &&
 !((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE) &&
virDomainObjIsActive(vm)) ||
   (MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE) &&
@@ -66,7 +68,7 @@ virDomainListPopulate(void *payload,
 goto cleanup;
 
 /* filter b

[libvirt] [PATCH 15/49] list: Implemente RPC calls for virStoragePoolListAllVolumes

2012-07-20 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 |   12 +++-
 src/remote_protocol-structs  |   13 
 4 files changed, 148 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 060c5a0..c1e30c0 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4006,6 +4006,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) {
+virNetError(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 ab821d5..179e7af 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2715,6 +2715,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_NO

[libvirt] [PATCH 04/49] list: Add helpers for listing storage pool objects

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

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

src/libvirt_private.syms: Export helper virStoragePoolList.
---
 src/conf/virobjectlist.c |  118 ++
 src/conf/virobjectlist.h |   36 ++
 src/libvirt_private.syms |1 +
 3 files changed, 155 insertions(+), 0 deletions(-)

diff --git a/src/conf/virobjectlist.c b/src/conf/virobjectlist.c
index 91eb660..fb5f974 100644
--- a/src/conf/virobjectlist.c
+++ b/src/conf/virobjectlist.c
@@ -29,6 +29,7 @@
 #include "internal.h"
 #include "virhash.h"
 #include "domain_conf.h"
+#include "storage_conf.h"
 #include "memory.h"
 #include "datatypes.h"
 #include "virterror_internal.h"
@@ -134,6 +135,64 @@ cleanup:
 }
 #undef MATCH
 
+#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
 virDomainList(virConnectPtr conn,
   virHashTablePtr domobjs,
@@ -222,3 +281,62 @@ cleanup:
 }
 return ret;
 }
+
+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;
+} else {
+npools++;
+}
+}
+virStoragePoolObjUnlock(poolobj);
+}
+
+if (tmp_pools) {
+/* trim the array to the final size */
+ignore_value(VIR_REALLOC_N(tmp_pools, n

[libvirt] [PATCH 09/49] virsh: Fix the wrong doc for pool-list

2012-07-20 Thread Osier Yang
The storage pool's management doesn't relate with a domain, it
probably was a 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 4bddf15..f79c945 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2156,11 +2156,10 @@ Returns basic information about the I object.
 
 =item B [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 B I
 
-- 
1.7.7.3

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


[libvirt] [PATCH 05/49] list: Implement the RPC calls for virConnectListAllStoragePools

2012-07-20 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 |   12 +++-
 src/remote_protocol-structs  |   12 
 4 files changed, 141 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 9334221..060c5a0 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -3952,6 +3952,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) {
+virNetError(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 d91ae87..ab821d5 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2652,6 +2652,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)
@@ -5401,6 +5464,7 @@ static virStorageDriver storage_driver = {
 .listPools = remoteListStoragePools, 

[libvirt] [PATCH 03/49] list: Define new API virStorageListALlStoragePools

2012-07-20 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 |   32 ++
 python/generator.py  |5 +-
 src/driver.h |5 ++
 src/libvirt.c|   93 +++---
 src/libvirt_public.syms  |5 ++
 5 files changed, 132 insertions(+), 8 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index e34438c..c7e810e 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2471,6 +2471,38 @@ int 
virConnectListDefinedStoragePools(virConnectPtr conn,
   int maxnames);
 
 /*
+ * virConnectListAllStoragePoolsFlags:
+ *
+ * Flags used to filter the returned pools. Flags in each group
+ * are exclusive attribute for a pool.
+ */
+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 2dada6e..5934040 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',
@@ -453,9 +453,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 b3c1740..7e3e8a1 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1225,6 +1225,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,
@@ -1369,6 +1373,7 @@ struct _virStorageDriver {
 virDrvConnectListStoragePools   listPools;
 virDrvConnectNumOfDefinedStoragePools   numOfDefinedPools;
 virDrvConnectListDefinedStoragePoolslistDefinedPools;
+virDrvConnectListAllStoragePools  

[libvirt] [PATCH 01/49] Fix indentions

2012-07-20 Thread Osier Yang
Some of the macros use tab, while the left use spaces, this patch
change it to always use the spaces. And a few aligning fixes.
---
 src/datatypes.h |   86 +++---
 1 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/src/datatypes.h b/src/datatypes.h
index fc284d2..01a8544 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -33,8 +33,8 @@
  * magic value used to protect the API when pointers to connection structures
  * are passed down by the users.
  */
-# define VIR_CONNECT_MAGIC 0x4F23DEAD
-# define VIR_IS_CONNECT(obj)   ((obj) && (obj)->magic==VIR_CONNECT_MAGIC)
+# define VIR_CONNECT_MAGIC   0x4F23DEAD
+# define VIR_IS_CONNECT(obj) ((obj) && (obj)->magic==VIR_CONNECT_MAGIC)
 
 
 /**
@@ -43,9 +43,9 @@
  * magic value used to protect the API when pointers to domain structures
  * are passed down by the users.
  */
-# define VIR_DOMAIN_MAGIC  0xDEAD4321
-# define VIR_IS_DOMAIN(obj)((obj) && 
(obj)->magic==VIR_DOMAIN_MAGIC)
-# define VIR_IS_CONNECTED_DOMAIN(obj)  (VIR_IS_DOMAIN(obj) && 
VIR_IS_CONNECT((obj)->conn))
+# define VIR_DOMAIN_MAGIC 0xDEAD4321
+# define VIR_IS_DOMAIN(obj)   ((obj) && (obj)->magic==VIR_DOMAIN_MAGIC)
+# define VIR_IS_CONNECTED_DOMAIN(obj) (VIR_IS_DOMAIN(obj) && 
VIR_IS_CONNECT((obj)->conn))
 
 /**
  * VIR_NETWORK_MAGIC:
@@ -53,9 +53,9 @@
  * magic value used to protect the API when pointers to network structures
  * are passed down by the users.
  */
-# define VIR_NETWORK_MAGIC 0xDEAD1234
-# define VIR_IS_NETWORK(obj)   ((obj) && 
(obj)->magic==VIR_NETWORK_MAGIC)
-# define VIR_IS_CONNECTED_NETWORK(obj) (VIR_IS_NETWORK(obj) && 
VIR_IS_CONNECT((obj)->conn))
+# define VIR_NETWORK_MAGIC 0xDEAD1234
+# define VIR_IS_NETWORK(obj)   ((obj) && 
(obj)->magic==VIR_NETWORK_MAGIC)
+# define VIR_IS_CONNECTED_NETWORK(obj) (VIR_IS_NETWORK(obj) && 
VIR_IS_CONNECT((obj)->conn))
 
 /**
  * VIR_INTERFACE_MAGIC:
@@ -63,9 +63,9 @@
  * magic value used to protect the API when pointers to interface structures
  * are passed down by the users.
  */
-# define VIR_INTERFACE_MAGIC   0xDEAD5309
-# define VIR_IS_INTERFACE(obj) ((obj) && 
(obj)->magic==VIR_INTERFACE_MAGIC)
-# define VIR_IS_CONNECTED_INTERFACE(obj)   (VIR_IS_INTERFACE(obj) && 
VIR_IS_CONNECT((obj)->conn))
+# define VIR_INTERFACE_MAGIC 0xDEAD5309
+# define VIR_IS_INTERFACE(obj)   ((obj) && 
(obj)->magic==VIR_INTERFACE_MAGIC)
+# define VIR_IS_CONNECTED_INTERFACE(obj) (VIR_IS_INTERFACE(obj) && 
VIR_IS_CONNECT((obj)->conn))
 
 /**
  * VIR_STORAGE_POOL_MAGIC:
@@ -73,9 +73,9 @@
  * magic value used to protect the API when pointers to storage pool structures
  * are passed down by the users.
  */
-# define VIR_STORAGE_POOL_MAGIC0xDEAD5678
-# define VIR_IS_STORAGE_POOL(obj)  ((obj) && 
(obj)->magic==VIR_STORAGE_POOL_MAGIC)
-# define VIR_IS_CONNECTED_STORAGE_POOL(obj)(VIR_IS_STORAGE_POOL(obj) && 
VIR_IS_CONNECT((obj)->conn))
+# define VIR_STORAGE_POOL_MAGIC 0xDEAD5678
+# define VIR_IS_STORAGE_POOL(obj)   ((obj) && 
(obj)->magic==VIR_STORAGE_POOL_MAGIC)
+# define VIR_IS_CONNECTED_STORAGE_POOL(obj) (VIR_IS_STORAGE_POOL(obj) && 
VIR_IS_CONNECT((obj)->conn))
 
 /**
  * VIR_STORAGE_VOL_MAGIC:
@@ -83,9 +83,9 @@
  * magic value used to protect the API when pointers to storage vol structures
  * are passed down by the users.
  */
-# define VIR_STORAGE_VOL_MAGIC 0xDEAD8765
-# define VIR_IS_STORAGE_VOL(obj)   ((obj) && 
(obj)->magic==VIR_STORAGE_VOL_MAGIC)
-# define VIR_IS_CONNECTED_STORAGE_VOL(obj) (VIR_IS_STORAGE_VOL(obj) && 
VIR_IS_CONNECT((obj)->conn))
+# define VIR_STORAGE_VOL_MAGIC 0xDEAD8765
+# define VIR_IS_STORAGE_VOL(obj)   ((obj) && 
(obj)->magic==VIR_STORAGE_VOL_MAGIC)
+# define VIR_IS_CONNECTED_STORAGE_VOL(obj) (VIR_IS_STORAGE_VOL(obj) && 
VIR_IS_CONNECT((obj)->conn))
 
 /**
  * VIR_NODE_DEVICE_MAGIC:
@@ -93,9 +93,9 @@
  * magic value used to protect the API when pointers to storage vol structures
  * are passed down by the users.
  */
-# define VIR_NODE_DEVICE_MAGIC   0xDEAD5679
-# define VIR_IS_NODE_DEVICE(obj) ((obj) && 
(obj)->magic==VIR_NODE_DEVICE_MAGIC)
-# define VIR_IS_CONNECTED_NODE_DEVICE(obj)   (VIR_IS_NODE_DEVICE(obj) && 
VIR_IS_CONNECT((obj)->conn))
+# define VIR_NODE_DEVICE_MAGIC 0xDEAD5679
+# define VIR_IS_NODE_DEVICE(obj)   ((obj) && 
(obj)->magic==VIR_NODE_DEVICE_MAGIC)
+# define VIR_IS_CONNECTED_NODE_DEVICE(obj) (VIR_IS_NODE_DEVICE(obj) && 
VIR_IS_CONNECT((obj)->conn))
 
 /**
  * VIR_SECRET_MAGIC:
@@ -103,9 +103,9 @@
  * magic value used to protect the API when pointers to secret structures are
  * passed down by the users.
  */
-# define VIR_SECRET_MAGIC  0x5678DEAD
-# define VIR_IS_SECRET(obj)((obj) && 
(obj)->magic==VIR_SECRET_MAGIC)
-# define VIR_IS_CONNECTED_SECRET(obj)  

[libvirt] [PATCH 06/49] list: Implement listAllStoragePools for storage driver

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

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index c9b8021..0974879 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -42,6 +42,7 @@
 #include "util.h"
 #include "storage_driver.h"
 #include "storage_conf.h"
+#include "virobjectlist.h"
 #include "memory.h"
 #include "storage_backend.h"
 #include "logging.h"
@@ -2287,6 +2288,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 */
@@ -2295,6 +2313,7 @@ static virStorageDriver storageDriver = {
 .listPools = storageListPools, /* 0.4.0 */
 .numOfDefinedPools = storageNumDefinedPools, /* 0.4.0 */
 .listDefinedPools = storageListDefinedPools, /* 0.4.0 */
+.listAllPools = storageListAllPools, /* 0.9.14 */
 .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] Disable NWFilter driver completely when unprivileged

2012-07-20 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Running libvirtd unprivileged results in a warning message from
the NWFilter driver

  virNWFilterSnoopLeaseFileRefresh:1882 : 
open("/var/run/libvirt/network/nwfilter.ltmp"): No such file or directory

Since it requires privileged network access, this driver should
not even run when unprivileged.

Signed-off-by: Daniel P. Berrange 
---
 src/nwfilter/nwfilter_driver.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 58d91f9..9034549 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -68,6 +68,9 @@ static int
 nwfilterDriverStartup(int privileged) {
 char *base = NULL;
 
+if (!privileged)
+return 0;
+
 if (virNWFilterIPAddrMapInit() < 0)
 return -1;
 if (virNWFilterLearnInit() < 0)
-- 
1.7.10.4

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


[libvirt] [PATCH 1/5 v2] Add public API to register a callback to be invoked on connection close

2012-07-20 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Define a new virConnectSetCloseCallback() public API which allows
registering a callback to be invoked when the connection to a
hypervisor is closed. The callback is provided with the reason for
the close, which may be 'error', 'eof' or 'keepalive'.

Signed-off-by: Daniel P. Berrange 
---
 include/libvirt/libvirt.h.in |   40 +---
 src/datatypes.c  |4 +++
 src/datatypes.h  |5 
 src/libvirt.c|   60 ++
 src/libvirt_public.syms  |6 +
 5 files changed, 105 insertions(+), 10 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index e34438c..85d8c8a 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -49,6 +49,17 @@ extern "C" {
  * defines VIR_ENUM_SENTINELS.  Enumerations for bit values do not
  * have a *_LAST value, but additional bits may be defined.  */
 
+/*
+ * virFreeCallback:
+ * @opaque: opaque user data provided at registration
+ *
+ * Type for a domain event callback when the event is deregistered and
+ * need to be freed, @opaque is provided along with the callback at
+ * registration time
+ */
+typedef void (*virFreeCallback)(void *opaque);
+
+
 /**
  * virConnect:
  *
@@ -1148,6 +1159,25 @@ int virConnectSetKeepAlive(virConnectPtr conn,
int interval,
unsigned int count);
 
+typedef enum {
+VIR_CONNECT_CLOSE_REASON_ERROR = 0, /* Misc I/O error */
+VIR_CONNECT_CLOSE_REASON_EOF   = 1, /* End-of-file from server */
+VIR_CONNECT_CLOSE_REASON_KEEPALIVE = 2, /* Keepalive timer triggered */
+VIR_CONNECT_CLOSE_REASON_CLIENT= 3, /* Client requested it */
+
+# ifdef VIR_ENUM_SENTINELS
+VIR_CONNECT_CLOSE_REASON_LAST
+# endif
+} virConnectCloseReason;
+
+typedef void (*virConnectCloseFunc)(virConnectPtr conn,
+int reason,
+void *opaque);
+
+int virConnectSetCloseCallback(virConnectPtr conn,
+   virConnectCloseFunc cb,
+   void *opaque,
+   virFreeCallback freecb);
 
 /*
  * Capabilities of the connection / driver.
@@ -2861,16 +2891,6 @@ typedef int 
(*virConnectDomainEventCallback)(virConnectPtr conn,
  int detail,
  void *opaque);
 
-/*
- * virFreeCallback:
- * @opaque: opaque user data provided at registration
- *
- * Type for a domain event callback when the event is deregistered and
- * need to be freed, @opaque is provided along with the callback at
- * registration time
- */
-typedef void (*virFreeCallback)(void *opaque);
-
 int virConnectDomainEventRegister(virConnectPtr conn,
   virConnectDomainEventCallback cb,
   void *opaque,
diff --git a/src/datatypes.c b/src/datatypes.c
index d718170..5d415b8 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -115,6 +115,10 @@ virReleaseConnect(virConnectPtr conn) {
 
 virMutexLock(&conn->lock);
 
+if (conn->closeOpaque &&
+conn->closeFreeCallback)
+conn->closeFreeCallback(conn->closeOpaque);
+
 virResetError(&conn->err);
 
 virURIFree(conn->uri);
diff --git a/src/datatypes.h b/src/datatypes.h
index fc284d2..af054ac 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -187,6 +187,11 @@ struct _virConnect {
 virErrorFunc handler;   /* associated handlet */
 void *userData; /* the user data */
 
+/* Per-connection close callback */
+virConnectCloseFunc closeCallback;
+void *closeOpaque;
+virFreeCallback closeFreeCallback;
+
 int refs; /* reference count */
 };
 
diff --git a/src/libvirt.c b/src/libvirt.c
index df78e8a..7a4a17c 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -18613,6 +18613,66 @@ error:
 
 
 /**
+ * virConnectSetCloseCallback:
+ * @conn: pointer to connection object
+ * @cb: callback to invoke upon close
+ * @opaque: user data to pass to @cb
+ * @freecb: callback to free @opaque
+ *
+ * Registers a callback to be invoked when the connection
+ * is closed. This callback is invoked when there is any
+ * condition that causes the socket connection to the
+ * hypervisor to be closed.
+ *
+ * This function is only applicable to hypervisor drivers
+ * which maintain a persistent open connection. Drivers
+ * which open a new connection for every operation will
+ * not invoke this.
+ *
+ * The @freecb must not invoke any other libvirt public
+ * APIs, since it is not called from a re-entrant safe
+ * context.
+ *
+ * Returns 0 on success, -1 on error
+ */
+int virConnectSetCloseCallback(virConnectPtr conn,
+   virConnectCloseFunc cb,
+   void *opaque,
+   virFreeCallback freecb)
+{
+

Re: [libvirt] [PATCH 5/5] Extend events demo to show close callbacks in use

2012-07-20 Thread Daniel P. Berrange
On Thu, Jul 19, 2012 at 01:12:33PM -0600, Eric Blake wrote:
> On 07/19/2012 09:04 AM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" 
> > 
> > Use a driver close callback to trigger shutdown of the
> > events demo program
> > 
> > Signed-off-by: Daniel P. Berrange 
> > ---
> >  examples/domain-events/events-c/event-test.c |   33 
> > --
> >  1 file changed, 31 insertions(+), 2 deletions(-)
> > 
> > diff --git a/examples/domain-events/events-c/event-test.c 
> > b/examples/domain-events/events-c/event-test.c
> > index ef6e77a..f2427ad 100644
> > --- a/examples/domain-events/events-c/event-test.c
> > +++ b/examples/domain-events/events-c/event-test.c
> > @@ -16,6 +16,8 @@
> >  # define ATTRIBUTE_UNUSED __attribute__((__unused__))
> >  #endif
> >  
> > +int run = 1;
> 
> bool?  Then again,  isn't available everywhere, and I think
> our examples can work with C89 even though the rest of our project
> requires C99.
> 
> > @@ -380,7 +407,6 @@ void usage(const char *pname)
> >  printf("%s uri\n", pname);
> >  }
> >  
> > -int run = 1;
> 
> not to mention it was just code motion.
> 
> > @@ -426,6 +452,9 @@ int main(int argc, char **argv)
> >  return -1;
> >  }
> >  
> > +virConnectSetCloseCallback(dconn,
> > +   connectClose, NULL, NULL);
> 
> :) I was right - passing a NULL opaque is useful!

And pasing NULL is already allowed.

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 3/5] Add callback to virNetClient to be invoked on connection close

2012-07-20 Thread Daniel P. Berrange
On Thu, Jul 19, 2012 at 11:57:17AM -0600, Eric Blake wrote:
> On 07/19/2012 09:04 AM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" 
> > 
> > Allow detection of socket close in virNetClient via an callback
> > function, triggered on any condition that causes the socket to
> > be close.
> > 
> > Signed-off-by: Daniel P. Berrange 
> > ---
> 
> > @@ -463,6 +480,9 @@ void virNetClientFree(virNetClientPtr client)
> >  return;
> >  }
> >  
> > +if (client->closeFf && client->closeOpaque)
> > +client->closeFf(client->closeOpaque);
> 
> Again, you should not be forcing closeOpaque to be non-NULL.  It's
> opaque, after all.

If opaque is NULL, then there's nothing that needs free'ing.

> > @@ -534,7 +561,7 @@ virNetClientCloseLocked(virNetClientPtr client)
> >  static void virNetClientCloseInternal(virNetClientPtr client,
> >int reason)
> >  {
> > -VIR_DEBUG("client=%p", client);
> > +VIR_DEBUG("client=%p wantclose=%d", client, client ? client->wantClose 
> > : false);
> 
> Passing 'false' to %d looks odd, but works.  If, per my 2/5 comments,
> you merge wantClose into closeReason, then you'd have an int instead of
> a bool to print here.
> 
> ACK, once you fix the non-NULL opaque limitation.

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/3] Make sure xenHypervisorInit correctly reports errors

2012-07-20 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

The xenHypervisorInit method was called from two different
locations, during initial driver registration and also while
opening a Xen connection. The former can't report any useful
errors to the end user/app, so remove it. To ensure thread
safety use a VIR_ONCE_GLOBAL_INIT call to invoke
xenHypervisorInit from the xenHypervisorOpen method.
---
 src/xen/xen_driver.c |3 ---
 src/xen/xen_hypervisor.c |   31 ++-
 2 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 43b2620..5e7d87c 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2273,9 +2273,6 @@ static virDriver xenUnifiedDriver = {
 int
 xenRegister (void)
 {
-/* Ignore failures here. */
-(void) xenHypervisorInit (NULL);
-
 #ifdef WITH_LIBVIRTD
 if (virRegisterStateDriver (&state_driver) == -1) return -1;
 #endif
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 9747010..e737564 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -65,6 +65,7 @@
 #include "buf.h"
 #include "capabilities.h"
 #include "memory.h"
+#include "threads.h"
 #include "virfile.h"
 #include "virnodesuspend.h"
 #include "virtypedparam.h"
@@ -113,8 +114,6 @@ typedef privcmd_hypercall_t hypercall_t;
 #endif
 
 static int xen_ioctl_hypercall_cmd = 0;
-static int initialized = 0;
-static int in_init = 0;
 static struct xenHypervisorVersions hv_versions = {
 .hv = 0,
 .hypervisor = 2,
@@ -887,7 +886,6 @@ struct xenUnifiedDriver xenHypervisorDriver = {
 };
 
 #define virXenError(code, ...) \
-if (in_init == 0)  \
 virReportErrorHelper(VIR_FROM_XEN, code, __FILE__, \
  __FUNCTION__, __LINE__, __VA_ARGS__)
 
@@ -1973,14 +1971,6 @@ xenHypervisorInit(struct xenHypervisorVersions 
*override_versions)
 xen_getdomaininfo info;
 virVcpuInfoPtr ipt = NULL;
 
-if (initialized) {
-if (hv_versions.hypervisor == -1)
-return -1;
-return 0;
-}
-initialized = 1;
-in_init = 1;
-
 /* Compile regular expressions used by xenHypervisorGetCapabilities.
  * Note that errors here are really internal errors since these
  * regexps should never fail to compile.
@@ -1991,7 +1981,6 @@ xenHypervisorInit(struct xenHypervisorVersions 
*override_versions)
 regerror (errcode, &flags_hvm_rec, error, sizeof(error));
 regfree (&flags_hvm_rec);
 virXenError(VIR_ERR_INTERNAL_ERROR, "%s", error);
-in_init = 0;
 return -1;
 }
 errcode = regcomp (&flags_pae_rec, flags_pae_re, REG_EXTENDED);
@@ -2001,7 +1990,6 @@ xenHypervisorInit(struct xenHypervisorVersions 
*override_versions)
 regfree (&flags_pae_rec);
 regfree (&flags_hvm_rec);
 virXenError(VIR_ERR_INTERNAL_ERROR, "%s", error);
-in_init = 0;
 return -1;
 }
 errcode = regcomp (&xen_cap_rec, xen_cap_re, REG_EXTENDED);
@@ -2012,13 +2000,11 @@ xenHypervisorInit(struct xenHypervisorVersions 
*override_versions)
 regfree (&flags_pae_rec);
 regfree (&flags_hvm_rec);
 virXenError(VIR_ERR_INTERNAL_ERROR, "%s", error);
-in_init = 0;
 return -1;
 }
 
 if (override_versions) {
   hv_versions = *override_versions;
-  in_init = 0;
   return 0;
 }
 
@@ -2075,7 +2061,6 @@ xenHypervisorInit(struct xenHypervisorVersions 
*override_versions)
  _("Unable to issue hypervisor ioctl %lu"),
  (unsigned long)IOCTL_PRIVCMD_HYPERCALL);
 VIR_FORCE_CLOSE(fd);
-in_init = 0;
 return -1;
 
  detect_v2:
@@ -2181,17 +2166,22 @@ xenHypervisorInit(struct xenHypervisorVersions 
*override_versions)
  (unsigned long)IOCTL_PRIVCMD_HYPERCALL);
 VIR_DEBUG("Failed to find any Xen hypervisor method");
 VIR_FORCE_CLOSE(fd);
-in_init = 0;
 VIR_FREE(ipt);
 return -1;
 
  done:
 VIR_FORCE_CLOSE(fd);
-in_init = 0;
 VIR_FREE(ipt);
 return 0;
 }
 
+
+static int xenHypervisorOnceInit(void) {
+return xenHypervisorInit(NULL);
+}
+
+VIR_ONCE_GLOBAL_INIT(xenHypervisor)
+
 /**
  * xenHypervisorOpen:
  * @conn: pointer to the connection block
@@ -2212,9 +2202,8 @@ xenHypervisorOpen(virConnectPtr conn,
 
 virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
 
-if (initialized == 0)
-if (xenHypervisorInit(NULL) == -1)
-return -1;
+if (xenHypervisorInitialize() < 0)
+return -1;
 
 priv->handle = -1;
 
-- 
1.7.10.4

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


Re: [libvirt] [PATCH 1/5] Add public API to register a callback to be invoked on connection close

2012-07-20 Thread Daniel P. Berrange
On Thu, Jul 19, 2012 at 11:46:28AM -0600, Eric Blake wrote:
> On 07/19/2012 09:04 AM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" 
> > 
> > Define a new virConnectSetCloseCallback() public API which allows
> > registering a callback to be invoked when the connection to a
> > hypervisor is closed. The callback is provided with the reason for
> > the close, which may be 'error', 'eof' or 'keepalive'.
> > 
> > Signed-off-by: Daniel P. Berrange 
> > ---
> >  include/libvirt/libvirt.h.in |   40 +++
> >  src/datatypes.c  |4 
> >  src/datatypes.h  |5 
> >  src/libvirt.c|   53 
> > ++
> >  src/libvirt_public.syms  |6 +
> >  5 files changed, 98 insertions(+), 10 deletions(-)
> 
> >  
> > +typedef enum {
> > +VIR_CONNECT_CLOSE_REASON_ERROR = 1, /* Misc I/O error */
> 
> Any reason you skipped 0?  It will make wrapping this in a VIR_ENUM harder.

No, that's a mistake.

> 
> 
> > +int virConnectSetCloseCallback(virConnectPtr conn,
> > +   virConnectCloseFunc cb,
> > +   void *opaque,
> > +   virFreeCallback freecb);
> 
> Do we want a 'flags' argument?

No, I don't think so for the callbacks

> 
> > +++ b/src/datatypes.c
> > @@ -115,6 +115,10 @@ virReleaseConnect(virConnectPtr conn) {
> >  
> >  virMutexLock(&conn->lock);
> >  
> > +if (conn->closeOpaque &&
> 
> NACK to this half of the condition.  A client should be allowed to pass
> NULL as their opaque data.

This doesn't prevent them passing NULL. The 'virFreeFunc' callback is
for free'ing the 'opaque' data. If the opaque data is NULL, there is
nothing that requires free'ing.

> > +int virConnectSetCloseCallback(virConnectPtr conn,
> > +   virConnectCloseFunc cb,
> > +   void *opaque,
> > +   virFreeCallback freecb)
> > +{
> > +VIR_DEBUG("conn=%p", conn);
> > +
> > +virResetLastError();
> > +
> > +if (!VIR_IS_CONNECT(conn)) {
> > +virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
> > +virDispatchError(NULL);
> > +return -1;
> > +}
> > +
> > +virMutexLock(&conn->lock);
> > +
> > +if (conn->closeOpaque &&
> > +conn->closeFreeCallback)
> > +conn->closeFreeCallback(conn->closeOpaque);
> 
> Again, no need to check closeOpaque, NULL is valid there.

Same point as above.

> > +
> > +conn->closeCallback = cb;
> > +conn->closeOpaque = opaque;
> > +conn->closeFreeCallback = freecb;
> 
> So the user can call this as many times as they want to override or
> uninstall an existing registered callback?  I guess that works.

Alternatively I could raise an error, probably nicer than silently
overriding an existing callback

> 
> ACK, once you allow a NULL opaque pointer, and answer why a flags is not
> useful (or else add a flags).

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 1/3] Ensure failure to talk to Xen hypervisor is fatal when privileged

2012-07-20 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

As per the comment, the Xen hypervisor driver is considered to
be mandatory when running privileged. When it fails to open,
we should thus return an error, not ignore it.
---
 src/xen/xen_driver.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 9ff3d29..43b2620 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -340,6 +340,8 @@ xenUnifiedOpen (virConnectPtr conn, virConnectAuthPtr auth, 
unsigned int flags)
 if (xenHypervisorOpen(conn, auth, flags) == VIR_DRV_OPEN_SUCCESS) {
 VIR_DEBUG("Activated hypervisor sub-driver");
 priv->opened[XEN_UNIFIED_HYPERVISOR_OFFSET] = 1;
+} else {
+goto fail;
 }
 }
 
-- 
1.7.10.4

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


  1   2   >