Re: [libvirt] [PATCH v13 05/49] qemu: use general virhostdev lists instead of its own

2014-03-05 Thread Chunyan Liu
2014-03-04 20:38 GMT+08:00 Daniel P. Berrange berra...@redhat.com:

 On Sat, Mar 01, 2014 at 02:29:00PM +0800, Chunyan Liu wrote:
 
  Signed-off-by: Chunyan Liu cy...@suse.com
  ---
   src/qemu/qemu_conf.h|8 --
   src/qemu/qemu_driver.c  |   74 +--
   src/qemu/qemu_hostdev.c |  192
 ---
   src/qemu/qemu_hotplug.c |1 +
   4 files changed, 151 insertions(+), 124 deletions(-)
 
  diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
  index ece185b..2ac88fb 100644
  --- a/src/qemu/qemu_conf.h
  +++ b/src/qemu/qemu_conf.h
  @@ -215,14 +215,6 @@ struct _virQEMUDriver {
   /* Immutable pointer. self-locking APIs */
   virSecurityManagerPtr securityManager;
 
  -/* Immutable pointers. Requires locks to be held before
  - * calling APIs. activePciHostdevs must be locked before
  - * inactivePciHostdevs */
  -virPCIDeviceListPtr activePciHostdevs;
  -virPCIDeviceListPtr inactivePciHostdevs;
  -virUSBDeviceListPtr activeUsbHostdevs;
  -virSCSIDeviceListPtr activeScsiHostdevs;
  -
   /* Immutable pointer. Unsafe APIs. XXX */
   virHashTablePtr sharedDevices;
 
  diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
  index f36a8b4..7d924b2 100644
  --- a/src/qemu/qemu_driver.c
  +++ b/src/qemu/qemu_driver.c
  @@ -95,6 +95,7 @@
   #include viraccessapicheck.h
   #include viraccessapicheckqemu.h
   #include storage/storage_driver.h
  +#include virhostdev.h
 
   #define VIR_FROM_THIS VIR_FROM_QEMU
 
  @@ -695,18 +696,6 @@ qemuStateInitialize(bool privileged,
   if (qemuSecurityInit(qemu_driver)  0)
   goto error;
 
  -if ((qemu_driver-activePciHostdevs = virPCIDeviceListNew()) ==
 NULL)
  -goto error;
  -
  -if ((qemu_driver-activeUsbHostdevs = virUSBDeviceListNew()) ==
 NULL)
  -goto error;
  -
  -if ((qemu_driver-inactivePciHostdevs = virPCIDeviceListNew()) ==
 NULL)
  -goto error;
  -
  -if ((qemu_driver-activeScsiHostdevs = virSCSIDeviceListNew()) ==
 NULL)
  -goto error;
  -

 I think we should obtain the hostdev manager instance here, and save a
 reference to it, so that later functions do not need to worry about
 failure of virHostdevManagerGetDefault()

 we could:
 add .hostdev_mgr to _virQEMUDriver, and add
 qemu_driver-hostdev_mgr = virHostdevManagerGetDefault() here.
 Is that OK?


  diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
  index 5546693..eeb1f24 100644
  --- a/src/qemu/qemu_hotplug.c
  +++ b/src/qemu/qemu_hotplug.c
  @@ -50,6 +50,7 @@
   #include virstoragefile.h
   #include virstring.h
   #include virtime.h
  +#include virhostdev.h

 This seems bogus as you're not adding any code to this file which would
 use those APIs

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


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

Re: [libvirt] [PATCH 4/7] Turn virLogSource into a struct instead of an enum

2014-03-05 Thread Ján Tomko
On 03/03/2014 08:18 PM, Daniel P. Berrange wrote:
 As part of the goal to get away from doing string matching on
 filenames when deciding whether to emit a log message, turn
 the virLogSource enum into a struct which contains a log
 name. There will eventually be one virLogSource instance
 statically declared per source file. To minimise churn in this
 commit though, a single global instance is used.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  src/libvirt_private.syms   |  1 +
  src/node_device/node_device_udev.c |  2 +-
  src/qemu/qemu_capabilities.c   |  2 +-
  src/util/viraudit.c|  7 ---
  src/util/viraudit.h| 10 ++
  src/util/virerror.c|  2 +-
  src/util/virlog.c  | 30 --
  src/util/virlog.h  | 33 -
  src/util/virprobe.h|  4 ++--
  tests/testutils.c  |  2 +-
  10 files changed, 45 insertions(+), 48 deletions(-)
 

 diff --git a/src/util/virlog.h b/src/util/virlog.h
 index 6ba2daa..cb27725 100644
 --- a/src/util/virlog.h
 +++ b/src/util/virlog.h

 @@ -68,7 +67,7 @@ typedef enum {
   *
   * Do nothing but eat parameters.
   */
 -static inline void virLogEatParams(virLogSource unused, ...)
 +static inline void virLogEatParams(virLog unused, ...)

s/virLog /virLogSourcePtr /

  {
  /* Silence gcc */
  unused = unused;

Jan



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

Re: [libvirt] [RFC] support memory reserved feature and optimize mlock guest memory propose

2014-03-05 Thread Paolo Bonzini
Il 05/03/2014 09:01, Zhanghailiang ha scritto:
 Hi all:
 
 Currently, we use cgroup(memory) to support memory QoS on KVM platform,
 and use mlock on qemu to support memory reserved.
 
 The mlock seems to be not appropriate.
 
 Now qemu mlock memory in the main thread, which would lock iothread
 (qemu_mutex_lock_iothread), if the memory size is large, that will
 consume lots of time.
 
 It means whenever we want to set a new 'mlock', the VM would be blocked
 for a while.

I'm not sure I understand how the mlock-ed memory is used.  Are you
using a custom malloc, for example with g_mem_set_vtable?

Paolo

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

[libvirt] libvirt xml can't specify USB physical port when passthrough USB device to VM

2014-03-05 Thread Wangrui (K)
Hello,

I passthrough a host usb device to a guest  with a bus number and device number 
in the xml to identify the usb device.
When I unplug and then plug back into the same USB physical port, the guest 
identifies the usb device failed. Because on the host ,the usb device number 
increases.
So , I want to know that whether Libvirt will provide an interface that 
identifies a host usb device with bus number and physical port .
As far as I know ,Qemu upstream had added a hostport property which allows to 
specify the host usb with bus number and physical port.
the patch is :
https://lists.gnu.org/archive/html/qemu-devel/2011-05/msg02341.html

Best Regards

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

Re: [libvirt] [PATCHv2 6/7] doc: storage: Explicitly state that it's possible to have non-unique key

2014-03-05 Thread Peter Krempa
On 03/05/14 05:47, Eric Blake wrote:
 On 03/03/2014 09:05 AM, Peter Krempa wrote:
 With most of our storage backends it's possible to have two separate
 volume keys to point to a single volume. (By creating sym/hard-links to
 local files or by mounting remote filesystems to two different locations
 and creating pools on top of them) Document this possibility.
 ---
  docs/formatstorage.html.in | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)
 
 ACK.
 

Thanks. I've pushed patches 1-6 of this series with the fixes requested.
Peter




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

Re: [libvirt] [PATCH v4 3/3] allow virsh dump --memory-only specify dump format

2014-03-05 Thread qiaonuo...@cn.fujitsu.com
On 03/04/2014 07:45 PM, Daniel P. Berrange wrote:
 On Mon, Mar 03, 2014 at 10:27:26AM +0800, qiaonuohan wrote:
 This patch is used to add --compress and [--compression-format]string 
 to
 virsh dump --memory-only. And virsh dump --memory-only is going be
 implemented by new virDomainCoreDumpWithFormat API.

 Signed-off-by: Qiao Nuohanqiaonuo...@cn.fujitsu.com
 ---
   tools/virsh-domain.c | 45 -
   1 file changed, 44 insertions(+), 1 deletion(-)

 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
 index 2e3f0ed..70613e5 100644
 --- a/tools/virsh-domain.c
 +++ b/tools/virsh-domain.c
 @@ -4486,6 +4486,14 @@ static const vshCmdOptDef opts_dump[] = {
.type = VSH_OT_BOOL,
.help = N_(dump domain's memory only)
   },
 +{.name = compress,
 + .type = VSH_OT_BOOL,
 + .help = N_(make qemu dump domain's memory in kdump-compressed format)
 +},
 +{.name = compression-format,
 + .type = VSH_OT_DATA,
 + .help = N_(specify the compression format of kdump-compressed format)
 +},
   {.name = NULL}
   };

 I don't really see much point in having both args here - it is overly
 verbose IMHO.

 I suggest  '--compress FORMAT' as a single arg

zlib/lzo/snappy are the compression types that will be supported. Obviously,
one of them, zlib, is used more *frequently*.

Actually, I wanted to add '--compress [format]'(argument can be omitted) to
make things simple. '--compress' alone is enough to specify zlib, and
'--compress format' is available to specify other formats. But such optional
argument is not supported in libvirt. So I use --compress, instead of 
'--compression-format zlib', to shorten the amount of typing when using zlib.

This is the use case, then what do you think.


 Regards,
 Daniel


-- 
Regards
Qiao Nuohan

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


Re: [libvirt] [PATCH v2] qemu: Reject unsupported tuning in session mode

2014-03-05 Thread Martin Kletzander
On Tue, Mar 04, 2014 at 02:04:05PM -0700, Eric Blake wrote:
 On 03/04/2014 07:15 AM, Martin Kletzander wrote:
  When domain is started with setting that cannot be done, i.e. those
  that require cgroups, there is no error reported and it succeeds
  without any message whatsoever.
 
  When setting with API, virsh, an error is reported, but only due to
  the fact that no cgroups are mounted (priv-cgroup == NULL).
 
  Given the above it seems reasonable to reject such unsupported
  settings.
 
  Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1023366
 
  Signed-off-by: Martin Kletzander mklet...@redhat.com
  ---
 
  @@ -7443,6 +7445,13 @@ static char *qemuDomainGetSchedulerType(virDomainPtr 
  dom,
   if (virDomainGetSchedulerTypeEnsureACL(dom-conn, vm-def)  0)
   goto cleanup;
 
  +cfg = virQEMUDriverGetConfig(driver);
  +if (!cfg-privileged) {
  +virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s,
  +   _(CPU tuning is not available in session mode));
  +goto cleanup;
  +}
  +
   /* Domain not running, thus no cgroups - return defaults */
   if (!virDomainObjIsActive(vm)) {

 I can understand failing the Set commands if we can't change things; but
 since we have a fallback for the Get command even for an offline domain,
 shouldn't we stick to returning the defaults rather than erroring out?


Particularly for SchedulerType, we can allow the Get method, but the
reading will still fail as there are no cgroups set up.  If we rework
our cgroups code for non-privileged daemons, we will have to check the
cgroup in which the domain belongs to, which will be the same as other
user processes, and doe to that fact the settings won't apply only to
that domain, but for everything in that cgroup; that will make the
values less useful (e.g. maximum used memory cannot be guaranteed
since the cgroup has more tasks inside than only qemu).  Our cgroup
path assembly functions will then need to differ based on whether it
is non-privileged or not.

If that's really needed, I'll rework it that way (even though it'll
probably need to get changed back when user cgroups will be
user-editable), but until then, could we make the error reported now:

$ virsh -c qemu:///session schedinfo dummy
Scheduler  : Unknown
error: Requested operation is not valid: cgroup CPU controller is not mounted

changed into:

$ virsh -c qemu:///session schedinfo dummy
Scheduler  : Unknown
error: Operation not supported: CPU tuning is not available in session mode

???

// I should've added that info into the commit message, I just forgot.

Martin

 Weak ACK; I'd still wait for Dan to weigh in.

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



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

Re: [libvirt] [PATCH 1/2] Treat zero cpu shares as a valid value

2014-03-05 Thread Ján Tomko
On 03/04/2014 03:30 PM, Martin Kletzander wrote:
 On Tue, Mar 04, 2014 at 02:13:14PM +0100, Ján Tomko wrote:
 Currently, cputuneshares0/shares/cputune is treated
 as if it were not specified.

 
 s/were/was/ in this particular case, I guess.
 

I think this particular case is a perfectly cromulent use of the past
subjunctive to express a counterfactual condition.

 ACK,
 
 Martin
 

Thank you for the review, I will take another look at the series before
pushing, since this was an RFC.

Jan



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 v13 05/49] qemu: use general virhostdev lists instead of its own

2014-03-05 Thread Daniel P. Berrange
On Wed, Mar 05, 2014 at 04:03:19PM +0800, Chunyan Liu wrote:
 2014-03-04 20:38 GMT+08:00 Daniel P. Berrange berra...@redhat.com:
 
  On Sat, Mar 01, 2014 at 02:29:00PM +0800, Chunyan Liu wrote:
  
   Signed-off-by: Chunyan Liu cy...@suse.com
   ---
src/qemu/qemu_conf.h|8 --
src/qemu/qemu_driver.c  |   74 +--
src/qemu/qemu_hostdev.c |  192
  ---
src/qemu/qemu_hotplug.c |1 +
4 files changed, 151 insertions(+), 124 deletions(-)
  
   diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
   index ece185b..2ac88fb 100644
   --- a/src/qemu/qemu_conf.h
   +++ b/src/qemu/qemu_conf.h
   @@ -215,14 +215,6 @@ struct _virQEMUDriver {
/* Immutable pointer. self-locking APIs */
virSecurityManagerPtr securityManager;
  
   -/* Immutable pointers. Requires locks to be held before
   - * calling APIs. activePciHostdevs must be locked before
   - * inactivePciHostdevs */
   -virPCIDeviceListPtr activePciHostdevs;
   -virPCIDeviceListPtr inactivePciHostdevs;
   -virUSBDeviceListPtr activeUsbHostdevs;
   -virSCSIDeviceListPtr activeScsiHostdevs;
   -
/* Immutable pointer. Unsafe APIs. XXX */
virHashTablePtr sharedDevices;
  
   diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
   index f36a8b4..7d924b2 100644
   --- a/src/qemu/qemu_driver.c
   +++ b/src/qemu/qemu_driver.c
   @@ -95,6 +95,7 @@
#include viraccessapicheck.h
#include viraccessapicheckqemu.h
#include storage/storage_driver.h
   +#include virhostdev.h
  
#define VIR_FROM_THIS VIR_FROM_QEMU
  
   @@ -695,18 +696,6 @@ qemuStateInitialize(bool privileged,
if (qemuSecurityInit(qemu_driver)  0)
goto error;
  
   -if ((qemu_driver-activePciHostdevs = virPCIDeviceListNew()) ==
  NULL)
   -goto error;
   -
   -if ((qemu_driver-activeUsbHostdevs = virUSBDeviceListNew()) ==
  NULL)
   -goto error;
   -
   -if ((qemu_driver-inactivePciHostdevs = virPCIDeviceListNew()) ==
  NULL)
   -goto error;
   -
   -if ((qemu_driver-activeScsiHostdevs = virSCSIDeviceListNew()) ==
  NULL)
   -goto error;
   -
 
  I think we should obtain the hostdev manager instance here, and save a
  reference to it, so that later functions do not need to worry about
  failure of virHostdevManagerGetDefault()
 
  we could:
  add .hostdev_mgr to _virQEMUDriver, and add
  qemu_driver-hostdev_mgr = virHostdevManagerGetDefault() here.
  Is that OK?

Yes, that would be good, and the same for LXC + libxl drivers too.

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

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


Re: [libvirt] [PATCH v13 00/49] write separate module for hostdev passthrough

2014-03-05 Thread Daniel P. Berrange
On Wed, Mar 05, 2014 at 02:15:51PM +0800, Chunyan Liu wrote:
 2014-03-04 0:57 GMT+08:00 Cedric Bosdonnat cbosdon...@suse.com:
 
  Hello ChunYan,
 
  I saw a few minor problems in some patches that made me rebase quite a
  lot of other patches in your serie, but otherwise it really looks good
  to me.
 
  Here is a summary of the changes I made or questions I have:
  * Patch 2: Fixed a few remaining changes that broke the build.
Just remember that having the tree building after each commit
helps a lot when one later needs to bisect.
  * Patch 4: when is the manager freed?
 
 It's hard to find a specified code point to free the manager, since we
 don't know is there anyone else still using it.

If we now keep a reference to the manager in the virQEMUDriver struct
and the same for the LXC/libxl drivers, then you could turn the
virHostdevManagerPtr struct into a virObject. Then you can use ref
counting to make it get free'd when the drivers shutdown.

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

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


[libvirt] [PATCH v3 0/2] Introduce max_anonymous_clients

2014-03-05 Thread Michal Privoznik
https://bugzilla.redhat.com/show_bug.cgi?id=981729

So far we can limit how many clients are connected,
how many are waiting in accept() line but we could
not control the count of accepted but not
authenticated yet.

diff to v2:
-Dan's suggestions worked in

Michal Privoznik (2):
  virNetServer: Introduce unauth clients counter
  daemon: Introduce max_anonymous_clients

 daemon/libvirtd-config.c|   4 +-
 daemon/libvirtd-config.h|   1 +
 daemon/libvirtd.aug |   1 +
 daemon/libvirtd.c   |   1 +
 daemon/libvirtd.conf|   6 ++-
 daemon/remote.c |  21 +
 daemon/test_libvirtd.aug.in |   3 +-
 src/locking/lock_daemon.c   |   2 +-
 src/lxc/lxc_controller.c|   2 +-
 src/rpc/virnetserver.c  | 108 
 src/rpc/virnetserver.h  |   4 ++
 11 files changed, 130 insertions(+), 23 deletions(-)

-- 
1.9.0

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


Re: [libvirt] [PATCH v4 2/3] add qemu support to virDomainCoreDumpWithFormat API

2014-03-05 Thread qiaonuo...@cn.fujitsu.com
On 03/04/2014 07:44 PM, Daniel P. Berrange wrote:
 On Mon, Mar 03, 2014 at 10:27:25AM +0800, qiaonuohan wrote:
   This patch makes qemu driver supprot virDomainCoreDumpWithFormat API.
   ---
 src/qemu/qemu_driver.c   | 45 
  +++-
 src/qemu/qemu_monitor.c  |  7 ---
 src/qemu/qemu_monitor.h  |  3 ++-
 src/qemu/qemu_monitor_json.c |  4 +++-
 src/qemu/qemu_monitor_json.h |  3 ++-
 tests/qemumonitorjsontest.c  |  2 +-
 6 files changed, 48 insertions(+), 16 deletions(-)
 
   diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
   index c9a865e..f373f7c 100644
   --- a/src/qemu/qemu_driver.c
   +++ b/src/qemu/qemu_driver.c
   @@ -3452,7 +3455,20 @@ doCoreDump(virQEMUDriverPtr driver,
 goto cleanup;
 
 if (dump_flags  VIR_DUMP_MEMORY_ONLY) {
   -ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP);
   +if (dumpformat == VIR_DUMP_FORMAT_RAW)
   +memory_dump_format = elf;
   +else if (dumpformat == VIR_DUMP_FORMAT_KDUMP_ZLIB)
   +memory_dump_format = kdump-zlib;
   +else if (dumpformat == VIR_DUMP_FORMAT_KDUMP_LZO)
   +memory_dump_format = kdump-lzo;
   +else if (dumpformat == VIR_DUMP_FORMAT_KDUMP_SNAPPY)
   +memory_dump_format = kdump-snappy;
   +else {
   +virReportError(VIR_ERR_INVALID_ARG,
   +   _(unknown dumpformat '%d'), dumpformat);
   +}
   +ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
   +   memory_dump_format);
 } else {
 ret = qemuMigrationToFile(driver, vm, fd, 0, path,
   qemuCompressProgramName(compress), 
  false,
 The else branch here should raise VIR_ERR_OPERATION_UNSUPPORTED
 if dumpformat != VIR_DUMP_FORMAT_RAW


So here is the place I should do the implmentation restriction(mentioned in
your last mail), then VIR_DUMP_FORMAT_RAW is the only choice when
VIR_DUMP_MEMORY_ONLY is not specified.

-- 
Regards
Qiao Nuohan

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


[libvirt] [PATCH v3 2/2] daemon: Introduce max_anonymous_clients

2014-03-05 Thread Michal Privoznik
https://bugzilla.redhat.com/show_bug.cgi?id=981729

This config tunable allows users to determine the maximum number of
accepted but yet not authenticated users.

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
 daemon/libvirtd-config.c|  4 ++-
 daemon/libvirtd-config.h|  1 +
 daemon/libvirtd.aug |  1 +
 daemon/libvirtd.c   |  1 +
 daemon/libvirtd.conf|  6 -
 daemon/test_libvirtd.aug.in |  3 ++-
 src/locking/lock_daemon.c   |  2 +-
 src/lxc/lxc_controller.c|  2 +-
 src/rpc/virnetserver.c  | 63 -
 src/rpc/virnetserver.h  |  1 +
 10 files changed, 72 insertions(+), 12 deletions(-)

diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c
index c816fda..c7e107b 100644
--- a/daemon/libvirtd-config.c
+++ b/daemon/libvirtd-config.c
@@ -258,7 +258,8 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
 
 data-min_workers = 5;
 data-max_workers = 20;
-data-max_clients = 20;
+data-max_clients = 5000;
+data-max_anonymous_clients = 20;
 
 data-prio_workers = 5;
 
@@ -415,6 +416,7 @@ daemonConfigLoadOptions(struct daemonConfig *data,
 GET_CONF_INT(conf, filename, max_workers);
 GET_CONF_INT(conf, filename, max_clients);
 GET_CONF_INT(conf, filename, max_queued_clients);
+GET_CONF_INT(conf, filename, max_anonymous_clients);
 
 GET_CONF_INT(conf, filename, prio_workers);
 
diff --git a/daemon/libvirtd-config.h b/daemon/libvirtd-config.h
index a24d5d2..66dc80b 100644
--- a/daemon/libvirtd-config.h
+++ b/daemon/libvirtd-config.h
@@ -64,6 +64,7 @@ struct daemonConfig {
 int max_workers;
 int max_clients;
 int max_queued_clients;
+int max_anonymous_clients;
 
 int prio_workers;
 
diff --git a/daemon/libvirtd.aug b/daemon/libvirtd.aug
index 70fce5c..5a0807c 100644
--- a/daemon/libvirtd.aug
+++ b/daemon/libvirtd.aug
@@ -57,6 +57,7 @@ module Libvirtd =
 | int_entry max_workers
 | int_entry max_clients
 | int_entry max_queued_clients
+| int_entry max_anonymous_clients
 | int_entry max_requests
 | int_entry max_client_requests
 | int_entry prio_workers
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 72f0e81..40cf671 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1376,6 +1376,7 @@ int main(int argc, char **argv) {
 config-max_workers,
 config-prio_workers,
 config-max_clients,
+config-max_anonymous_clients,
 config-keepalive_interval,
 config-keepalive_count,
 !!config-keepalive_required,
diff --git a/daemon/libvirtd.conf b/daemon/libvirtd.conf
index 073c178..64c215d 100644
--- a/daemon/libvirtd.conf
+++ b/daemon/libvirtd.conf
@@ -255,7 +255,7 @@
 
 # The maximum number of concurrent client connections to allow
 # over all sockets combined.
-#max_clients = 20
+#max_clients = 5000
 
 # The maximum length of queue of connections waiting to be
 # accepted by the daemon. Note, that some protocols supporting
@@ -263,6 +263,10 @@
 # connection succeeds.
 #max_queued_clients = 1000
 
+# The maximum length of queue of accepted but not yet not
+# authenticated clients. The default value is zero, meaning
+# the feature is disabled.
+#max_anonymous_clients = 20
 
 # The minimum limit sets the number of workers to start up
 # initially. If the number of active clients exceeds this,
diff --git a/daemon/test_libvirtd.aug.in b/daemon/test_libvirtd.aug.in
index a7e8515..37ff33d 100644
--- a/daemon/test_libvirtd.aug.in
+++ b/daemon/test_libvirtd.aug.in
@@ -34,8 +34,9 @@ module Test_libvirtd =
  { 1 = j...@example.com }
  { 2 = f...@example.com }
 }
-{ max_clients = 20 }
+{ max_clients = 5000 }
 { max_queued_clients = 1000 }
+{ max_anonymous_clients = 20 }
 { min_workers = 5 }
 { max_workers = 20 }
 { prio_workers = 5 }
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index e047751..054dda9 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -145,7 +145,7 @@ virLockDaemonNew(virLockDaemonConfigPtr config, bool 
privileged)
 }
 
 if (!(lockd-srv = virNetServerNew(1, 1, 0, config-max_clients,
-   -1, 0,
+   config-max_clients, -1, 0,
false, NULL,
virLockDaemonClientNew,
virLockDaemonClientPreExecRestart,
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 5ca960f..ab140f1 100644
--- a/src/lxc/lxc_controller.c
+++ 

[libvirt] [PATCH v3 1/2] virNetServer: Introduce unauth clients counter

2014-03-05 Thread Michal Privoznik
The counter gets incremented on each unauthenticated client added to the
server and decremented whenever the client authenticates.

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
 daemon/remote.c| 21 +
 src/rpc/virnetserver.c | 45 ++---
 src/rpc/virnetserver.h |  3 +++
 3 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index b48d456..416aa40 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -2619,7 +2619,7 @@ cleanup:
 /*-*/
 
 static int
-remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED,
+remoteDispatchAuthList(virNetServerPtr server,
virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr,
@@ -2649,6 +2649,7 @@ remoteDispatchAuthList(virNetServerPtr server 
ATTRIBUTE_UNUSED,
 goto cleanup;
 VIR_INFO(Bypass polkit auth for privileged client %s, ident);
 virNetServerClientSetAuth(client, 0);
+virNetServerTrackCompletedAuth(server);
 auth = VIR_NET_SERVER_SERVICE_AUTH_NONE;
 VIR_FREE(ident);
 }
@@ -2764,7 +2765,8 @@ authfail:
  * Returns 0 if ok, -1 on error, -2 if rejected
  */
 static int
-remoteSASLFinish(virNetServerClientPtr client)
+remoteSASLFinish(virNetServerPtr server,
+ virNetServerClientPtr client)
 {
 const char *identity;
 struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
@@ -2789,6 +2791,7 @@ remoteSASLFinish(virNetServerClientPtr client)
 return -2;
 
 virNetServerClientSetAuth(client, 0);
+virNetServerTrackCompletedAuth(server);
 virNetServerClientSetSASLSession(client, priv-sasl);
 
 VIR_DEBUG(Authentication successful %d, virNetServerClientGetFD(client));
@@ -2810,7 +2813,7 @@ error:
  * This starts the SASL authentication negotiation.
  */
 static int
-remoteDispatchAuthSaslStart(virNetServerPtr server ATTRIBUTE_UNUSED,
+remoteDispatchAuthSaslStart(virNetServerPtr server,
 virNetServerClientPtr client,
 virNetMessagePtr msg ATTRIBUTE_UNUSED,
 virNetMessageErrorPtr rerr,
@@ -2868,7 +2871,7 @@ remoteDispatchAuthSaslStart(virNetServerPtr server 
ATTRIBUTE_UNUSED,
 ret-complete = 0;
 } else {
 /* Check username whitelist ACL */
-if ((err = remoteSASLFinish(client))  0) {
+if ((err = remoteSASLFinish(server, client))  0) {
 if (err == -2)
 goto authdeny;
 else
@@ -2908,7 +2911,7 @@ error:
 
 
 static int
-remoteDispatchAuthSaslStep(virNetServerPtr server ATTRIBUTE_UNUSED,
+remoteDispatchAuthSaslStep(virNetServerPtr server,
virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr,
@@ -2966,7 +2969,7 @@ remoteDispatchAuthSaslStep(virNetServerPtr server 
ATTRIBUTE_UNUSED,
 ret-complete = 0;
 } else {
 /* Check username whitelist ACL */
-if ((err = remoteSASLFinish(client))  0) {
+if ((err = remoteSASLFinish(server, client))  0) {
 if (err == -2)
 goto authdeny;
 else
@@ -3051,7 +3054,7 @@ remoteDispatchAuthSaslStep(virNetServerPtr server 
ATTRIBUTE_UNUSED,
 
 #if WITH_POLKIT1
 static int
-remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED,
+remoteDispatchAuthPolkit(virNetServerPtr server,
  virNetServerClientPtr client,
  virNetMessagePtr msg ATTRIBUTE_UNUSED,
  virNetMessageErrorPtr rerr,
@@ -3142,6 +3145,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server 
ATTRIBUTE_UNUSED,
 ret-complete = 1;
 
 virNetServerClientSetAuth(client, 0);
+virNetServerTrackCompletedAuth(server);
 virMutexUnlock(priv-lock);
 virCommandFree(cmd);
 VIR_FREE(pkout);
@@ -3182,7 +3186,7 @@ authdeny:
 }
 #elif WITH_POLKIT0
 static int
-remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED,
+remoteDispatchAuthPolkit(virNetServerPtr server,
  virNetServerClientPtr client,
  virNetMessagePtr msg ATTRIBUTE_UNUSED,
  virNetMessageErrorPtr rerr,
@@ -3297,6 +3301,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server 
ATTRIBUTE_UNUSED,
 ret-complete = 1;
 
 virNetServerClientSetAuth(client, 0);
+virNetServerTrackCompletedAuth(server);
 virMutexUnlock(priv-lock);
 VIR_FREE(ident);
 return 0;
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index f70e260..3170f64 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -88,9 +88,10 @@ struct _virNetServer {
 size_t 

[libvirt] Python-libvirt in a virtual environment.

2014-03-05 Thread Sijo Jose
Hi,
Could you guide me to install libvirt in a virtual environment..?
OR
How python-libvirt could be used within a virtual environment after
installing it, in the system.

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

Re: [libvirt] [PATCH v4 1/3] add new virDomainCoreDumpWithFormat API

2014-03-05 Thread qiaonuo...@cn.fujitsu.com
On 03/04/2014 07:41 PM, Daniel P. Berrange wrote:
 diff --git a/src/test/test_driver.c b/src/test/test_driver.c
 index b724f82..605b0d1 100644
 --- a/src/test/test_driver.c
 +++ b/src/test/test_driver.c
 @@ -2427,9 +2427,10 @@ testDomainRestore(virConnectPtr conn,
   return testDomainRestoreFlags(conn, path, NULL, 0);
   }

 -static int testDomainCoreDump(virDomainPtr domain,
 -  const char *to,
 -  unsigned int flags)
 +static int testDomainCoreDumpWithFormat(virDomainPtr domain,
 +const char *to,
 +unsigned int dumpformat,
 +unsigned int flags)
   {
   testConnPtr privconn = domain-conn-privateData;
   int fd = -1;
 @@ -2479,6 +2480,12 @@ static int testDomainCoreDump(virDomainPtr domain,
   }
   }

 +if (dumpformat  VIR_DUMP_FORMAT_KDUMP_SNAPPY) {
 +virReportSystemError(errno,
 + _(invalid value of dumpformat: %d), 
 dumpformat);
 +goto cleanup;
 +}

 This should be done in the libvirt.c entry point, comparing against
 VIR_DUMP_FORMAT_LAST


Is it OK, if I change the check to following one

+/* dump the core of domain to file to */
+if (virDomainCoreDumpWithFormat(domain, to, dumpformat, flags)  0) {
+goto cleanup;
+}


 Regards,
 Daniel


-- 
Regards
Qiao Nuohan

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


Re: [libvirt] [PATCH v4 1/3] add new virDomainCoreDumpWithFormat API

2014-03-05 Thread Daniel P. Berrange
On Wed, Mar 05, 2014 at 12:00:59PM +, qiaonuo...@cn.fujitsu.com wrote:
 On 03/04/2014 07:41 PM, Daniel P. Berrange wrote:
  diff --git a/src/test/test_driver.c b/src/test/test_driver.c
  index b724f82..605b0d1 100644
  --- a/src/test/test_driver.c
  +++ b/src/test/test_driver.c
  @@ -2427,9 +2427,10 @@ testDomainRestore(virConnectPtr conn,
return testDomainRestoreFlags(conn, path, NULL, 0);
}
 
  -static int testDomainCoreDump(virDomainPtr domain,
  -  const char *to,
  -  unsigned int flags)
  +static int testDomainCoreDumpWithFormat(virDomainPtr domain,
  +const char *to,
  +unsigned int dumpformat,
  +unsigned int flags)
{
testConnPtr privconn = domain-conn-privateData;
int fd = -1;
  @@ -2479,6 +2480,12 @@ static int testDomainCoreDump(virDomainPtr domain,
}
}
 
  +if (dumpformat  VIR_DUMP_FORMAT_KDUMP_SNAPPY) {
  +virReportSystemError(errno,
  + _(invalid value of dumpformat: %d), 
  dumpformat);
  +goto cleanup;
  +}
 
  This should be done in the libvirt.c entry point, comparing against
  VIR_DUMP_FORMAT_LAST
 
 
 Is it OK, if I change the check to following one
 
 +/* dump the core of domain to file to */
 +if (virDomainCoreDumpWithFormat(domain, to, dumpformat, flags)  0) {
 +goto cleanup;
 +}

Huh, I don't really see what you mean here.

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

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


Re: [libvirt] [PATCH v4 1/3] add new virDomainCoreDumpWithFormat API

2014-03-05 Thread qiaonuo...@cn.fujitsu.com
On 03/05/2014 08:42 PM, Daniel P. Berrange wrote:
 On Wed, Mar 05, 2014 at 12:00:59PM +, qiaonuo...@cn.fujitsu.com wrote:
 On 03/04/2014 07:41 PM, Daniel P. Berrange wrote:
 diff --git a/src/test/test_driver.c b/src/test/test_driver.c
 index b724f82..605b0d1 100644
 --- a/src/test/test_driver.c
 +++ b/src/test/test_driver.c
 @@ -2427,9 +2427,10 @@ testDomainRestore(virConnectPtr conn,
return testDomainRestoreFlags(conn, path, NULL, 0);
}

 -static int testDomainCoreDump(virDomainPtr domain,
 -  const char *to,
 -  unsigned int flags)
 +static int testDomainCoreDumpWithFormat(virDomainPtr domain,
 +const char *to,
 +unsigned int dumpformat,
 +unsigned int flags)
{
testConnPtr privconn = domain-conn-privateData;
int fd = -1;
 @@ -2479,6 +2480,12 @@ static int testDomainCoreDump(virDomainPtr domain,
}
}

 +if (dumpformat   VIR_DUMP_FORMAT_KDUMP_SNAPPY) {
 +virReportSystemError(errno,
 + _(invalid value of dumpformat: %d), 
 dumpformat);
 +goto cleanup;
 +}

 This should be done in the libvirt.c entry point, comparing against
 VIR_DUMP_FORMAT_LAST


 Is it OK, if I change the check to following one

 +/* dump the core of domain to file to */
 +if (virDomainCoreDumpWithFormat(domain, to, dumpformat, flags)  0) {
 +goto cleanup;
 +}

 Huh, I don't really see what you mean here.

parameter of testXXX should be used, or it won't go through make. My computer
output the following message. I just want to check is it OK to use
virDomainCoreDumpWithFormat here.

cut
...
   CC qemu/libvirt_driver_qemu_impl_la-qemu_capabilities.lo
   CC qemu/libvirt_driver_qemu_impl_la-qemu_command.lo
   CC qemu/libvirt_driver_qemu_impl_la-qemu_domain.lo
cc1: warnings being treated as errors
test/test_driver.c: In function 'testDomainCoreDumpWithFormat':
test/test_driver.c:2432: error: unused parameter 'dumpformat' 
[-Wunused-parameter]
make[3]: *** [test/libvirt_driver_test_la-test_driver.lo] Error 1
make[3]: *** Waiting for unfinished jobs
make[3]: Leaving directory `/work/qemu/libvirt/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/work/qemu/libvirt/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/work/qemu/libvirt'
make: *** [all] Error 2
cut


 Regards,
 Daniel


-- 
Regards
Qiao Nuohan

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


Re: [libvirt] [PATCH v4 1/3] add new virDomainCoreDumpWithFormat API

2014-03-05 Thread Daniel P. Berrange
On Wed, Mar 05, 2014 at 12:48:00PM +, qiaonuo...@cn.fujitsu.com wrote:
 On 03/05/2014 08:42 PM, Daniel P. Berrange wrote:
  On Wed, Mar 05, 2014 at 12:00:59PM +, qiaonuo...@cn.fujitsu.com wrote:
  On 03/04/2014 07:41 PM, Daniel P. Berrange wrote:
  diff --git a/src/test/test_driver.c b/src/test/test_driver.c
  index b724f82..605b0d1 100644
  --- a/src/test/test_driver.c
  +++ b/src/test/test_driver.c
  @@ -2427,9 +2427,10 @@ testDomainRestore(virConnectPtr conn,
 return testDomainRestoreFlags(conn, path, NULL, 0);
 }
 
  -static int testDomainCoreDump(virDomainPtr domain,
  -  const char *to,
  -  unsigned int flags)
  +static int testDomainCoreDumpWithFormat(virDomainPtr domain,
  +const char *to,
  +unsigned int dumpformat,
  +unsigned int flags)
 {
 testConnPtr privconn = domain-conn-privateData;
 int fd = -1;
  @@ -2479,6 +2480,12 @@ static int testDomainCoreDump(virDomainPtr domain,
 }
 }
 
  +if (dumpformat   VIR_DUMP_FORMAT_KDUMP_SNAPPY) {
  +virReportSystemError(errno,
  + _(invalid value of dumpformat: %d), 
  dumpformat);
  +goto cleanup;
  +}
 
  This should be done in the libvirt.c entry point, comparing against
  VIR_DUMP_FORMAT_LAST
 
 
  Is it OK, if I change the check to following one
 
  +/* dump the core of domain to file to */
  +if (virDomainCoreDumpWithFormat(domain, to, dumpformat, flags)  0) {
  +goto cleanup;
  +}
 
  Huh, I don't really see what you mean here.
 
 parameter of testXXX should be used, or it won't go through make. My computer
 output the following message. I just want to check is it OK to use
 virDomainCoreDumpWithFormat here.
 
 cut
 ...
CC qemu/libvirt_driver_qemu_impl_la-qemu_capabilities.lo
CC qemu/libvirt_driver_qemu_impl_la-qemu_command.lo
CC qemu/libvirt_driver_qemu_impl_la-qemu_domain.lo
 cc1: warnings being treated as errors
 test/test_driver.c: In function 'testDomainCoreDumpWithFormat':
 test/test_driver.c:2432: error: unused parameter 'dumpformat' 
 [-Wunused-parameter]

Ok, so for the test driver you should do something like this


  if (dumpformat != VIR_DUMP_FORMAT_RAW) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
);
 return -1;
  }

ie, only accept raw format

The check for format value being out of range should be in libvirt.c

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

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


Re: [libvirt] [PATCH] datatypes: Fix comments

2014-03-05 Thread Ján Tomko
On 03/04/2014 03:58 AM, Michael Chapman wrote:
 - As of commit 2ff4c137, all virGet*() functions in datatypes.c always
   return pointers to new objects. Objects are not cached in a
   per-connection hashtable.
 
 - As of commit 46ec5f85, the conn.lock mutex does not need to be held
   when calling any vir*Dispose() function in datatypes.c (via
   virObjectUnref()).
 
 - Add comments for virGetStream(), virStreamDispose(),
   virGetDomainSnapshot(), virDomainSnapshotDispose().
 
 Signed-off-by: Michael Chapman m...@very.puzzling.org
 ---
  src/datatypes.c | 174 
 
  1 file changed, 99 insertions(+), 75 deletions(-)

ACK

Jan



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] qemu: Reject unsupported tuning in session mode

2014-03-05 Thread Eric Blake
On 03/05/2014 03:37 AM, Martin Kletzander wrote:
 On Tue, Mar 04, 2014 at 02:04:05PM -0700, Eric Blake wrote:
 On 03/04/2014 07:15 AM, Martin Kletzander wrote:
 When domain is started with setting that cannot be done, i.e. those
 that require cgroups, there is no error reported and it succeeds
 without any message whatsoever.

 When setting with API, virsh, an error is reported, but only due to
 the fact that no cgroups are mounted (priv-cgroup == NULL).

 Given the above it seems reasonable to reject such unsupported
 settings.



 I can understand failing the Set commands if we can't change things; but
 since we have a fallback for the Get command even for an offline domain,
 shouldn't we stick to returning the defaults rather than erroring out?

 

 
 If that's really needed, I'll rework it that way (even though it'll
 probably need to get changed back when user cgroups will be
 user-editable), but until then, could we make the error reported now:
 
 $ virsh -c qemu:///session schedinfo dummy
 Scheduler  : Unknown
 error: Requested operation is not valid: cgroup CPU controller is not mounted
 
 changed into:
 
 $ virsh -c qemu:///session schedinfo dummy
 Scheduler  : Unknown
 error: Operation not supported: CPU tuning is not available in session mode

 // I should've added that info into the commit message, I just forgot.

Indeed, trading one error for another nicer one is always safe - and
mentioning it in the commit message highlights that it is an improvement
(we aren't causing an error on any situation where we used to pass).
ACK to this patch, then.

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



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

Re: [libvirt] Python-libvirt in a virtual environment.

2014-03-05 Thread Eric Blake
On 03/05/2014 05:34 AM, Sijo Jose wrote:
 Hi,
 Could you guide me to install libvirt in a virtual environment..?
 OR
 How python-libvirt could be used within a virtual environment after
 installing it, in the system.

Same way as in a non-virtual system.  For example, if your virtual
environment is using Fedora, then 'yum install libvirt-client
libvirt-python', then using it is as simple as:

$ python
 import libvirt
 conn = libvirt.open(...)
... use conn

where the URI you pass to libvirt.open is whatever needed to connect to
the machine where your guests are running, such as qemu://host/system.

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



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

Re: [libvirt] [PATCH v13 01/49] add 'driver' info to used_by

2014-03-05 Thread John Ferlan
Coverity found a memory leak...

...snip...

  int
  virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
 -   const char *name)
 +   const char *drvname,
 +   const char *domname)
  {
 -char *copy = NULL;
 -
 -if (VIR_STRDUP(copy, name)  0)
 +virUsedByInfoPtr copy;
 +if (VIR_ALLOC(copy)  0)
 +return -1;
 +if (VIR_STRDUP(copy-drvname, drvname)  0)
 +return -1;
 +if (VIR_STRDUP(copy-domname, domname)  0)
  return -1;

Either/both VIR_STRDUP() failures of return -1 will leak 'copy'.

John

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


Re: [libvirt] [PATCH 08/10] virt-login-shell: use single instead of double fork

2014-03-05 Thread John Ferlan
Coverity has found an issue (NEGATIVE_RETURNS)

The 'nfdlist' is the culprit.

 diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c
 index 666facf..75a5223 100644
 --- a/tools/virt-login-shell.c
 +++ b/tools/virt-login-shell.c
 @@ -41,24 +41,8 @@
  #include vircommand.h
  #define VIR_FROM_THIS VIR_FROM_NONE
 
 -static ssize_t nfdlist;
 -static int *fdlist;
  static const char *conf_file = SYSCONFDIR /libvirt/virt-login-shell.conf;
 
 -static void virLoginShellFini(virConnectPtr conn, virDomainPtr dom)
 -{
 -size_t i;
 -
 -for (i = 0; i  nfdlist; i++)
 -VIR_FORCE_CLOSE(fdlist[i]);
 -VIR_FREE(fdlist);
 -nfdlist = 0;
 -if (dom)
 -virDomainFree(dom);
 -if (conn)
 -virConnectClose(conn);
 -}
 -
  static int virLoginShellAllowedUser(virConfPtr conf,
  const char *name,
  gid_t *groups)
 @@ -187,7 +171,6 @@ main(int argc, char **argv)
  pid_t cpid;
  int ret = EXIT_FAILURE;
  int status;
 -int status2;
  uid_t uid = getuid();
  gid_t gid = getgid();
  char *name = NULL;
 @@ -201,6 +184,10 @@ main(int argc, char **argv)
  int longindex = -1;
  int ngroups;
  gid_t *groups = NULL;
 +ssize_t nfdlist = 0;
 +int *fdlist = NULL;
 +int openmax;
 +size_t i;
 
  struct option opt[] = {
  {help, no_argument, NULL, 'h'},
 @@ -298,6 +285,13 @@ main(int argc, char **argv)
  }
  }
 
 +openmax = sysconf(_SC_OPEN_MAX);
 +if (openmax  0) {
 +virReportSystemError(errno,  %s,
 + _(sysconf(_SC_OPEN_MAX) failed));
 +goto cleanup;
 +}
 +
  if ((nfdlist = virDomainLxcOpenNamespace(dom, fdlist, 0))  0)
  goto cleanup;


(36) Event negative_return_fn:  Function virDomainLxcOpenNamespace(dom,
fdlist, 0U) returns a negative number. [details]
(37) Event var_assign:  Assigning: signed variable nfdlist =
virDomainLxcOpenNamespace.
(38) Event cond_true:   Condition (nfdlist =
virDomainLxcOpenNamespace(dom, fdlist, 0))  0, taking true branch
Also see events:[negative_returns]


  if (VIR_ALLOC(secmodel)  0)
 @@ -308,76 +302,52 @@ main(int argc, char **argv)
  goto cleanup;
  if (virDomainGetSecurityLabel(dom, seclabel)  0)
  goto cleanup;
 +if (virSetUIDGID(0, 0, NULL, 0)  0)
 +goto cleanup;
 +if (virDomainLxcEnterSecurityLabel(secmodel, seclabel, NULL, 0)  0)
 +goto cleanup;
 +if (nfdlist  0 
 +virDomainLxcEnterNamespace(dom, nfdlist, fdlist, NULL, NULL, 0)  0)
 +goto cleanup;
 +if (virSetUIDGID(uid, gid, groups, ngroups)  0)
 +goto cleanup;
 +if (chdir(homedir)  0) {
 +virReportSystemError(errno, _(Unable to chdir(%s)), homedir);
 +goto cleanup;
 +}
 
 -/* Fork once because we don't want to affect virt-login-shell's
 - * namespace itself.  FIXME: is this necessary?
 - */
 +/* A fork is required to create new process in correct pid namespace.  */
  if ((cpid = virFork())  0)
  goto cleanup;
 
  if (cpid == 0) {
 -pid_t ccpid;
 -
 -int openmax = sysconf(_SC_OPEN_MAX);
 -int fd;
 +int tmpfd;
 
 -if (virSetUIDGID(0, 0, NULL, 0)  0)
 -return EXIT_FAILURE;
 -
 -if (virDomainLxcEnterSecurityLabel(secmodel,
 -   seclabel,
 -   NULL,
 -   0)  0)
 -return EXIT_FAILURE;
 -
 -if (nfdlist  0) {
 -if (virDomainLxcEnterNamespace(dom,
 -   nfdlist,
 -   fdlist,
 -   NULL,
 -   NULL,
 -   0)  0)
 -return EXIT_FAILURE;
 -}
 -
 -ret = virSetUIDGID(uid, gid, groups, ngroups);
 -VIR_FREE(groups);
 -if (ret  0)
 -return EXIT_FAILURE;
 -
 -if (openmax  0) {
 -virReportSystemError(errno,  %s,
 - _(sysconf(_SC_OPEN_MAX) failed));
 -return EXIT_FAILURE;
 -}
 -for (fd = 3; fd  openmax; fd++) {
 -int tmpfd = fd;
 +for (i = 3; i  openmax; i++) {
 +tmpfd = i;
  VIR_MASS_CLOSE(tmpfd);
  }
 -
 -/* A fork is required to create new process in correct pid
 - * namespace.  */
 -if ((ccpid = virFork())  0)
 +if (execv(shargv[0], (char *const*) shargv)  0) {
 +virReportSystemError(errno, _(Unable to exec shell %s),
 + shargv[0]);
  return EXIT_FAILURE;
 -
 -if (ccpid == 0) {
 -if (chdir(homedir)  0) {
 -virReportSystemError(errno, _(Unable to 

Re: [libvirt] [PATCHv8 1/2] qemu: conf Implement domain RBD storage pool support

2014-03-05 Thread Ján Tomko
The subject would IMO be better as:
qemu: support RBD storage pools in 'volume' type disks

On 03/03/2014 05:43 PM, Adam Walters wrote:
 This patch adds a helper function, qemuAddRBDPoolSourceHost, and
 implements the usage of this function to allow RBD storage pools in QEMU
 domain XML.
 
 The new function grabs RBD monitor hosts from the storage pool
 definition and applies them to the domain's disk definition at runtime.
 This function is used by my modifications to qemuTranslateDiskSourcePool
 similar to the function used by the iSCSI code.
 
 My modifications to qemuTranslateDiskSourcePool is based heavily on the
 existing iSCSI code, but modified to support RBD install. It will place
 all relevant information into the domain's disk definition at runtime to
 allow access to a RBD storage pool.
 
 Signed-off-by: Adam Walters a...@pandorasboxen.com
 ---
  src/qemu/qemu_conf.c | 62 
 +++-
  1 file changed, 61 insertions(+), 1 deletion(-)
 
 diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
 index 2c397b0..629ac62 100644
 --- a/src/qemu/qemu_conf.c
 +++ b/src/qemu/qemu_conf.c
 @@ -1251,6 +1251,45 @@ cleanup:
  }
  
  static int
 +qemuAddRBDPoolSourceHost(virDomainDiskDefPtr def,
 + virStoragePoolDefPtr pooldef)
 +{
 +int ret = -1;
 +size_t i = 0;
 +char **tokens = NULL;

Unused variable.

The rest looks good to me.

Jan



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

Re: [libvirt] [PATCHv8 2/2] domain: conf: Fix secret type checking for network volumes

2014-03-05 Thread Ján Tomko
On 03/03/2014 05:43 PM, Adam Walters wrote:
 This patch fixes the secret type checking done in the
 virDomainDiskDefParseXML function. Previously, it would not allow any
 volumes that utilized a secret. This patch is a simple bypass of the
 checking code for volumes.
 
 Signed-off-by: Adam Walters a...@pandorasboxen.com
 ---
  src/conf/domain_conf.c | 9 +++--
  1 file changed, 7 insertions(+), 2 deletions(-)
 
 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
 index 1d5cc14..be6742a 100644
 --- a/src/conf/domain_conf.c
 +++ b/src/conf/domain_conf.c
 @@ -5494,7 +5494,11 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
  cur = cur-next;
  }
  
 -if (auth_secret_usage != -1  auth_secret_usage != 
 expected_secret_usage) {
 +/* Bypass this check for volumes. On libvirtd start, pool definitions 
 are not
 + * yet parsed, and thus we can't expect to have a valid 
 expected_secret_usage.
 + */

The storage driver is initialized before QEMU driver.

When a domain definition with disk type='volume' is parsed, we don't check if
the pool or the volume exists, so we shouldn't check the secret either.


 +if (auth_secret_usage != -1  auth_secret_usage != 
 expected_secret_usage 
 +def-type != VIR_DOMAIN_DISK_TYPE_VOLUME) {
  virReportError(VIR_ERR_INTERNAL_ERROR,
 _(invalid secret type '%s'),
 virSecretUsageTypeTypeToString(auth_secret_usage));

If there is a secret in the pool definition, the secret specified here will
get overwritten in qemuTranslateDiskSourcePoolAuth. (which is where the secret
type check should be IMO)

 @@ -18442,7 +18446,8 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
  if (!disk-src || disk-type == VIR_DOMAIN_DISK_TYPE_NETWORK ||
  (disk-type == VIR_DOMAIN_DISK_TYPE_VOLUME 
   disk-srcpool 
 - disk-srcpool-mode == VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT))
 + (disk-srcpool-mode == VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT ||
 + disk-srcpool-actualtype == VIR_DOMAIN_DISK_TYPE_NETWORK)))

This changes the behavior for ISCSI volumees with MODE_HOST or MODE_DEFAULT.
I think you need to check pooltype, since the default for iscsi (HOST) is
different for rbd (DIRECT)

  return 0;
  
  if (iter(disk, disk-src, 0, opaque)  0)
 

Jan



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

[libvirt] [PATCH] qemu: monitor: Provide more information in generic block job error

2014-03-05 Thread Peter Krempa
The qemuMonitorJSONBlockJob handles a few errors internally. If qemu
returns a different error we would report a rather unhelpful message:

 $ virsh blockpull gluster-job vda --base /dev/null
 error: internal error: Unexpected error

As the actual message from qemu contains a bit more info, let's use it
to report something a little more useful:

 $ virsh blockpull gluster-job vda --base /dev/null
 error: internal error: Unexpected error: (GenericError) 'Base '/dev/null' not 
found'
---
 src/qemu/qemu_monitor_json.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 9a5b812..ee3ae15 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3678,8 +3678,12 @@ qemuMonitorJSONBlockJob(qemuMonitorPtr mon,
 virReportError(VIR_ERR_OPERATION_INVALID,
_(Command '%s' is not found), cmd_name);
 } else {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(Unexpected error));
+virJSONValuePtr error = virJSONValueObjectGet(reply, error);
+
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Unexpected error: (%s) '%s'),
+   NULLSTR(virJSONValueObjectGetString(error, 
class)),
+   NULLSTR(virJSONValueObjectGetString(error, 
desc)));
 }
 }

-- 
1.9.0

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


Re: [libvirt] [PATCH 3/7] Move dtrace probe macros into separate header file

2014-03-05 Thread John Ferlan


On 03/03/2014 02:18 PM, Daniel P. Berrange wrote:
 The dtrace probe macros rely on the logging API. We can't make
 the internal.h header include the virlog.h header though since
 that'd be a circular include. Instead simply split the dtrace
 probes into their own header file, since there's no compelling
 reason for them to be in the main internal.h header.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  daemon/remote.c  |   1 +
  src/internal.h   |  74 
  src/qemu/qemu_monitor.c  |   1 +
  src/qemu/qemu_monitor_json.c |   1 +
  src/qemu/qemu_monitor_text.c |   1 +
  src/rpc/virkeepalive.c   |   1 +
  src/rpc/virnetclient.c   |   1 +
  src/rpc/virnetserverclient.c |   1 +
  src/rpc/virnetsocket.c   |   1 +
  src/rpc/virnettlscontext.c   |   1 +
  src/util/vireventpoll.c  |   1 +
  src/util/virobject.c |   1 +
  src/util/virprobe.h  | 100 
 +++
  13 files changed, 111 insertions(+), 74 deletions(-)
  create mode 100644 src/util/virprobe.h
 

...snip...

 --- /dev/null
 +++ b/src/util/virprobe.h
 @@ -0,0 +1,100 @@
 +/*
 + * virlog.h: internal logging and debugging

NIT:  virprobe.h


 + *
 + * Copyright (C) 2006-2008, 2011-2012 Red Hat, Inc.
 + *

Should this be just 2014 or the range?

John

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


Re: [libvirt] [PATCH 5/7] Add virLogSource variables to all source files

2014-03-05 Thread John Ferlan


On 03/03/2014 02:18 PM, Daniel P. Berrange wrote:
 Any source file which calls the logging APIs now needs
 to have a VIR_LOG_INIT(source.name) declaration at
 the start of the file. This provides a static variable
 of the virLogSource type.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---

...snip...

I found just one typo - I assume this is added anywhere a VIR_FROM_THIS
was found (although I didn't check :-))


 diff --git a/src/locking/lock_daemon_config.c 
 b/src/locking/lock_daemon_config.c
 index 8e632f5..c7d9d97 100644
 --- a/src/locking/lock_daemon_config.c
 +++ b/src/locking/lock_daemon_config.c
 @@ -35,6 +35,8 @@
  
  #define VIR_FROM_THIS VIR_FROM_CONF
  
 +VIR_LOG_INIT(locking.lock_daemon_confijg);
 +

s/lock_daemon_confijg/lock_daemon_config

  
  /* A helper function used by each of the following macros.  */
  static int

ACK

John

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


Re: [libvirt] [PATCH 5/7] Add virLogSource variables to all source files

2014-03-05 Thread Daniel P. Berrange
On Wed, Mar 05, 2014 at 10:09:55AM -0500, John Ferlan wrote:
 
 
 On 03/03/2014 02:18 PM, Daniel P. Berrange wrote:
  Any source file which calls the logging APIs now needs
  to have a VIR_LOG_INIT(source.name) declaration at
  the start of the file. This provides a static variable
  of the virLogSource type.
  
  Signed-off-by: Daniel P. Berrange berra...@redhat.com
  ---
 
 ...snip...
 
 I found just one typo - I assume this is added anywhere a VIR_FROM_THIS
 was found (although I didn't check :-))

Actually anywhere a VIR_DEBUG or equiv statement is set. Fortunately
we will get a compile error if i missed any...

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

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


[libvirt] [RFC] support memory reserved feature and optimize mlock guest memory propose

2014-03-05 Thread Zhanghailiang
Hi all:
Currently, we use cgroup(memory) to support memory QoS on KVM platform, and use 
mlock on qemu to support memory reserved.
The mlock seems to be not appropriate.
Now qemu mlock memory in the main thread, which would lock iothread 
(qemu_mutex_lock_iothread), if the memory size is large, that will consume lots 
of time.
It means whenever we want to set a new 'mlock', the VM would be blocked for a 
while.
Here is my optimization:
  1. Add a global variable (lock_ram_size) to save the value of memory 
reserved;
  2. Add a qmp commond set_ram_minguarantee to change lock_ram_size;
  3. Create a new thread to mlock(lock_ram_zie), while is waked up by the 
set_ram_minguarantee qmp command.
Flow chart:
   main funciton   qmp command set_ram_minguarantee
 |   |
 |   |
create mlock thread   change value of lock_ram_size
 |   |
 |   |
|--thread wait-wake up mlock thread
||
||
||
|---mlock(lock_ram_zie)

We have tested this demo a few days, it seems to be worked well.
But we are not sure is there any other problems , if the main thread and mlock 
thread access one memory zone at one time without a mutex lock.
Is it workable?Or Is there any other idea to support memory reserved ?

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

[libvirt] [PATCH] Fix missing char dev lock path case in configure

2014-03-05 Thread Roman Bogorodskiy
configure check for character devices lock path calls
AC_DEFINE_UNQUOTED for VIR_CHRDEV_LOCK_FILE_PATH even if
$with_chrdev_lock_files = no.

So the locking code in conf/virchrdev.c:

 #ifdef VIR_CHRDEV_LOCK_FILE_PATH

is compiled in even if it shouldn't, because VIR_CHRDEV_LOCK_FILE_PATH
is defined as no, so it tries to create lock files with strange
lock path like 'no/LCK..'.

Fix that by calling AC_DEFINE_UNQUOTED only if $with_chrdev_lock_files
is not 'no'.
---
 configure.ac | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index a9339ce..62b74c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1401,8 +1401,10 @@ if test $with_chrdev_lock_files != no; then
 AC_MSG_ERROR([You must specify path for the lock files on this
 platform])
   fi
-  AC_DEFINE_UNQUOTED([VIR_CHRDEV_LOCK_FILE_PATH], $with_chrdev_lock_files,
-  [path to directory containing UUCP device lock files])
+  if test $with_chrdev_lock_files != no; then
+AC_DEFINE_UNQUOTED([VIR_CHRDEV_LOCK_FILE_PATH], $with_chrdev_lock_files,
+   [path to directory containing UUCP device lock files])
+  fi
 fi
 AM_CONDITIONAL([VIR_CHRDEV_LOCK_FILE_PATH], [test $with_chrdev_lock_files != 
no])
 
-- 
1.8.4.2

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


Re: [libvirt] [PATCH] Fix missing char dev lock path case in configure

2014-03-05 Thread Daniel P. Berrange
On Wed, Mar 05, 2014 at 07:34:11PM +0400, Roman Bogorodskiy wrote:
 configure check for character devices lock path calls
 AC_DEFINE_UNQUOTED for VIR_CHRDEV_LOCK_FILE_PATH even if
 $with_chrdev_lock_files = no.
 
 So the locking code in conf/virchrdev.c:
 
  #ifdef VIR_CHRDEV_LOCK_FILE_PATH
 
 is compiled in even if it shouldn't, because VIR_CHRDEV_LOCK_FILE_PATH
 is defined as no, so it tries to create lock files with strange
 lock path like 'no/LCK..'.
 
 Fix that by calling AC_DEFINE_UNQUOTED only if $with_chrdev_lock_files
 is not 'no'.
 ---
  configure.ac | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)
 
 diff --git a/configure.ac b/configure.ac
 index a9339ce..62b74c5 100644
 --- a/configure.ac
 +++ b/configure.ac
 @@ -1401,8 +1401,10 @@ if test $with_chrdev_lock_files != no; then
  AC_MSG_ERROR([You must specify path for the lock files on this
  platform])
fi
 -  AC_DEFINE_UNQUOTED([VIR_CHRDEV_LOCK_FILE_PATH], $with_chrdev_lock_files,
 -  [path to directory containing UUCP device lock files])
 +  if test $with_chrdev_lock_files != no; then
 +AC_DEFINE_UNQUOTED([VIR_CHRDEV_LOCK_FILE_PATH], 
 $with_chrdev_lock_files,
 +   [path to directory containing UUCP device lock files])
 +  fi
  fi
  AM_CONDITIONAL([VIR_CHRDEV_LOCK_FILE_PATH], [test $with_chrdev_lock_files 
 != no])

ACK

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

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


Re: [libvirt] [PATCH] qemu: monitor: Provide more information in generic block job error

2014-03-05 Thread Eric Blake
On 03/05/2014 07:15 AM, Peter Krempa wrote:
 The qemuMonitorJSONBlockJob handles a few errors internally. If qemu
 returns a different error we would report a rather unhelpful message:
 
  $ virsh blockpull gluster-job vda --base /dev/null
  error: internal error: Unexpected error
 
 As the actual message from qemu contains a bit more info, let's use it
 to report something a little more useful:
 
  $ virsh blockpull gluster-job vda --base /dev/null
  error: internal error: Unexpected error: (GenericError) 'Base '/dev/null' 
 not found'

The fact that we're reporting an internal error instead of catching it
up front and avoiding the monitor command in the first place is a bit
worrisome (ideally, we should be tracking the backing chain ourselves,
and have some clue that qemu can't succeed because the input the user
gave was not part of the chain).  But fixing _that_ is a bigger task,
and meanwhile, this patch definitely improves the error quality by
reflecting qemu's complaints.

For that matter, the fact that it is so easy to trigger an internal
error is a bit worrisome, but I don't know if we have a better error
category to use.

 ---
  src/qemu/qemu_monitor_json.c | 8 ++--
  1 file changed, 6 insertions(+), 2 deletions(-)

ACK.

 
 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
 index 9a5b812..ee3ae15 100644
 --- a/src/qemu/qemu_monitor_json.c
 +++ b/src/qemu/qemu_monitor_json.c
 @@ -3678,8 +3678,12 @@ qemuMonitorJSONBlockJob(qemuMonitorPtr mon,
  virReportError(VIR_ERR_OPERATION_INVALID,
 _(Command '%s' is not found), cmd_name);
  } else {
 -virReportError(VIR_ERR_INTERNAL_ERROR, %s,
 -   _(Unexpected error));
 +virJSONValuePtr error = virJSONValueObjectGet(reply, error);
 +
 +virReportError(VIR_ERR_INTERNAL_ERROR,
 +   _(Unexpected error: (%s) '%s'),
 +   NULLSTR(virJSONValueObjectGetString(error, 
 class)),
 +   NULLSTR(virJSONValueObjectGetString(error, 
 desc)));
  }
  }
 

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



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

Re: [libvirt] [PATCH v3 2/2] query-command-line-options: query all the options in qemu-options.hx

2014-03-05 Thread Eric Blake
On 03/04/2014 11:40 PM, Amos Kong wrote:

 but the docs imply that I should now see:

 {parameters: [], option: smbios, argument: true}
 
 I really got : {parameters: [], option: smbios, argument: true}
 
 (I was testing with latest qemu upstream + my patches, attached the
 output file)

Hmm, maybe I was testing a stale binary.  Let me try re-running tests on
my end - I recently changed my choice of configure arguments to speed up
build time by building fewer binaries, so maybe I tested on a binary
that my configure arguments no longer rebuild.

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



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

Re: [libvirt] [PATCH] qemu: monitor: Provide more information in generic block job error

2014-03-05 Thread Peter Krempa
On 03/05/14 16:49, Eric Blake wrote:
 On 03/05/2014 07:15 AM, Peter Krempa wrote:
 The qemuMonitorJSONBlockJob handles a few errors internally. If qemu
 returns a different error we would report a rather unhelpful message:

  $ virsh blockpull gluster-job vda --base /dev/null
  error: internal error: Unexpected error

 As the actual message from qemu contains a bit more info, let's use it
 to report something a little more useful:

  $ virsh blockpull gluster-job vda --base /dev/null
  error: internal error: Unexpected error: (GenericError) 'Base '/dev/null' 
 not found'
 
 The fact that we're reporting an internal error instead of catching it
 up front and avoiding the monitor command in the first place is a bit
 worrisome (ideally, we should be tracking the backing chain ourselves,
 and have some clue that qemu can't succeed because the input the user
 gave was not part of the chain).  But fixing _that_ is a bigger task,
 and meanwhile, this patch definitely improves the error quality by
 reflecting qemu's complaints.
 
 For that matter, the fact that it is so easy to trigger an internal
 error is a bit worrisome, but I don't know if we have a better error
 category to use.
 
 ---
  src/qemu/qemu_monitor_json.c | 8 ++--
  1 file changed, 6 insertions(+), 2 deletions(-)
 
 ACK.
 

Pushed; Thanks.

Peter




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] libxl: add migration support

2014-03-05 Thread Jim Fehlig
This patch adds initial migration support to the libxl driver,
using the VIR_DRV_FEATURE_MIGRATION_PARAMS family of migration
functions.

Signed-off-by: Jim Fehlig jfeh...@suse.com
---

A few small fixes found while reviewing/testing the patch.

V2:
- Change name of local variable in libxlDoMigrateSend from 'live'
  to 'xl_flags'.
- Fail early in libxlDomainMigrateBegin3Params if domain is inactive

 po/POTFILES.in  |   1 +
 src/Makefile.am |   3 +-
 src/libxl/libxl_conf.h  |   6 +
 src/libxl/libxl_domain.h|   1 +
 src/libxl/libxl_driver.c| 225 +
 src/libxl/libxl_migration.c | 579 
 src/libxl/libxl_migration.h |  78 ++
 7 files changed, 892 insertions(+), 1 deletion(-)

diff --git a/po/POTFILES.in b/po/POTFILES.in
index c565771..36ac669 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -74,6 +74,7 @@ src/lxc/lxc_process.c
 src/libxl/libxl_domain.c
 src/libxl/libxl_driver.c
 src/libxl/libxl_conf.c
+src/libxl/libxl_migration.c
 src/network/bridge_driver.c
 src/network/bridge_driver_linux.c
 src/node_device/node_device_driver.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 6ef32ee..929b304 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -698,7 +698,8 @@ XENAPI_DRIVER_SOURCES = 
\
 LIBXL_DRIVER_SOURCES = \
libxl/libxl_conf.c libxl/libxl_conf.h   \
libxl/libxl_domain.c libxl/libxl_domain.h   \
-   libxl/libxl_driver.c libxl/libxl_driver.h
+   libxl/libxl_driver.c libxl/libxl_driver.h   \
+   libxl/libxl_migration.c libxl/libxl_migration.h
 
 UML_DRIVER_SOURCES =   \
uml/uml_conf.c uml/uml_conf.h   \
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index 6584933..0ad444d 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -42,6 +42,9 @@
 # define LIBXL_VNC_PORT_MIN  5900
 # define LIBXL_VNC_PORT_MAX  65535
 
+# define LIBXL_MIGRATION_PORT_MIN  49152
+# define LIBXL_MIGRATION_PORT_MAX  49216
+
 # define LIBXL_CONFIG_DIR SYSCONFDIR /libvirt/libxl
 # define LIBXL_AUTOSTART_DIR LIBXL_CONFIG_DIR /autostart
 # define LIBXL_STATE_DIR LOCALSTATEDIR /run/libvirt/libxl
@@ -113,6 +116,9 @@ struct _libxlDriverPrivate {
 /* Immutable pointer, self-locking APIs */
 virPortAllocatorPtr reservedVNCPorts;
 
+/* Immutable pointer, self-locking APIs */
+virPortAllocatorPtr migrationPorts;
+
 /* Immutable pointer, lockless APIs*/
 virSysinfoDefPtr hostsysinfo;
 };
diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h
index 979ce2a..9d48049 100644
--- a/src/libxl/libxl_domain.h
+++ b/src/libxl/libxl_domain.h
@@ -69,6 +69,7 @@ struct _libxlDomainObjPrivate {
 virChrdevsPtr devs;
 libxl_evgen_domain_death *deathW;
 libxlDriverPrivatePtr driver;
+unsigned short migrationPort;
 
 struct libxlDomainJobObj job;
 };
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index c6722d9..eb4dbec 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -45,6 +45,7 @@
 #include libxl_domain.h
 #include libxl_driver.h
 #include libxl_conf.h
+#include libxl_migration.h
 #include xen_xm.h
 #include virtypedparam.h
 #include viruri.h
@@ -194,6 +195,7 @@ libxlStateCleanup(void)
 virObjectUnref(libxl_driver-xmlopt);
 virObjectUnref(libxl_driver-domains);
 virObjectUnref(libxl_driver-reservedVNCPorts);
+virObjectUnref(libxl_driver-migrationPorts);
 
 virObjectEventStateFree(libxl_driver-domainEventState);
 virSysinfoDefFree(libxl_driver-hostsysinfo);
@@ -266,6 +268,13 @@ libxlStateInitialize(bool privileged,
   LIBXL_VNC_PORT_MAX)))
 goto error;
 
+/* Allocate bitmap for migration port reservation */
+if (!(libxl_driver-migrationPorts =
+  virPortAllocatorNew(_(migration),
+  LIBXL_MIGRATION_PORT_MIN,
+  LIBXL_MIGRATION_PORT_MAX)))
+goto error;
+
 if (!(libxl_driver-domains = virDomainObjListNew()))
 goto error;
 
@@ -3852,12 +3861,223 @@ libxlConnectSupportsFeature(virConnectPtr conn, int 
feature)
 
 switch (feature) {
 case VIR_DRV_FEATURE_TYPED_PARAM_STRING:
+case VIR_DRV_FEATURE_MIGRATION_PARAMS:
 return 1;
 default:
 return 0;
 }
 }
 
+static char *
+libxlDomainMigrateBegin3Params(virDomainPtr domain,
+   virTypedParameterPtr params,
+   int nparams,
+   char **cookieout ATTRIBUTE_UNUSED,
+   int *cookieoutlen ATTRIBUTE_UNUSED,
+   unsigned int flags)
+{
+const char *xmlin = NULL;
+const char *dname = NULL;
+virDomainObjPtr vm = NULL;
+
+

[libvirt] [PATCH 2/4] Convert lock driver plugins to use new crypto APIs

2014-03-05 Thread Daniel P. Berrange
Conver the sanlock and lockd lock driver plugins over to use
the new virCryptoHashString APIs instead of having their own
duplicated code.

Signed-off-by: Daniel P. Berrange berra...@redhat.com
---
 src/locking/lock_driver_lockd.c   | 32 ++---
 src/locking/lock_driver_sanlock.c | 42 ++-
 2 files changed, 12 insertions(+), 62 deletions(-)

diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index f3b9467..1b92d68 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -24,6 +24,7 @@
 #include lock_driver.h
 #include virconf.h
 #include viralloc.h
+#include vircrypto.h
 #include virlog.h
 #include viruuid.h
 #include virfile.h
@@ -31,7 +32,6 @@
 #include rpc/virnetclient.h
 #include lock_protocol.h
 #include configmake.h
-#include sha256.h
 #include virstring.h
 
 #define VIR_FROM_THIS VIR_FROM_LOCKING
@@ -505,34 +505,6 @@ static int virLockManagerLockDaemonNew(virLockManagerPtr 
lock,
 }
 
 
-static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
-'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
-
-static char *virLockManagerLockDaemonDiskLeaseName(const char *path)
-{
-unsigned char buf[SHA256_DIGEST_SIZE];
-char *ret;
-size_t i;
-
-if (!(sha256_buffer(path, strlen(path), buf))) {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(Unable to compute sha256 checksum));
-return NULL;
-}
-
-if (VIR_ALLOC_N(ret, (SHA256_DIGEST_SIZE * 2) + 1)  0)
-return NULL;
-
-for (i = 0; i  SHA256_DIGEST_SIZE; i++) {
-ret[i*2] = hex[(buf[i]  4)  0xf];
-ret[(i*2)+1] = hex[buf[i]  0xf];
-}
-ret[(SHA256_DIGEST_SIZE * 2) + 1] = '\0';
-
-return ret;
-}
-
-
 static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
unsigned int type,
const char *name,
@@ -605,7 +577,7 @@ static int 
virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
 if (driver-fileLockSpaceDir) {
 if (VIR_STRDUP(newLockspace, driver-fileLockSpaceDir)  0)
 goto error;
-if (!(newName = virLockManagerLockDaemonDiskLeaseName(name)))
+if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, newName)  
0)
 goto error;
 autoCreate = true;
 VIR_DEBUG(Using indirect lease %s for %s, newName, name);
diff --git a/src/locking/lock_driver_sanlock.c 
b/src/locking/lock_driver_sanlock.c
index f11f3c6..0c87048 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -40,8 +40,8 @@
 #include virlog.h
 #include virerror.h
 #include viralloc.h
+#include vircrypto.h
 #include virfile.h
-#include md5.h
 #include virconf.h
 #include virstring.h
 
@@ -509,36 +509,6 @@ static void virLockManagerSanlockFree(virLockManagerPtr 
lock)
 }
 
 
-static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
-'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
-
-static int virLockManagerSanlockDiskLeaseName(const char *path,
-  char *str,
-  size_t strbuflen)
-{
-unsigned char buf[MD5_DIGEST_SIZE];
-size_t i;
-
-if (strbuflen  ((MD5_DIGEST_SIZE * 2) + 1)) {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(String length too small to store md5 checksum));
-return -1;
-}
-
-if (!(md5_buffer(path, strlen(path), buf))) {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(Unable to compute md5 checksum));
-return -1;
-}
-
-for (i = 0; i  MD5_DIGEST_SIZE; i++) {
-str[i*2] = hex[(buf[i]  4)  0xf];
-str[(i*2)+1] = hex[buf[i]  0xf];
-}
-str[(MD5_DIGEST_SIZE*2)+1] = '\0';
-return 0;
-}
-
 static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
  const char *name,
  size_t nparams,
@@ -606,6 +576,7 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr 
lock,
 int ret = -1;
 struct sanlk_resource *res = NULL;
 char *path = NULL;
+char *hash = NULL;
 
 if (nparams) {
 virReportError(VIR_ERR_INTERNAL_ERROR, %s,
@@ -618,8 +589,14 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr 
lock,
 
 res-flags = shared ? SANLK_RES_SHARED : 0;
 res-num_disks = 1;
-if (virLockManagerSanlockDiskLeaseName(name, res-name, SANLK_NAME_LEN)  
0)
+if (virCryptoHashString(VIR_CRYPTO_HASH_MD5, name, hash)  0)
+goto cleanup;
+if (!virStrcpy(res-name, hash, SANLK_NAME_LEN)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(MD5 hash '%s' unexpectedly larger than %d 
characters),
+   hash, (SANLK_NAME_LEN - 

[libvirt] [PATCH 0/4] Add caching of QEMU probed capabilities

2014-03-05 Thread Daniel P. Berrange
Probing capabilities takes 200-300ms per binary and we have as many
as 26 binaries. This noticably slows down libvirtd startup. It does
not look like performance of probing QEMU can be improved, so this
series introduces caching of the capabilities information. So the
first time libvirtd starts it'll be slow, but thereafter it is fast.
The cache is invalidated any time the QEMU binary timestamp changes
or the libvirtd binary or driver module timestamp changes.

Daniel P. Berrange (4):
  Add helper APIs for generating cryptographic hashes
  Convert lock driver plugins to use new crypto APIs
  Cache result of QEMU capabilities extraction
  Refresh qemu capabilities if libvirtd binary changes

 .gitignore|   1 +
 daemon/libvirtd.c |   2 +
 include/libvirt/virterror.h   |   1 +
 po/POTFILES.in|   1 +
 src/Makefile.am   |   1 +
 src/driver.c  |   2 +
 src/libvirt_private.syms  |   6 +
 src/locking/lock_driver_lockd.c   |  32 +--
 src/locking/lock_driver_sanlock.c |  42 +---
 src/qemu/qemu_capabilities.c  | 418 +-
 src/qemu/qemu_capabilities.h  |   2 +
 src/qemu/qemu_driver.c|   1 +
 src/util/vircrypto.c  |  80 
 src/util/vircrypto.h  |  40 
 src/util/virerror.c   |   1 +
 src/util/virutil.c|  23 +++
 src/util/virutil.h|   4 +
 tests/Makefile.am |   5 +
 tests/vircryptotest.c |  90 
 19 files changed, 682 insertions(+), 70 deletions(-)
 create mode 100644 src/util/vircrypto.c
 create mode 100644 src/util/vircrypto.h
 create mode 100644 tests/vircryptotest.c

-- 
1.8.5.3

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


[libvirt] [PATCH 3/4] Cache result of QEMU capabilities extraction

2014-03-05 Thread Daniel P. Berrange
Extracting capabilities from QEMU takes a notable amount of time
when all QEMU binaries are installed. Each system emulator
needs about 200-300ms multiplied by 26 binaries == ~5-8 seconds.

This change causes the QEMU driver to save an XML file containing
the content of the virQEMUCaps object instance in the cache
dir eg /var/cache/libvirt/qemu/capabilities/$SHA256(binarypath).xml
or $HOME/.cache/libvirt/qemu/cache/capabilities/$SHA256(binarypath).xml

We attempt to load this and only if it fails, do we fallback to
probing the QEMU binary. The timestamp of the file is compared to
the timestamp of the QEMU binary and discarded if the QEMU binary
is newer.

Signed-off-by: Daniel P. Berrange berra...@redhat.com
---
 src/qemu/qemu_capabilities.c | 412 ++-
 src/qemu/qemu_capabilities.h |   2 +
 src/qemu/qemu_driver.c   |   1 +
 3 files changed, 407 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index cae25e0..e3ed960 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -25,6 +25,7 @@
 
 #include qemu_capabilities.h
 #include viralloc.h
+#include vircrypto.h
 #include virlog.h
 #include virerror.h
 #include virfile.h
@@ -44,6 +45,7 @@
 #include unistd.h
 #include sys/wait.h
 #include stdarg.h
+#include utime.h
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -281,7 +283,7 @@ struct _virQEMUCapsCache {
 virMutex lock;
 virHashTablePtr binaries;
 char *libDir;
-char *runDir;
+char *cacheDir;
 uid_t runUid;
 gid_t runGid;
 };
@@ -2339,6 +2341,386 @@ int virQEMUCapsProbeQMP(virQEMUCapsPtr qemuCaps,
 }
 
 
+/*
+ * Parsing a doc that looks like
+ *
+ * qemuCaps
+ *   usedQMP/
+ *   flag name='foo'/
+ *   flag name='bar'/
+ *   ...
+ *   cpu name=pentium3/
+ *   ...
+ *   machine name=pc-1.0 alias=pc maxCpus=4/
+ *   ...
+ * /qemuCaps
+ */
+static int
+virQEMUCapsLoadCache(virQEMUCapsPtr qemuCaps, const char *filename)
+{
+xmlDocPtr doc = NULL;
+int ret = -1;
+size_t i;
+int n;
+xmlNodePtr *nodes = NULL;
+xmlXPathContextPtr ctxt = NULL;
+char *str;
+
+if (!(doc = virXMLParseFile(filename)))
+goto cleanup;
+
+if (!(ctxt = xmlXPathNewContext(doc))) {
+virReportOOMError();
+goto cleanup;
+}
+
+ctxt-node = xmlDocGetRootElement(doc);
+
+if (STRNEQ((const char *)ctxt-node-name, qemuCaps)) {
+virReportError(VIR_ERR_XML_ERROR,
+   _(unexpected root element %s, 
+ expecting qemuCaps),
+   ctxt-node-name);
+goto cleanup;
+}
+
+qemuCaps-usedQMP = virXPathBoolean(count(.//usedQMP)  0,
+ctxt)  0;
+
+if ((n = virXPathNodeSet(.//flag, ctxt, nodes))  0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(failed to parse qemu capabilities flags));
+goto cleanup;
+}
+VIR_DEBUG(Got flags %d, n);
+if (n  0) {
+for (i = 0; i  n; i++) {
+int flag;
+if (!(str = virXMLPropString(nodes[i], name))) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(missing flag name in QEMU capabilities 
cache));
+goto cleanup;
+}
+flag = virQEMUCapsTypeFromString(str);
+if (flag  0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Unknown qemu capabilities flag %s), str);
+VIR_FREE(str);
+goto cleanup;
+}
+VIR_FREE(str);
+virQEMUCapsSet(qemuCaps, flag);
+}
+}
+VIR_FREE(nodes);
+
+if (virXPathUInt(string(.//version), ctxt, qemuCaps-version)  0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(missing version in QEMU capabilities cache));
+goto cleanup;
+}
+
+if (virXPathUInt(string(.//kvmVersion), ctxt, qemuCaps-kvmVersion)  
0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(missing version in QEMU capabilities cache));
+goto cleanup;
+}
+
+if (!(str = virXPathString(string(.//arch), ctxt))) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(missing arch in QEMU capabilities cache));
+goto cleanup;
+}
+if (!(qemuCaps-arch = virArchFromString(str))) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(unknown arch %s in QEMU capabilities cache), str);
+goto cleanup;
+}
+
+if ((n = virXPathNodeSet(.//cpu, ctxt, nodes))  0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(failed to parse qemu capabilities cpus));
+goto cleanup;
+}
+if (n  0) {
+qemuCaps-ncpuDefinitions = n;
+if (VIR_ALLOC_N(qemuCaps-cpuDefinitions,
+qemuCaps-ncpuDefinitions)  0)
+ 

[libvirt] [PATCH 1/4] Add helper APIs for generating cryptographic hashes

2014-03-05 Thread Daniel P. Berrange
GNULIB provides APIs for calculating md5 and sha256 hashes,
but these APIs only return you raw byte arrays. Most users
in libvirt want the hash in printable string format. Add
some helper APIs in util/vircrypto.{c,h} for doing this.

Signed-off-by: Daniel P. Berrange berra...@redhat.com
---
 .gitignore  |  1 +
 include/libvirt/virterror.h |  1 +
 po/POTFILES.in  |  1 +
 src/Makefile.am |  1 +
 src/libvirt_private.syms|  4 ++
 src/util/vircrypto.c| 80 
 src/util/vircrypto.h| 40 
 src/util/virerror.c |  1 +
 tests/Makefile.am   |  5 +++
 tests/vircryptotest.c   | 90 +
 10 files changed, 224 insertions(+)
 create mode 100644 src/util/vircrypto.c
 create mode 100644 src/util/vircrypto.h
 create mode 100644 tests/vircryptotest.c

diff --git a/.gitignore b/.gitignore
index cb60734..1973640 100644
--- a/.gitignore
+++ b/.gitignore
@@ -198,6 +198,7 @@
 /tests/virbuftest
 /tests/vircapstest
 /tests/vircgrouptest
+/tests/vircryptotest
 /tests/virdbustest
 /tests/virdrivermoduletest
 /tests/virendiantest
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index cc6569d..495c121 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -121,6 +121,7 @@ typedef enum {
 VIR_FROM_ACCESS = 55,   /* Error from access control manager */
 VIR_FROM_SYSTEMD = 56,  /* Error from systemd code */
 VIR_FROM_BHYVE = 57,/* Error from bhyve driver */
+VIR_FROM_CRYPTO = 58,   /* Error from crypto code */
 
 # ifdef VIR_ENUM_SENTINELS
 VIR_ERR_DOMAIN_LAST
diff --git a/po/POTFILES.in b/po/POTFILES.in
index bcc0ee0..a8a5975 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -158,6 +158,7 @@ src/util/vircgroup.c
 src/util/virclosecallbacks.c
 src/util/vircommand.c
 src/util/virconf.c
+src/util/vircrypto.c
 src/util/virdbus.c
 src/util/virdnsmasq.c
 src/util/vireventpoll.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 25d0370..4bc2df4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -93,6 +93,7 @@ UTIL_SOURCES =
\
util/virclosecallbacks.c util/virclosecallbacks.h   
\
util/vircommand.c util/vircommand.h \
util/virconf.c util/virconf.h   \
+   util/vircrypto.c util/vircrypto.h   \
util/virdbus.c util/virdbus.h util/virdbuspriv.h\
util/virdnsmasq.c util/virdnsmasq.h \
util/virebtables.c util/virebtables.h   \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 80070c5..00e3d9c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1149,6 +1149,10 @@ virConfWriteFile;
 virConfWriteMem;
 
 
+# util/vircrypto.h
+virCryptoHashString;
+
+
 # util/virdbus.h
 virDBusCallMethod;
 virDBusCloseSystemBus;
diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c
new file mode 100644
index 000..bd00644
--- /dev/null
+++ b/src/util/vircrypto.c
@@ -0,0 +1,80 @@
+/*
+ * vircrypto.c: cryptographic helper APIs
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * http://www.gnu.org/licenses/.
+ */
+
+#include config.h
+
+#include vircrypto.h
+#include virerror.h
+#include viralloc.h
+
+#include md5.h
+#include sha256.h
+
+#define VIR_FROM_THIS VIR_FROM_CRYPTO
+
+static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
+'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
+struct virHashInfo {
+void *(*func)(const char *buf, size_t len, void *res);
+size_t hashlen;
+} hashinfo[] = {
+{ md5_buffer, MD5_DIGEST_SIZE },
+{ sha256_buffer, SHA256_DIGEST_SIZE },
+};
+
+#define VIR_CRYPTO_LARGEST_DIGEST_SIZE SHA256_DIGEST_SIZE
+
+verify(ARRAY_CARDINALITY(hashinfo) == VIR_CRYPTO_HASH_LAST);
+
+int
+virCryptoHashString(virCryptoHash hash,
+const char *input,
+char **output)
+{
+unsigned char buf[VIR_CRYPTO_LARGEST_DIGEST_SIZE];
+size_t hashstrlen;
+size_t i;
+
+if (hash = VIR_CRYPTO_HASH_LAST) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _(Unknown crypto hash 

[libvirt] [PATCH 4/4] Refresh qemu capabilities if libvirtd binary changes

2014-03-05 Thread Daniel P. Berrange
Currently the QEMU capabilities cache files on disk are only
invalidated if the QEMU binary changes. New versions of libvirt,
however, may want to extract more information from existing
binaries. Thus we must take into account modification time of
the libvirtd daemon and/or any loadable driver modules when
checking cache validity

Signed-off-by: Daniel P. Berrange berra...@redhat.com
---
 daemon/libvirtd.c|  2 ++
 src/driver.c |  2 ++
 src/libvirt_private.syms |  2 ++
 src/qemu/qemu_capabilities.c | 24 +++-
 src/util/virutil.c   | 23 +++
 src/util/virutil.h   |  4 
 6 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 72f0e81..d8226a4 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1152,6 +1152,8 @@ int main(int argc, char **argv) {
 exit(EXIT_FAILURE);
 }
 
+virUpdateSelfLastModified(argv[0]);
+
 if (strstr(argv[0], lt-libvirtd) ||
 strstr(argv[0], /daemon/.libs/libvirtd)) {
 char *tmp = strrchr(argv[0], '/');
diff --git a/src/driver.c b/src/driver.c
index ab2a253..2acf39c 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -74,6 +74,8 @@ virDriverLoadModule(const char *name)
 goto cleanup;
 }
 
+virUpdateSelfLastModified(modfile);
+
 handle = dlopen(modfile, RTLD_NOW | RTLD_GLOBAL);
 if (!handle) {
 VIR_ERROR(_(failed to load module %s %s), modfile, dlerror());
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 00e3d9c..82a8918 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1954,6 +1954,7 @@ virGetGroupID;
 virGetGroupList;
 virGetGroupName;
 virGetHostname;
+virGetSelfLastModified;
 virGetUnprivSGIOSysfsPath;
 virGetUserCacheDirectory;
 virGetUserConfigDirectory;
@@ -1983,6 +1984,7 @@ virSetNonBlock;
 virSetUIDGID;
 virSetUIDGIDWithCaps;
 virStrIsPrint;
+virUpdateSelfLastModified;
 virValidateWWN;
 
 
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e3ed960..3dfaf48 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2564,18 +2564,21 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const 
char *filename)
 goto cleanup;
 }
 
-ut.actime = qemuCaps-mtime;
-ut.modtime = qemuCaps-mtime;
+ut.modtime = virGetSelfLastModified();
+if (qemuCaps-mtime  ut.modtime)
+ut.modtime = qemuCaps-mtime;
+
+ut.actime = ut.modtime;
 if (utime(filename, ut)  0) {
 virReportSystemError(errno,
- _(Failed to set mtime on '%s' for '%s'),
- filename, qemuCaps-binary);
+ _(Failed to set mtime on '%s' for '%s' to %lld),
+ filename, qemuCaps-binary, (long 
long)ut.modtime);
 ignore_value(unlink(filename));
 goto cleanup;
 }
 
 VIR_DEBUG(Saved caps '%s' for '%s' with %lld,
-  filename, qemuCaps-binary, (long long)qemuCaps-mtime);
+  filename, qemuCaps-binary, (long long)ut.modtime);
 
 ret = 0;
  cleanup:
@@ -2654,6 +2657,7 @@ virQEMUCapsInitCached(virQEMUCapsPtr qemuCaps, const char 
*cacheDir)
 int ret = -1;
 char *binaryhash = NULL;
 struct stat sb;
+time_t selfmtime = virGetSelfLastModified();
 
 if (virAsprintf(capsdir, %s/capabilities, cacheDir)  0)
 goto cleanup;
@@ -2687,11 +2691,13 @@ virQEMUCapsInitCached(virQEMUCapsPtr qemuCaps, const 
char *cacheDir)
 }
 
 /* Discard if cache is older that QEMU binary */
-/* XXX must also compare to libvirtd timestamp  */
-if (sb.st_mtime  qemuCaps-mtime) {
-VIR_DEBUG(Outdated cached capabilities '%s' for '%s' (%lld vs %lld),
+if (sb.st_mtime  qemuCaps-mtime ||
+sb.st_mtime  selfmtime) {
+VIR_DEBUG(Outdated cached capabilities '%s' for '%s' (%lld,%lld vs 
%lld),
   capsfile, qemuCaps-binary,
-  (long long)sb.st_mtime, (long long)qemuCaps-mtime);
+  (long long)sb.st_mtime,
+  (long long)selfmtime,
+  (long long)qemuCaps-mtime);
 ignore_value(unlink(capsfile));
 ret = 0;
 goto cleanup;
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 7a2fbb0..0e3fbd7 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -2173,3 +2173,26 @@ bool virIsSUID(void)
 {
 return getuid() != geteuid();
 }
+
+
+static time_t selfLastModified;
+
+time_t virGetSelfLastModified(void)
+{
+return selfLastModified;
+}
+
+
+void virUpdateSelfLastModified(const char *path)
+{
+struct stat sb;
+
+if (stat(path, sb)  0)
+return;
+
+if (sb.st_mtime  selfLastModified) {
+VIR_DEBUG(Setting self last modified to %lld for '%s',
+  (long long)sb.st_mtime, path);
+selfLastModified = sb.st_mtime;
+}
+}
diff --git a/src/util/virutil.h 

Re: [libvirt] [PATCH v3 2/2] query-command-line-options: query all the options in qemu-options.hx

2014-03-05 Thread Eric Blake
On 03/05/2014 08:58 AM, Eric Blake wrote:
 On 03/04/2014 11:40 PM, Amos Kong wrote:
 
 but the docs imply that I should now see:

 {parameters: [], option: smbios, argument: true}

 I really got : {parameters: [], option: smbios, argument: true}

 (I was testing with latest qemu upstream + my patches, attached the
 output file)
 
 Hmm, maybe I was testing a stale binary.  Let me try re-running tests on
 my end - I recently changed my choice of configure arguments to speed up
 build time by building fewer binaries, so maybe I tested on a binary
 that my configure arguments no longer rebuild.

Aha, it WAS my configure options at fault.  Apologies for the mis-test
on my side.  I can now confirm that pre-patch, I see (rearranged a
subset of entries, and newlines added for legibility):

{parameters: [], option: smbios},
{parameters: [{name: file, type: string},
   {name: events, type: string}], option: trace},

and no fips, while post-patch, I see:

{parameters: [], option: enable-fips, argument: false},
{parameters: [], option: smbios, argument: true},
{parameters: [{name: file, type: string},
   {name: events, type: string}], option: trace},

which matches the docs.  However, I did notice that pre-patch, I see:

{parameters: [], option: acpi}

while post-patch, there is no hit for acpi, but there is a new:

{parameters: [], option: acpitable, argument: true}

What's going on there?  It is a potential regression if we fail to list
an option post-patch that was listed pre-patch.  Then again, looking at
the actual -help text, I see my particular qemu binary mentions only
-acpitable [sig=str]... in the help text (pre- and post-patch), as
well as this test to prove there is no '-acpi':

$ ./x86_64-softmmu/qemu-system-x86_64 -acpi
qemu-system-x86_64: -acpi: invalid option
$ ./x86_64-softmmu/qemu-system-x86_64 -acpitable
qemu-system-x86_64: -acpitable: requires an argument

so it looks like your patch was silently fixing a bug.  Indeed, reading
vl.c, I see:

case QEMU_OPTION_acpitable:
opts = qemu_opts_parse(qemu_find_opts(acpi), optarg, 1);
if (!opts) {
exit(1);
}
do_acpitable_option(opts);

so the option table named acpi is indeed for the command line argument
acpitable.

It would be nice to mention bonus bug fixes like that in the commit
message (that is, you are not only adding support for flags like
-enable-fips, you are also fixing options to match their actual
command-line spelling rather than an alternate name associated with the
option table in use by the command).

So, at this point, we still need a v4 to avoid the duplicate static
tables, but I am now set up to give a Tested-by.

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



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

Re: [libvirt] [PATCH 08/10] virt-login-shell: use single instead of double fork

2014-03-05 Thread Eric Blake
On 03/05/2014 06:57 AM, John Ferlan wrote:
 Coverity has found an issue (NEGATIVE_RETURNS)
 
 The 'nfdlist' is the culprit.
 

  cleanup:
 +for (i = 0; i  nfdlist; i++)
 +VIR_FORCE_CLOSE(fdlist[i]);
 
 (41) Event negative_returns:  Using unsigned variable nfdlist in a
 loop exit condition.
 Also see events:  [negative_return_fn][var_assign]

Yep.  Fixing with this, as the obvious followup:

diff --git i/tools/virt-login-shell.c w/tools/virt-login-shell.c
index 3ea7ade..abe7eeb 100644
--- i/tools/virt-login-shell.c
+++ w/tools/virt-login-shell.c
@@ -339,8 +339,9 @@ main(int argc, char **argv)
 /* At this point, the parent is now waiting for the child to exit,
  * but as that may take a long time, we release resources now.  */
 cleanup:
-for (i = 0; i  nfdlist; i++)
-VIR_FORCE_CLOSE(fdlist[i]);
+if (nfdlist  0)
+for (i = 0; i  nfdlist; i++)
+VIR_FORCE_CLOSE(fdlist[i]);
 VIR_FREE(fdlist);
 virConfFree(conf);
 if (dom)


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



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

Re: [libvirt] [PATCH] Fix missing char dev lock path case in configure

2014-03-05 Thread Roman Bogorodskiy
  Daniel P. Berrange wrote:

 On Wed, Mar 05, 2014 at 07:34:11PM +0400, Roman Bogorodskiy wrote:
  configure check for character devices lock path calls
  AC_DEFINE_UNQUOTED for VIR_CHRDEV_LOCK_FILE_PATH even if
  $with_chrdev_lock_files = no.
  
  So the locking code in conf/virchrdev.c:
  
   #ifdef VIR_CHRDEV_LOCK_FILE_PATH
  
  is compiled in even if it shouldn't, because VIR_CHRDEV_LOCK_FILE_PATH
  is defined as no, so it tries to create lock files with strange
  lock path like 'no/LCK..'.
  
  Fix that by calling AC_DEFINE_UNQUOTED only if $with_chrdev_lock_files
  is not 'no'.
  ---
   configure.ac | 6 --
   1 file changed, 4 insertions(+), 2 deletions(-)
  
  diff --git a/configure.ac b/configure.ac
  index a9339ce..62b74c5 100644
  --- a/configure.ac
  +++ b/configure.ac
  @@ -1401,8 +1401,10 @@ if test $with_chrdev_lock_files != no; then
   AC_MSG_ERROR([You must specify path for the lock files on this
   platform])
 fi
  -  AC_DEFINE_UNQUOTED([VIR_CHRDEV_LOCK_FILE_PATH], 
  $with_chrdev_lock_files,
  -  [path to directory containing UUCP device lock 
  files])
  +  if test $with_chrdev_lock_files != no; then
  +AC_DEFINE_UNQUOTED([VIR_CHRDEV_LOCK_FILE_PATH], 
  $with_chrdev_lock_files,
  +   [path to directory containing UUCP device lock 
  files])
  +  fi
   fi
   AM_CONDITIONAL([VIR_CHRDEV_LOCK_FILE_PATH], [test 
  $with_chrdev_lock_files != no])
 
 ACK

Pushed, thanks.

Roman Bogorodskiy


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

Re: [libvirt] [PATCH 08/10] virt-login-shell: use single instead of double fork

2014-03-05 Thread John Ferlan


On 03/05/2014 01:55 PM, Eric Blake wrote:
 On 03/05/2014 06:57 AM, John Ferlan wrote:
 Coverity has found an issue (NEGATIVE_RETURNS)

 The 'nfdlist' is the culprit.

 
  cleanup:
 +for (i = 0; i  nfdlist; i++)
 +VIR_FORCE_CLOSE(fdlist[i]);

 (41) Event negative_returns: Using unsigned variable nfdlist in a
 loop exit condition.
 Also see events: [negative_return_fn][var_assign]
 
 Yep.  Fixing with this, as the obvious followup:
 
 diff --git i/tools/virt-login-shell.c w/tools/virt-login-shell.c
 index 3ea7ade..abe7eeb 100644
 --- i/tools/virt-login-shell.c
 +++ w/tools/virt-login-shell.c
 @@ -339,8 +339,9 @@ main(int argc, char **argv)
  /* At this point, the parent is now waiting for the child to exit,
   * but as that may take a long time, we release resources now.  */
  cleanup:
 -for (i = 0; i  nfdlist; i++)
 -VIR_FORCE_CLOSE(fdlist[i]);
 +if (nfdlist  0)
 +for (i = 0; i  nfdlist; i++)
 +VIR_FORCE_CLOSE(fdlist[i]);
  VIR_FREE(fdlist);
  virConfFree(conf);
  if (dom)
 
 


ACK,

checked with my Coverity build too.

John

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


[libvirt] [PATCH v2 0/5] Expose FSFreeze/FSThaw within the guest as API

2014-03-05 Thread Tomoki Sekiyama
Hello,

This is patchset v2 to add FSFreeze/FSThaw API for custom disk snapshotting.

Changes to v1:
 * added quiesced status tracking to avoid double fsfreeze in qemu driver
 * removed unused 'mountPoint' argument
 * use @acl: domain:write in remote driver
 * rebased to master
 (v1: http://www.redhat.com/archives/libvir-list/2013-November/msg00610.html )

=== Description ===

Currently FSFreeze and FSThaw are supported by qemu guest agent and they are
used internally in snapshot-create command with --quiesce option.
However, when users want to utilize the native snapshot feature of storage
devices (such as LVM over iSCSI, enterprise storage appliances, etc.),
they need to issue fsfreeze command separately from libvirt-driven snapshots.
(OpenStack cinder provides these storages' snapshot feature, but it cannot
 quiesce the guest filesystems automatically for now.)

Although virDomainQemuGuestAgent() API could be used for this purpose, it
is only for debugging and is not supported officially.

This patchset adds virDomainFSFreeze()/virDomainFSThaw() APIs and virsh
domfsfreeze/domfsthaw commands to enable the users to freeze and thaw
domain's filesystems cleanly.

The APIs have flags option currently unsupported for future extension.
---

Tomoki Sekiyama (5):
  Introduce virDomainFSFreeze() and virDomainFSThaw() public API
  remote: Implement virDomainFSFreeze and virDomainFSThaw
  qemu: Track domain quiesced status
  qemu: Implement virDomainFSFreeze and virDomainFSThaw
  virsh: Expose new virDomainFSFreeze and virDomainFSThaw API


 include/libvirt/libvirt.h.in |6 ++
 src/driver.h |   10 
 src/libvirt.c|   70 +
 src/libvirt_public.syms  |5 ++
 src/qemu/qemu_domain.h   |2 +
 src/qemu/qemu_driver.c   |  119 ++
 src/remote/remote_driver.c   |2 +
 src/remote/remote_protocol.x |   23 
 src/remote_protocol-structs  |9 +++
 src/rpc/gendispatch.pl   |2 +
 tools/virsh-domain.c |   92 
 tools/virsh.pod  |   15 +
 12 files changed, 344 insertions(+), 11 deletions(-)

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


[libvirt] [PATCH v2 3/5] qemu: Track domain quiesced status

2014-03-05 Thread Tomoki Sekiyama
Adds an quiesced flag into qemuDomainObjPrivate that tracks whether guest
filesystems of the domain is quiesced of not.
It also modify error code from qemuDomainSnapshotFSFreeze and
qemuDomainSnapshotFSThaw, so that a caller can know whether the command is
actually sent to the guest agent. If the error is caused before sending a
freeze command, a counterpart thaw command shouldn't be sent to avoid
confusing the tracking of quiesced status.
---
 src/qemu/qemu_domain.h |2 ++
 src/qemu/qemu_driver.c |   41 +++--
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 0bed50b..8a79a00 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -176,6 +176,8 @@ struct _qemuDomainObjPrivate {
 char **qemuDevices; /* NULL-terminated list of devices aliases known to 
QEMU */
 
 bool hookRun;  /* true if there was a hook run over this domain */
+
+bool quiesced; /* true if the domain filesystems are quiesced */
 };
 
 typedef enum {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9aad2dc..8109e46 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12040,6 +12040,8 @@ cleanup:
 }
 
 
+/* Return -1 if request is not sent to agent due to misconfig, -2 on agent
+ * failure, and number of frozen filesystems on success. */
 static int
 qemuDomainSnapshotFSFreeze(virDomainObjPtr vm) {
 qemuDomainObjPrivatePtr priv = vm-privateData;
@@ -12056,14 +12058,24 @@ qemuDomainSnapshotFSFreeze(virDomainObjPtr vm) {
_(QEMU guest agent is not configured));
 return -1;
 }
+if (priv-quiesced) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(domain is already quiesced));
+return -1;
+}
 
 qemuDomainObjEnterAgent(vm);
 freezed = qemuAgentFSFreeze(priv-agent);
 qemuDomainObjExitAgent(vm);
 
-return freezed;
+if (freezed = 0)
+priv-quiesced = true;
+
+return freezed  0 ? -2 : freezed;
 }
 
+/* Return -1 if request is not sent to agent due to misconfig, -2 on agent
+ * failure, and number of thawed filesystems on success. */
 static int
 qemuDomainSnapshotFSThaw(virDomainObjPtr vm, bool report)
 {
@@ -12084,6 +12096,11 @@ qemuDomainSnapshotFSThaw(virDomainObjPtr vm, bool 
report)
_(QEMU guest agent is not configured));
 return -1;
 }
+if (!priv-quiesced  report) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(domain is not quiesced));
+return -1;
+}
 
 qemuDomainObjEnterAgent(vm);
 if (!report)
@@ -12093,8 +12110,11 @@ qemuDomainSnapshotFSThaw(virDomainObjPtr vm, bool 
report)
 virSetError(err);
 qemuDomainObjExitAgent(vm);
 
+if (thawed = 0)
+priv-quiesced = false;
+
 virFreeError(err);
-return thawed;
+return thawed  0 ? -2 : thawed;
 }
 
 /* The domain is expected to be locked and inactive. */
@@ -13069,17 +13089,18 @@ qemuDomainSnapshotCreateActiveExternal(virConnectPtr 
conn,
 goto cleanup;
 
 /* If quiesce was requested, then issue a freeze command, and a
- * counterpart thaw command, no matter what.  The command will
- * fail if the guest is paused or the guest agent is not
- * running.  */
+ * counterpart thaw command when the it is actually sent to agent.
+ * The command will fail if the guest is paused or the guest agent is not
+ * running, or is already quiesced.  */
 if (flags  VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE) {
-if (qemuDomainSnapshotFSFreeze(vm)  0) {
-/* helper reported the error */
-thaw = -1;
+int freeze = qemuDomainSnapshotFSFreeze(vm);
+if (freeze  0) {
+/* the helper reported the error */
+if (freeze != -1)
+thaw = -1; /* the command is sent but agent failed */
 goto endjob;
-} else {
-thaw = 1;
 }
+thaw = 1;
 }
 
 /* We need to track what state the guest is in, since taking the

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


[libvirt] [PATCH v2 2/5] remote: Implement virDomainFSFreeze and virDomainFSThaw

2014-03-05 Thread Tomoki Sekiyama
New rules are added in fixup_name in gendispatch.pl to keep the name
FSFreeze and FSThaw.

Signed-off-by: Tomoki Sekiyama tomoki.sekiy...@hds.com
---
 src/remote/remote_driver.c   |2 ++
 src/remote/remote_protocol.x |   23 ++-
 src/remote_protocol-structs  |9 +
 src/rpc/gendispatch.pl   |2 ++
 4 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 955465a..8a4efe4 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -7660,6 +7660,8 @@ static virDriver remote_driver = {
 .domainMigrateFinish3Params = remoteDomainMigrateFinish3Params, /* 1.1.0 */
 .domainMigrateConfirm3Params = remoteDomainMigrateConfirm3Params, /* 1.1.0 
*/
 .connectGetCPUModelNames = remoteConnectGetCPUModelNames, /* 1.1.3 */
+.domainFSFreeze = remoteDomainFSFreeze, /* 1.2.3 */
+.domainFSThaw = remoteDomainFSThaw, /* 1.2.3 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index f1f2359..3585f63 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2952,6 +2952,15 @@ struct remote_network_event_lifecycle_msg {
 int detail;
 };
 
+struct remote_domain_fsfreeze_args {
+remote_nonnull_domain dom;
+unsigned int flags;
+};
+
+struct remote_domain_fsthaw_args {
+remote_nonnull_domain dom;
+unsigned int flags;
+};
 
 
 /*- Protocol. -*/
@@ -5262,5 +5271,17 @@ enum remote_procedure {
  * @generate: both
  * @acl: none
  */
-REMOTE_PROC_DOMAIN_EVENT_CALLBACK_DEVICE_REMOVED = 333
+REMOTE_PROC_DOMAIN_EVENT_CALLBACK_DEVICE_REMOVED = 333,
+
+/**
+ * @generate: both
+ * @acl: domain:write
+ */
+REMOTE_PROC_DOMAIN_FSFREEZE = 334,
+
+/**
+ * @generate: both
+ * @acl: domain:write
+ */
+REMOTE_PROC_DOMAIN_FSTHAW = 335
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 5636d55..07086a0 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2420,6 +2420,13 @@ struct remote_network_event_lifecycle_msg {
 remote_nonnull_network net;
 intevent;
 intdetail;
+struct remote_domain_fsfreeze_args {
+remote_nonnull_domain  dom;
+u_int  flags;
+};
+struct remote_domain_fsthaw_args {
+remote_nonnull_domain  dom;
+u_int  flags;
 };
 enum remote_procedure {
 REMOTE_PROC_CONNECT_OPEN = 1,
@@ -2755,4 +2762,6 @@ enum remote_procedure {
 REMOTE_PROC_DOMAIN_EVENT_CALLBACK_BALLOON_CHANGE = 331,
 REMOTE_PROC_DOMAIN_EVENT_CALLBACK_PMSUSPEND_DISK = 332,
 REMOTE_PROC_DOMAIN_EVENT_CALLBACK_DEVICE_REMOVED = 333,
+REMOTE_PROC_DOMAIN_FSFREEZE = 334,
+REMOTE_PROC_DOMAIN_FSTHAW = 335,
 };
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index ceb1ad8..0b256f3 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -64,6 +64,8 @@ sub fixup_name {
 $name =~ s/Nmi$/NMI/;
 $name =~ s/Pm/PM/;
 $name =~ s/Fstrim$/FSTrim/;
+$name =~ s/Fsfreeze$/FSFreeze/;
+$name =~ s/Fsthaw$/FSThaw/;
 $name =~ s/Scsi/SCSI/;
 $name =~ s/Wwn$/WWN/;
 

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


[libvirt] [PATCH v2 4/5] qemu: Implement virDomainFSFreeze and virDomainFSThaw

2014-03-05 Thread Tomoki Sekiyama
Use qemuDomainSnapshotFSFreeze() and qemuDomainSnapshotFSFreeze() which are
already implemented for snapshot quiescing.

Signed-off-by: Tomoki Sekiyama tomoki.sekiy...@hds.com
---
 src/qemu/qemu_driver.c |   78 
 1 file changed, 78 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8109e46..29202a3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16598,6 +16598,82 @@ qemuConnectGetCPUModelNames(virConnectPtr conn,
 }
 
 
+static int
+qemuDomainFSFreeze(virDomainPtr dom,
+   unsigned int flags)
+{
+virQEMUDriverPtr driver = dom-conn-privateData;
+virDomainObjPtr vm;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+if (!(vm = qemuDomObjFromDomain(dom)))
+goto cleanup;
+
+if (virDomainFSFreezeEnsureACL(dom-conn, vm-def)  0)
+goto cleanup;
+
+if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY)  0)
+goto cleanup;
+
+if (!virDomainObjIsActive(vm)) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   %s, _(domain is not running));
+goto endjob;
+}
+
+ret = qemuDomainSnapshotFSFreeze(vm);
+
+endjob:
+if (!qemuDomainObjEndJob(driver, vm))
+vm = NULL;
+
+cleanup:
+if (vm)
+virObjectUnlock(vm);
+return ret;
+}
+
+
+static int
+qemuDomainFSThaw(virDomainPtr dom,
+ unsigned int flags)
+{
+virQEMUDriverPtr driver = dom-conn-privateData;
+virDomainObjPtr vm;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+if (!(vm = qemuDomObjFromDomain(dom)))
+goto cleanup;
+
+if (virDomainFSThawEnsureACL(dom-conn, vm-def)  0)
+goto cleanup;
+
+if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY)  0)
+goto cleanup;
+
+if (!virDomainObjIsActive(vm)) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   %s, _(domain is not running));
+goto endjob;
+}
+
+ret = qemuDomainSnapshotFSThaw(vm, true);
+
+endjob:
+if (!qemuDomainObjEndJob(driver, vm))
+vm = NULL;
+
+cleanup:
+if (vm)
+virObjectUnlock(vm);
+return ret;
+}
+
+
 static virDriver qemuDriver = {
 .no = VIR_DRV_QEMU,
 .name = QEMU_DRIVER_NAME,
@@ -16785,6 +16861,8 @@ static virDriver qemuDriver = {
 .domainMigrateFinish3Params = qemuDomainMigrateFinish3Params, /* 1.1.0 */
 .domainMigrateConfirm3Params = qemuDomainMigrateConfirm3Params, /* 1.1.0 */
 .connectGetCPUModelNames = qemuConnectGetCPUModelNames, /* 1.1.3 */
+.domainFSFreeze = qemuDomainFSFreeze, /* 1.2.3 */
+.domainFSThaw = qemuDomainFSThaw, /* 1.2.3 */
 };
 
 

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


[libvirt] [PATCH v2 5/5] virsh: Expose new virDomainFSFreeze and virDomainFSThaw API

2014-03-05 Thread Tomoki Sekiyama
These are exposed under domfsfreeze command and domfsthaw command.

Signed-off-by: Tomoki Sekiyama tomoki.sekiy...@hds.com
---
 tools/virsh-domain.c |   92 ++
 tools/virsh.pod  |   15 
 2 files changed, 107 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 1d3c5f0..329e32e 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11201,6 +11201,86 @@ cleanup:
 return ret;
 }
 
+static const vshCmdInfo info_domfsfreeze[] = {
+{.name = help,
+ .data = N_(Freeze domain's mounted filesystems.)
+},
+{.name = desc,
+ .data = N_(Freeze domain's mounted filesystems.)
+},
+{.name = NULL}
+};
+
+static const vshCmdOptDef opts_domfsfreeze[] = {
+{.name = domain,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(domain name, id or uuid)
+},
+{.name = NULL}
+};
+static bool
+cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd)
+{
+virDomainPtr dom = NULL;
+bool ret = false;
+unsigned int flags = 0;
+
+if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+return ret;
+
+if (virDomainFSFreeze(dom, flags)  0) {
+vshError(ctl, _(Unable to freeze filesystems));
+goto cleanup;
+}
+
+ret = true;
+
+cleanup:
+virDomainFree(dom);
+return ret;
+}
+
+static const vshCmdInfo info_domfsthaw[] = {
+{.name = help,
+ .data = N_(Thaw domain's mounted filesystems.)
+},
+{.name = desc,
+ .data = N_(Thaw domain's mounted filesystems.)
+},
+{.name = NULL}
+};
+
+static const vshCmdOptDef opts_domfsthaw[] = {
+{.name = domain,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(domain name, id or uuid)
+},
+{.name = NULL}
+};
+static bool
+cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd)
+{
+virDomainPtr dom = NULL;
+bool ret = false;
+unsigned int flags = 0;
+
+if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+return ret;
+
+if (virDomainFSThaw(dom, flags)  0) {
+vshError(ctl, _(Unable to thaw filesystems));
+goto cleanup;
+}
+
+ret = true;
+
+cleanup:
+virDomainFree(dom);
+return ret;
+}
+
 const vshCmdDef domManagementCmds[] = {
 {.name = attach-device,
  .handler = cmdAttachDevice,
@@ -11348,6 +11428,18 @@ const vshCmdDef domManagementCmds[] = {
  .info = info_domdisplay,
  .flags = 0
 },
+{.name = domfsfreeze,
+ .handler = cmdDomFSFreeze,
+ .opts = opts_domfsfreeze,
+ .info = info_domfsfreeze,
+ .flags = 0
+},
+{.name = domfsthaw,
+ .handler = cmdDomFSThaw,
+ .opts = opts_domfsthaw,
+ .info = info_domfsthaw,
+ .flags = 0
+},
 {.name = domfstrim,
  .handler = cmdDomFSTrim,
  .opts = opts_domfstrim,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index cafbb9a..e234bde 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -926,6 +926,21 @@ Output a URI which can be used to connect to the graphical 
display of the
 domain via VNC, SPICE or RDP. If I--include-password is specified, the
 SPICE channel password will be included in the URI.
 
+=item Bdomfsfreeze Idomain
+
+Freeze all mounted filesystems within a running domain to prepare for
+consistent snapshots.
+
+Note that Bsnapshot-create command has a I--quiesce option to freeze
+and thaw the filesystems automatically to keep snapshots consistent.
+Bdomfsfreeze command is only needed when a user wants to utilize the
+native snapshot features of storage devices not supported by libvirt yet.
+
+=item Bdomfsthaw Idomain
+
+Thaw all mounted filesystems within a running domain, which are frozen
+by domfsfreeze command.
+
 =item Bdomfstrim Idomain [I--minimum Bbytes]
 [I--mountpoint mountPoint]
 

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


Re: [libvirt] [PATCH 3/4] Cache result of QEMU capabilities extraction

2014-03-05 Thread Guido Günther
Hi Daniel,
On Wed, Mar 05, 2014 at 05:53:53PM +, Daniel P. Berrange wrote:
[..snip..] 
 +/* Discard if cache is older that QEMU binary */
 +/* XXX must also compare to libvirtd timestamp  */
 +if (sb.st_mtime  qemuCaps-mtime) {
I think looking at the mtime isn't sufficent here. Tools like dpkg set
the mtime to the time the package was built at not the installation time
so we might end up updating qemu but still having an mtime older than
the time the xml was created (same holds for downgrades to older qemu
versions) or are we simply requiring distributors to clean the cache
upon package upgrades (which would mandate using a trigger)?

Maybe we need to actually calculate the binaries checksum not only the
pathname? We could then simply just wipe alle checksums upon libvirt
upgrades to get rid of old entries.
Cheers,
 -- Guido

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


Re: [libvirt] [PATCH 3/4] Cache result of QEMU capabilities extraction

2014-03-05 Thread Eric Blake
On 03/05/2014 01:40 PM, Guido Günther wrote:
 Hi Daniel,
 On Wed, Mar 05, 2014 at 05:53:53PM +, Daniel P. Berrange wrote:
 [..snip..] 
 +/* Discard if cache is older that QEMU binary */
 +/* XXX must also compare to libvirtd timestamp  */
 +if (sb.st_mtime  qemuCaps-mtime) {
 I think looking at the mtime isn't sufficent here. Tools like dpkg set
 the mtime to the time the package was built at not the installation time
 so we might end up updating qemu but still having an mtime older than
 the time the xml was created (same holds for downgrades to older qemu
 versions) or are we simply requiring distributors to clean the cache
 upon package upgrades (which would mandate using a trigger)?

ctime is better than mtime, because ctime can't be faked.  On the other
hand, ctime changes in more situations than mtime (chmod, anyone?) - but
then again, any time ctime changes, we probably DO want to retest (a
chmod may change our ability to execute a given binary).

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



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

Re: [libvirt] [PATCH 1/4] Add helper APIs for generating cryptographic hashes

2014-03-05 Thread Eric Blake
On 03/05/2014 10:53 AM, Daniel P. Berrange wrote:
 GNULIB provides APIs for calculating md5 and sha256 hashes,
 but these APIs only return you raw byte arrays. Most users
 in libvirt want the hash in printable string format. Add
 some helper APIs in util/vircrypto.{c,h} for doing this.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  .gitignore  |  1 +
  include/libvirt/virterror.h |  1 +
  po/POTFILES.in  |  1 +
  src/Makefile.am |  1 +
  src/libvirt_private.syms|  4 ++
  src/util/vircrypto.c| 80 
  src/util/vircrypto.h| 40 
  src/util/virerror.c |  1 +
  tests/Makefile.am   |  5 +++
  tests/vircryptotest.c   | 90 
 +
  10 files changed, 224 insertions(+)
  create mode 100644 src/util/vircrypto.c
  create mode 100644 src/util/vircrypto.h
  create mode 100644 tests/vircryptotest.c
 

 +#define VIR_FROM_THIS VIR_FROM_CRYPTO
 +
 +static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
 +'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

Why not the more compact:

static const char hex[] = 0123456789abcdef;

virbuffer.c and virsystemd.c also have variants of this table.


 +
 +for (i = 0; i  hashinfo[hash].hashlen; i++) {
 +(*output)[i*2] = hex[(buf[i]  4)  0xf];
 +(*output)[(i*2)+1] = hex[buf[i]  0xf];

Spaces around operators * and +

ACK.

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



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

Re: [libvirt] [PATCH 2/4] Convert lock driver plugins to use new crypto APIs

2014-03-05 Thread Eric Blake
On 03/05/2014 10:53 AM, Daniel P. Berrange wrote:
 Conver the sanlock and lockd lock driver plugins over to use

s/Conver/Convert/

 the new virCryptoHashString APIs instead of having their own
 duplicated code.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  src/locking/lock_driver_lockd.c   | 32 ++---
  src/locking/lock_driver_sanlock.c | 42 
 ++-
  2 files changed, 12 insertions(+), 62 deletions(-)

ACK

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



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

Re: [libvirt] [PATCH 3/4] Cache result of QEMU capabilities extraction

2014-03-05 Thread Eric Blake
On 03/05/2014 10:53 AM, Daniel P. Berrange wrote:
 Extracting capabilities from QEMU takes a notable amount of time
 when all QEMU binaries are installed. Each system emulator
 needs about 200-300ms multiplied by 26 binaries == ~5-8 seconds.
 
 This change causes the QEMU driver to save an XML file containing
 the content of the virQEMUCaps object instance in the cache
 dir eg /var/cache/libvirt/qemu/capabilities/$SHA256(binarypath).xml
 or $HOME/.cache/libvirt/qemu/cache/capabilities/$SHA256(binarypath).xml
 
 We attempt to load this and only if it fails, do we fallback to
 probing the QEMU binary. The timestamp of the file is compared to
 the timestamp of the QEMU binary and discarded if the QEMU binary
 is newer.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  src/qemu/qemu_capabilities.c | 412 
 ++-
  src/qemu/qemu_capabilities.h |   2 +
  src/qemu/qemu_driver.c   |   1 +
  3 files changed, 407 insertions(+), 8 deletions(-)
 

 @@ -44,6 +45,7 @@
  #include unistd.h
  #include sys/wait.h
  #include stdarg.h
 +#include utime.h

utime.h (and the utime() function) is deprecated by POSIX and
therefore no longer portable because it corrupts sub-second timestamps.
 Better is to use gnulib's utimensat (or futimens).  But what timestamps
do we actually have to munge?

 +
 +ut.actime = qemuCaps-mtime;
 +ut.modtime = qemuCaps-mtime;
 +if (utime(filename, ut)  0) {
 +virReportSystemError(errno,
 + _(Failed to set mtime on '%s' for '%s'),
 + filename, qemuCaps-binary);

Why not just store the qemu binary timestamp in the XML, rather than
playing games with the mtime of the xml file?
 +
 +/* Discard if cache is older that QEMU binary */
 +/* XXX must also compare to libvirtd timestamp  */
 +if (sb.st_mtime  qemuCaps-mtime) {

This ignores subsecond timestamps; you may want to use gnulib's
stat-time module to do a more accurate check.

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



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

Re: [libvirt] [PATCH 4/4] Refresh qemu capabilities if libvirtd binary changes

2014-03-05 Thread Eric Blake
On 03/05/2014 10:53 AM, Daniel P. Berrange wrote:
 Currently the QEMU capabilities cache files on disk are only
 invalidated if the QEMU binary changes. New versions of libvirt,
 however, may want to extract more information from existing
 binaries. Thus we must take into account modification time of
 the libvirtd daemon and/or any loadable driver modules when
 checking cache validity
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---

 +++ b/src/qemu/qemu_capabilities.c
 @@ -2564,18 +2564,21 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const 
 char *filename)
  goto cleanup;
  }
  
 -ut.actime = qemuCaps-mtime;
 -ut.modtime = qemuCaps-mtime;
 +ut.modtime = virGetSelfLastModified();
 +if (qemuCaps-mtime  ut.modtime)
 +ut.modtime = qemuCaps-mtime;
 +

I'm still thinking that mtime is a bit dangerous, compared to ctime.

 +ut.actime = ut.modtime;
  if (utime(filename, ut)  0) {
  virReportSystemError(errno,
 - _(Failed to set mtime on '%s' for '%s'),
 - filename, qemuCaps-binary);
 + _(Failed to set mtime on '%s' for '%s' to 
 %lld),
 + filename, qemuCaps-binary, (long 
 long)ut.modtime);

If you go by ctime, you can't use utime() (or the modern futimens
counterpart).  I'm also still not convinced that just storing the time
in the xml file is going to be any slower than playing file timestamp games.

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



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

Re: [libvirt] [PATCH v3 2/2] query-command-line-options: query all the options in qemu-options.hx

2014-03-05 Thread Amos Kong
On Wed, Mar 05, 2014 at 11:50:22AM -0700, Eric Blake wrote:
 On 03/05/2014 08:58 AM, Eric Blake wrote:
  On 03/04/2014 11:40 PM, Amos Kong wrote:
  
  but the docs imply that I should now see:
 
  {parameters: [], option: smbios, argument: true}
 
  I really got : {parameters: [], option: smbios, argument: true}
 
  (I was testing with latest qemu upstream + my patches, attached the
  output file)
  
  Hmm, maybe I was testing a stale binary.  Let me try re-running tests on
  my end - I recently changed my choice of configure arguments to speed up
  build time by building fewer binaries, so maybe I tested on a binary
  that my configure arguments no longer rebuild.
 
 Aha, it WAS my configure options at fault.  Apologies for the mis-test
 on my side.  I can now confirm that pre-patch, I see (rearranged a
 subset of entries, and newlines added for legibility):
 
 {parameters: [], option: smbios},
 {parameters: [{name: file, type: string},
{name: events, type: string}], option: trace},
 
 and no fips, while post-patch, I see:
 
 {parameters: [], option: enable-fips, argument: false},
 {parameters: [], option: smbios, argument: true},
 {parameters: [{name: file, type: string},
{name: events, type: string}], option: trace},
 
 which matches the docs.  However, I did notice that pre-patch, I see:
 
 {parameters: [], option: acpi}
 
 while post-patch, there is no hit for acpi, but there is a new:
 
 {parameters: [], option: acpitable, argument: true}
 
 What's going on there?  It is a potential regression if we fail to list
 an option post-patch that was listed pre-patch.  Then again, looking at
 the actual -help text, I see my particular qemu binary mentions only
 -acpitable [sig=str]... in the help text (pre- and post-patch), as
 well as this test to prove there is no '-acpi':
 
 $ ./x86_64-softmmu/qemu-system-x86_64 -acpi
 qemu-system-x86_64: -acpi: invalid option
 $ ./x86_64-softmmu/qemu-system-x86_64 -acpitable
 qemu-system-x86_64: -acpitable: requires an argument
 
 so it looks like your patch was silently fixing a bug.  Indeed, reading
 vl.c, I see:
 
 case QEMU_OPTION_acpitable:
 opts = qemu_opts_parse(qemu_find_opts(acpi), optarg, 1);
 if (!opts) {
 exit(1);
 }
 do_acpitable_option(opts);
 
 so the option table named acpi is indeed for the command line argument
 acpitable.

Can we update all the name in option tables to match with actual
command-line spelling? (we can use another patch to fix it)
 
 It would be nice to mention bonus bug fixes like that in the commit
 message (that is, you are not only adding support for flags like
 -enable-fips, you are also fixing options to match their actual
 command-line spelling rather than an alternate name associated with the
 option table in use by the command).
 
 So, at this point, we still need a v4 to avoid the duplicate static
 tables, but I am now set up to give a Tested-by.

Thanks for your confirm, I will post a V4.

-- 
Amos.


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

[libvirt] [PATCH v4 0/2] fix query-command-line-options

2014-03-05 Thread Amos Kong
This patchset fixed some issues of query-command-line-options:
 * some new options that haven't argument can't be queried. (eg: -enable-fips)
 * some legacy options that have argument can't be queried. (eg: -vnc display)

More discussion:
 http://marc.info/?l=qemu-develm=139081830416684w=2

V2: remove duplicate option tables, update schema (eric)
V3: fix typo in commitlog and export qemu_options talbe (eric)
V4: avoid the duplicate static table (eric)

Amos Kong (2):
  qmp: rename query_option_descs() to get_param_infolist()
  query-command-line-options: query all the options in qemu-options.hx

 qapi-schema.json   |  8 ++--
 qemu-options.h | 10 ++
 util/qemu-config.c | 50 +-
 vl.c   | 15 ---
 4 files changed, 57 insertions(+), 26 deletions(-)

-- 
1.8.5.3

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


[libvirt] [PATCH v4 2/2] query-command-line-options: query all the options in qemu-options.hx

2014-03-05 Thread Amos Kong
vm_config_groups[] only contains part of the options which have
argument, and all options which have no argument aren't added
to vm_config_groups[]. Current query-command-line-options only
checks options from vm_config_groups[], so some options will
be lost.

We have macro in qemu-options.hx to generate a table that
contains all the options. This patch tries to query options
from the table.

Then we won't lose the legacy options that weren't added to
vm_config_groups[] (eg: -vnc, -smbios). The options that have
no argument will also be returned (eg: -enable-fips)

Some options that have argument have a NULL desc list, some
options don't have argument, and parameters is mandatory
in the past. So we add a new field argument to present
if the option takes unspecified arguments.

This patch also fixes options to match their actual command-line
spelling rather than an alternate name associated with the
option table in use by the command.

Signed-off-by: Amos Kong ak...@redhat.com
---
 qapi-schema.json   |  8 ++--
 qemu-options.h | 10 ++
 util/qemu-config.c | 44 ++--
 vl.c   | 15 ---
 4 files changed, 54 insertions(+), 23 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 193e7e4..4ab0d16 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4070,12 +4070,16 @@
 #
 # @option: option name
 #
-# @parameters: an array of @CommandLineParameterInfo
+# @parameters: array of @CommandLineParameterInfo, possibly empty
+# @argument: @optional present if the @parameters array is empty. If
+#true, then the option takes unspecified arguments, if
+#false, then the option is merely a boolean flag (since 2.0)
 #
 # Since 1.5
 ##
 { 'type': 'CommandLineOptionInfo',
-  'data': { 'option': 'str', 'parameters': ['CommandLineParameterInfo'] } }
+  'data': { 'option': 'str', 'parameters': ['CommandLineParameterInfo'],
+'*argument': 'bool' } }
 
 ##
 # @query-command-line-options:
diff --git a/qemu-options.h b/qemu-options.h
index 89a009e..8a515e0 100644
--- a/qemu-options.h
+++ b/qemu-options.h
@@ -25,6 +25,8 @@
  * THE SOFTWARE.
  */
 
+#include sysemu/arch_init.h
+
 #ifndef _QEMU_OPTIONS_H_
 #define _QEMU_OPTIONS_H_
 
@@ -33,4 +35,12 @@ enum {
 #include qemu-options-wrapper.h
 };
 
+typedef struct QEMUOption {
+const char *name;
+int flags;
+int index;
+uint32_t arch_mask;
+} QEMUOption;
+
+extern const QEMUOption qemu_options[];
 #endif
diff --git a/util/qemu-config.c b/util/qemu-config.c
index d2facfd..2f89b92 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -6,6 +6,16 @@
 #include hw/qdev.h
 #include qapi/error.h
 #include qmp-commands.h
+#include qemu-options.h
+
+#define HAS_ARG 0x0001
+
+const QEMUOption qemu_options[] = {
+{ h, 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
+#define QEMU_OPTIONS_GENERATE_OPTIONS
+#include qemu-options-wrapper.h
+{ NULL },
+};
 
 static QemuOptsList *vm_config_groups[32];
 static QemuOptsList *drive_config_groups[4];
@@ -78,6 +88,17 @@ static CommandLineParameterInfoList 
*get_param_infolist(const QemuOptDesc *desc)
 return param_list;
 }
 
+static int get_group_index(const char *name)
+{
+int i;
+
+for (i = 0; vm_config_groups[i] != NULL; i++) {
+if (!strcmp(vm_config_groups[i]-name, name)) {
+return i;
+}
+}
+return -1;
+}
 /* remove repeated entry from the info list */
 static void cleanup_infolist(CommandLineParameterInfoList *head)
 {
@@ -139,15 +160,26 @@ CommandLineOptionInfoList 
*qmp_query_command_line_options(bool has_option,
 CommandLineOptionInfo *info;
 int i;
 
-for (i = 0; vm_config_groups[i] != NULL; i++) {
-if (!has_option || !strcmp(option, vm_config_groups[i]-name)) {
+for (i = 0; qemu_options[i].name; i++) {
+if (!has_option || !strcmp(option, qemu_options[i].name)) {
 info = g_malloc0(sizeof(*info));
-info-option = g_strdup(vm_config_groups[i]-name);
-if (!strcmp(drive, vm_config_groups[i]-name)) {
+info-option = g_strdup(qemu_options[i].name);
+
+int idx = get_group_index(qemu_options[i].name);
+
+if (qemu_options[i].flags) {
+info-argument = true;
+}
+
+if (!strcmp(drive, qemu_options[i].name)) {
 info-parameters = get_drive_infolist();
-} else {
+} else if (idx = 0) {
 info-parameters =
-get_param_infolist(vm_config_groups[i]-desc);
+get_param_infolist(vm_config_groups[idx]-desc);
+}
+
+if (!info-parameters) {
+info-has_argument = true;
 }
 entry = g_malloc0(sizeof(*entry));
 entry-value = info;
diff --git a/vl.c b/vl.c
index 685a7a9..6269762 100644
--- a/vl.c
+++ b/vl.c
@@ -111,7 +111,6 @@ int main(int argc, char **argv)
 #include trace/control.h
 

[libvirt] [PATCH v4 1/2] qmp: rename query_option_descs() to get_param_infolist()

2014-03-05 Thread Amos Kong
Signed-off-by: Amos Kong ak...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 util/qemu-config.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/util/qemu-config.c b/util/qemu-config.c
index f610101..d2facfd 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -39,7 +39,7 @@ QemuOptsList *qemu_find_opts(const char *group)
 return ret;
 }
 
-static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc 
*desc)
+static CommandLineParameterInfoList *get_param_infolist(const QemuOptDesc 
*desc)
 {
 CommandLineParameterInfoList *param_list = NULL, *entry;
 CommandLineParameterInfo *info;
@@ -120,9 +120,9 @@ static CommandLineParameterInfoList 
*get_drive_infolist(void)
 
 for (i = 0; drive_config_groups[i] != NULL; i++) {
 if (!head) {
-head = query_option_descs(drive_config_groups[i]-desc);
+head = get_param_infolist(drive_config_groups[i]-desc);
 } else {
-cur = query_option_descs(drive_config_groups[i]-desc);
+cur = get_param_infolist(drive_config_groups[i]-desc);
 connect_infolist(head, cur);
 }
 }
@@ -147,7 +147,7 @@ CommandLineOptionInfoList 
*qmp_query_command_line_options(bool has_option,
 info-parameters = get_drive_infolist();
 } else {
 info-parameters =
-query_option_descs(vm_config_groups[i]-desc);
+get_param_infolist(vm_config_groups[i]-desc);
 }
 entry = g_malloc0(sizeof(*entry));
 entry-value = info;
-- 
1.8.5.3

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


[libvirt] [PATCH] spec: move some dirs into appropriate subpackages

2014-03-05 Thread Michael Chapman
This commit moves a few directories into more appropriate subpackages.
In a few cases a directory is owned by two subpackages, however this is
OK as long as the permissions and ownership for the directory are
consistent between them.

- %{_sysconfdir}/libvirt/qemu/

  Used by the qemu and network drivers.

  When building with separate driver modules, this directory is only
  owned by l-d-d-network. l-d-d-qemu has a hard dependency on
  l-d-d-network, which means this directory is created with the
  correct permissions and ownership, however it's clearer if both
  subpackages own the directory independently.

- %{_sysconfdir}/libvirt/nwfilter/

  Used by the nwfilter driver only.

  This directory is currently always owned by libvirt-daemon. This
  commit moves it into l-d-d-nwfilter when building with separate
  driver modules.

- %{_localstatedir}/run/libvirt/network/

  Used by the network and nwfilter drivers.

  When building without separate driver modules, this directory is
  should be owned by libvirt-daemon only if either of these drivers
  are enabled. When building with separate driver modules, this
  directory should be owned by l-d-d-nwfilter in addition to
  l-d-d-network.

- %{_datadir}/libvirt/networks/ and
  %{_datadir}/libvirt/networks/default.xml

  Used only by the %post scriptlet in libvirt-daemon-config-network.

Signed-off-by: Michael Chapman m...@very.puzzling.org
---
 libvirt.spec.in | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 014fe5d..ac71db0 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1837,10 +1837,6 @@ exit 0
 
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/
 
-%if %{with_nwfilter}
-%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/nwfilter/
-%endif
-
 %if %{with_systemd}
 %{_unitdir}/libvirtd.service
 %{_unitdir}/virtlockd.service
@@ -1903,16 +1899,21 @@ exit 0
 %{_mandir}/man8/virtlockd.8*
 
 %if ! %{with_driver_modules}
-%if %{with_network}
+%if %{with_network} || %{with_qemu}
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/
+%endif
+%if %{with_network} || %{with_nwfilter}
+%ghost %dir %{_localstatedir}/run/libvirt/network/
+%endif
+%if %{with_network}
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/autostart
-%dir %{_datadir}/libvirt/networks/
-%{_datadir}/libvirt/networks/default.xml
-%ghost %dir %{_localstatedir}/run/libvirt/network/
 %dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/network/
 %dir %attr(0755, root, root) %{_localstatedir}/lib/libvirt/dnsmasq/
 %endif
+%if %{with_nwfilter}
+%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/nwfilter/
+%endif
 %if %{with_storage_disk}
 %attr(0755, root, root) %{_libexecdir}/libvirt_parthelper
 %endif
@@ -1958,6 +1959,8 @@ exit 0
 %if %{with_network}
 %files daemon-config-network
 %defattr(-, root, root)
+%dir %{_datadir}/libvirt/networks/
+%{_datadir}/libvirt/networks/default.xml
 %endif
 
 %if %{with_nwfilter}
@@ -1979,8 +1982,6 @@ exit 0
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/
 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/autostart
-%dir %{_datadir}/libvirt/networks/
-%{_datadir}/libvirt/networks/default.xml
 %ghost %dir %{_localstatedir}/run/libvirt/network/
 %dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/network/
 %dir %attr(0755, root, root) %{_localstatedir}/lib/libvirt/dnsmasq/
@@ -1996,6 +1997,8 @@ exit 0
 %if %{with_nwfilter}
 %files daemon-driver-nwfilter
 %defattr(-, root, root)
+%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/nwfilter/
+%ghost %dir %{_localstatedir}/run/libvirt/network/
 %{_libdir}/%{name}/connection-driver/libvirt_driver_nwfilter.so
 %endif
 
@@ -2015,6 +2018,7 @@ exit 0
 %if %{with_qemu}
 %files daemon-driver-qemu
 %defattr(-, root, root)
+%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/
 %dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/qemu/
 %config(noreplace) %{_sysconfdir}/libvirt/qemu.conf
 %config(noreplace) %{_sysconfdir}/libvirt/qemu-lockd.conf
-- 
1.8.5.3

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


[libvirt] [PATCH 3/4] virIdentityGetSystem: don't fail if SELinux is disabled

2014-03-05 Thread Michael Chapman
If SELinux is compiled into libvirt but it is disabled on the host,
libvirtd logs:

  error : virIdentityGetSystem:173 : Unable to lookup SELinux process
  context: Invalid argument

on each and every client connection.

Use is_selinux_enabled() to skip retrieval of the process's SELinux
context if SELinux is disabled.

Signed-off-by: Michael Chapman m...@very.puzzling.org
---
 src/util/viridentity.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/util/viridentity.c b/src/util/viridentity.c
index 4f5127c..bd6adcf 100644
--- a/src/util/viridentity.c
+++ b/src/util/viridentity.c
@@ -168,16 +168,18 @@ virIdentityPtr virIdentityGetSystem(void)
 goto cleanup;
 
 #if WITH_SELINUX
-if (getcon(con)  0) {
-virReportSystemError(errno, %s,
- _(Unable to lookup SELinux process context));
-goto cleanup;
-}
-if (VIR_STRDUP(seccontext, con)  0) {
+if (is_selinux_enabled()) {
+if (getcon(con)  0) {
+virReportSystemError(errno, %s,
+ _(Unable to lookup SELinux process 
context));
+goto cleanup;
+}
+if (VIR_STRDUP(seccontext, con)  0) {
+freecon(con);
+goto cleanup;
+}
 freecon(con);
-goto cleanup;
 }
-freecon(con);
 #endif
 
 if (!(ret = virIdentityNew()))
-- 
1.8.5.3

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


[libvirt] [PATCH 2/4] tests: SELinux tests do not need to be skipped

2014-03-05 Thread Michael Chapman
With the previous commit's securityselinuxhelper enhancements, the
SELinux security manager can be tested even without SELinux enabled on
the test system.

Signed-off-by: Michael Chapman m...@very.puzzling.org
---
 tests/securityselinuxlabeltest.c | 3 ---
 tests/securityselinuxtest.c  | 3 ---
 2 files changed, 6 deletions(-)

diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c
index f98033d..3505f8c 100644
--- a/tests/securityselinuxlabeltest.c
+++ b/tests/securityselinuxlabeltest.c
@@ -322,9 +322,6 @@ mymain(void)
 
 if (!(mgr = virSecurityManagerNew(selinux, QEMU, false, true, false))) 
{
 virErrorPtr err = virGetLastError();
-if (err-code == VIR_ERR_CONFIG_UNSUPPORTED)
-return EXIT_AM_SKIP;
-
 fprintf(stderr, Unable to initialize security driver: %s\n,
 err-message);
 return EXIT_FAILURE;
diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c
index 99b9b24..feb5366 100644
--- a/tests/securityselinuxtest.c
+++ b/tests/securityselinuxtest.c
@@ -272,9 +272,6 @@ mymain(void)
 
 if (!(mgr = virSecurityManagerNew(selinux, QEMU, false, true, false))) 
{
 virErrorPtr err = virGetLastError();
-if (err-code == VIR_ERR_CONFIG_UNSUPPORTED)
-return EXIT_AM_SKIP;
-
 fprintf(stderr, Unable to initialize security driver: %s\n,
 err-message);
 return EXIT_FAILURE;
-- 
1.8.5.3

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


[libvirt] [PATCH 0/4] Fix for virIdentityGetSystem when SELinux is disabled

2014-03-05 Thread Michael Chapman
If SELinux is compiled into libvirt but it is disabled on the host, libvirtd
logs:

  error : virIdentityGetSystem:173 : Unable to lookup SELinux process
  context: Invalid argument

on each and every client connection.

This patch series adds a runtime check for SELinux to this function.

I've added security_disable() to securityselinuxhelper so virIdentityGetSystem
can be tested twice, once with SELinux enabled and once with it disabled. A few
other libselinux functions have also been added, so now
securityselinuxlabeltest and securityselinuxtest do not need to be skipped even
when SELinux isn't enabled on the test system.

Michael Chapman (4):
  tests: Flesh out securityselinuxhelper
  tests: SELinux tests do not need to be skipped
  virIdentityGetSystem: don't fail if SELinux is disabled
  tests: Test virIdentityGetSystem

 src/util/viridentity.c |  18 ++-
 tests/Makefile.am  |   4 +
 tests/securityselinuxhelper.c  | 162 -
 tests/securityselinuxhelperdata/lxc_contexts   |   5 +
 .../virtual_domain_context |   2 +
 .../virtual_image_context  |   2 +
 tests/securityselinuxlabeltest.c   |   3 -
 tests/securityselinuxtest.c|   3 -
 tests/viridentitytest.c|  75 +-
 9 files changed, 254 insertions(+), 20 deletions(-)
 create mode 100644 tests/securityselinuxhelperdata/lxc_contexts
 create mode 100644 tests/securityselinuxhelperdata/virtual_domain_context
 create mode 100644 tests/securityselinuxhelperdata/virtual_image_context

-- 
1.8.5.3

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


[libvirt] [PATCH 1/4] tests: Flesh out securityselinuxhelper

2014-03-05 Thread Michael Chapman
Add fake implementations of:

- is_selinux_enabled
- security_disable
- selinux_virtual_domain_context_path
- selinux_virtual_image_context_path
- selinux_lxc_contexts_path
- selabel_open
- selabel_close
- selabel_lookup_raw

The selabel_* functions back onto the real implementations if SELinux is
enabled on the test system, otherwise we just implement a fake selabel
handle which errors out on all labelling lookups.

With these changes in place, securityselinuxtest and
securityselinuxlabeltest don't need to skip all tests if SELinux isn't
available; they can exercise much of the security manager code.

Signed-off-by: Michael Chapman m...@very.puzzling.org
---
 tests/securityselinuxhelper.c  | 162 -
 tests/securityselinuxhelperdata/lxc_contexts   |   5 +
 .../virtual_domain_context |   2 +
 .../virtual_image_context  |   2 +
 4 files changed, 166 insertions(+), 5 deletions(-)
 create mode 100644 tests/securityselinuxhelperdata/lxc_contexts
 create mode 100644 tests/securityselinuxhelperdata/virtual_domain_context
 create mode 100644 tests/securityselinuxhelperdata/virtual_image_context

diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c
index d996825..703381c 100644
--- a/tests/securityselinuxhelper.c
+++ b/tests/securityselinuxhelper.c
@@ -28,6 +28,9 @@
 # include linux/magic.h
 #endif
 #include selinux/selinux.h
+#if HAVE_SELINUX_LABEL_H
+# include selinux/label.h
+#endif
 #include stdio.h
 #include stdlib.h
 #include string.h
@@ -39,10 +42,32 @@
 # define NFS_SUPER_MAGIC 0x6969
 #endif
 
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+#include viralloc.h
 #include virstring.h
 
 static int (*realstatfs)(const char *path, struct statfs *buf);
 static int (*realsecurity_get_boolean_active)(const char *name);
+static int (*realis_selinux_enabled)(void);
+
+static const char *(*realselinux_virtual_domain_context_path)(void);
+static const char *(*realselinux_virtual_image_context_path)(void);
+
+#ifdef HAVE_SELINUX_LXC_CONTEXTS_PATH
+static const char *(*realselinux_lxc_contexts_path)(void);
+#endif
+
+#if HAVE_SELINUX_LABEL_H
+static struct selabel_handle *(*realselabel_open)(unsigned int backend,
+  struct selinux_opt *opts,
+  unsigned nopts);
+static void (*realselabel_close)(struct selabel_handle *handle);
+static int (*realselabel_lookup_raw)(struct selabel_handle *handle,
+ security_context_t *con,
+ const char *key,
+ int type);
+#endif
 
 static void init_syms(void)
 {
@@ -59,6 +84,20 @@ static void init_syms(void)
 
 LOAD_SYM(statfs);
 LOAD_SYM(security_get_boolean_active);
+LOAD_SYM(is_selinux_enabled);
+
+LOAD_SYM(selinux_virtual_domain_context_path);
+LOAD_SYM(selinux_virtual_image_context_path);
+
+#ifdef HAVE_SELINUX_LXC_CONTEXTS_PATH
+LOAD_SYM(selinux_lxc_contexts_path);
+#endif
+
+#if HAVE_SELINUX_LABEL_H
+LOAD_SYM(selabel_open);
+LOAD_SYM(selabel_close);
+LOAD_SYM(selabel_lookup_raw);
+#endif
 
 #undef LOAD_SYM
 }
@@ -76,12 +115,16 @@ static void init_syms(void)
 
 int getcon_raw(security_context_t *context)
 {
-if (getenv(FAKE_CONTEXT) == NULL) {
+if (!is_selinux_enabled()) {
+errno = EINVAL;
+return -1;
+}
+if (getenv(FAKE_SELINUX_CONTEXT) == NULL) {
 *context = NULL;
 errno = EINVAL;
 return -1;
 }
-return VIR_STRDUP_QUIET(*context, getenv(FAKE_CONTEXT));
+return VIR_STRDUP_QUIET(*context, getenv(FAKE_SELINUX_CONTEXT));
 }
 
 int getcon(security_context_t *context)
@@ -91,17 +134,21 @@ int getcon(security_context_t *context)
 
 int getpidcon_raw(pid_t pid, security_context_t *context)
 {
+if (!is_selinux_enabled()) {
+errno = EINVAL;
+return -1;
+}
 if (pid != getpid()) {
 *context = NULL;
 errno = ESRCH;
 return -1;
 }
-if (getenv(FAKE_CONTEXT) == NULL) {
+if (getenv(FAKE_SELINUX_CONTEXT) == NULL) {
 *context = NULL;
 errno = EINVAL;
 return -1;
 }
-return VIR_STRDUP_QUIET(*context, getenv(FAKE_CONTEXT));
+return VIR_STRDUP_QUIET(*context, getenv(FAKE_SELINUX_CONTEXT));
 }
 
 int getpidcon(pid_t pid, security_context_t *context)
@@ -111,7 +158,11 @@ int getpidcon(pid_t pid, security_context_t *context)
 
 int setcon_raw(security_context_t context)
 {
-return setenv(FAKE_CONTEXT, context, 1);
+if (!is_selinux_enabled()) {
+errno = EINVAL;
+return -1;
+}
+return setenv(FAKE_SELINUX_CONTEXT, context, 1);
 }
 
 int setcon(security_context_t context)
@@ -178,9 +229,28 @@ int statfs(const char *path, struct statfs *buf)
 return ret;
 }
 
+int is_selinux_enabled(void)
+{
+return getenv(FAKE_SELINUX_DISABLED) == NULL;
+}
+
+int 

[libvirt] [PATCH 4/4] tests: Test virIdentityGetSystem

2014-03-05 Thread Michael Chapman
Test it once with SELinux enabled and once with it disabled.

Signed-off-by: Michael Chapman m...@very.puzzling.org
---
 tests/Makefile.am   |  4 +++
 tests/viridentitytest.c | 75 -
 2 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index cd91734..acc9e26 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -779,6 +779,10 @@ virstoragetest_LDADD = $(LDADDS)
 viridentitytest_SOURCES = \
viridentitytest.c testutils.h testutils.c
 viridentitytest_LDADD = $(LDADDS)
+if WITH_SELINUX
+viridentitytest_DEPENDENCIES = libsecurityselinuxhelper.la \
+   ../src/libvirt.la
+endif WITH_SELINUX
 
 virkeycodetest_SOURCES = \
virkeycodetest.c testutils.h testutils.c
diff --git a/tests/viridentitytest.c b/tests/viridentitytest.c
index 814db4f..9fcdcd3 100644
--- a/tests/viridentitytest.c
+++ b/tests/viridentitytest.c
@@ -22,6 +22,10 @@
 
 #include stdlib.h
 
+#if WITH_SELINUX
+# include selinux/selinux.h
+#endif
+
 #include testutils.h
 
 #include viridentity.h
@@ -148,7 +152,7 @@ static int testIdentityEqual(const void *data 
ATTRIBUTE_UNUSED)
 goto cleanup;
 
 if (virIdentityIsEqual(identa, identb)) {
-VIR_DEBUG(Mis-atched identities should not be equal);
+VIR_DEBUG(Mis-matched identities should not be equal);
 goto cleanup;
 }
 
@@ -159,17 +163,86 @@ cleanup:
 return ret;
 }
 
+static int testIdentityGetSystem(const void *data)
+{
+const char *context = data;
+int ret = -1;
+virIdentityPtr ident = NULL;
+const char *val;
+
+#if !WITH_SELINUX
+if (context) {
+VIR_DEBUG(libvirt not compiled with SELinux, skipping this test);
+ret = EXIT_AM_SKIP;
+goto cleanup;
+}
+#endif
+
+if (!(ident = virIdentityGetSystem())) {
+VIR_DEBUG(Unable to get system identity);
+goto cleanup;
+}
+
+if (virIdentityGetAttr(ident,
+   VIR_IDENTITY_ATTR_SELINUX_CONTEXT,
+   val)  0)
+goto cleanup;
+
+if (STRNEQ_NULLABLE(val, context)) {
+VIR_DEBUG(Unexpected SELinux context attribute);
+goto cleanup;
+}
+
+ret = 0;
+cleanup:
+virObjectUnref(ident);
+return ret;
+}
+
+static int testSetFakeSELinuxContext(const void *data ATTRIBUTE_UNUSED)
+{
+#if WITH_SELINUX
+return setcon_raw((security_context_t)data);
+#else
+VIR_DEBUG(libvirt not compiled with SELinux, skipping this test);
+return EXIT_AM_SKIP;
+#endif
+}
+
+static int testDisableFakeSELinux(const void *data ATTRIBUTE_UNUSED)
+{
+#if WITH_SELINUX
+return security_disable();
+#else
+VIR_DEBUG(libvirt not compiled with SELinux, skipping this test);
+return EXIT_AM_SKIP;
+#endif
+}
+
 static int
 mymain(void)
 {
+const char *context = unconfined_u:unconfined_r:unconfined_t:s0;
 int ret = 0;
 
 if (virtTestRun(Identity attributes , testIdentityAttrs, NULL)  0)
 ret = -1;
 if (virtTestRun(Identity equality , testIdentityEqual, NULL)  0)
 ret = -1;
+if (virtTestRun(Setting fake SELinux context , 
testSetFakeSELinuxContext, context)  0)
+ret = -1;
+if (virtTestRun(System identity (fake SELinux enabled) , 
testIdentityGetSystem, context)  0)
+ret = -1;
+if (virtTestRun(Disabling fake SELinux , testDisableFakeSELinux, NULL)  
0)
+ret = -1;
+if (virtTestRun(System identity (fake SELinux disabled) , 
testIdentityGetSystem, NULL)  0)
+ret = -1;
 
 return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
+#if WITH_SELINUX
+VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir 
/.libs/libsecurityselinuxhelper.so)
+#else
 VIRT_TEST_MAIN(mymain)
+#endif
-- 
1.8.5.3

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


Re: [libvirt] Python-libvirt in a virtual environment.

2014-03-05 Thread Sijo Jose
@Michel
using virtualenv we can create an isolated environment in the system.
Just go through - http://docs.python-guide.org/en/latest/dev/virtualenvs/
@Eric
I'm using Ubuntu, and I was able to install and use libvirt using sudo
apt-get install python-libvirt but its not available in tg2 virtual
environment.

Moreover if you try to install in the virtualenv using the sudo apt-get
install python-libvirt, it would say  the package is been already installed.







On Wed, Mar 5, 2014 at 6:51 PM, Eric Blake ebl...@redhat.com wrote:

 On 03/05/2014 05:34 AM, Sijo Jose wrote:
  Hi,
  Could you guide me to install libvirt in a virtual environment..?
  OR
  How python-libvirt could be used within a virtual environment after
  installing it, in the system.

 Same way as in a non-virtual system.  For example, if your virtual
 environment is using Fedora, then 'yum install libvirt-client
 libvirt-python', then using it is as simple as:

 $ python
  import libvirt
  conn = libvirt.open(...)
 ... use conn

 where the URI you pass to libvirt.open is whatever needed to connect to
 the machine where your guests are running, such as qemu://host/system.

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


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

Re: [libvirt] Python-libvirt in a virtual environment.

2014-03-05 Thread Roman Bogorodskiy
  Sijo Jose wrote:

 @Michel
 using virtualenv we can create an isolated environment in the system.
 Just go through - http://docs.python-guide.org/en/latest/dev/virtualenvs/
 @Eric
 I'm using Ubuntu, and I was able to install and use libvirt using sudo
 apt-get install python-libvirt but its not available in tg2 virtual
 environment.
 
 Moreover if you try to install in the virtualenv using the sudo apt-get
 install python-libvirt, it would say  the package is been already installed.

apt-get operates with system-level packages, so there's no
difference if you run it from virtualenv or not.

I think you have two options:

- Install python-libvirt and create virtualenv with
  --system-site-packages [1] so it pulls system python-libvirt

- Activate virtualenv and install python-libvirt using pip

1: 
http://virtualenv.readthedocs.org/en/latest/virtualenv.html#the-system-site-packages-option

Roman Bogorodskiy

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


Re: [libvirt] Release of libvirt-1.2.2

2014-03-05 Thread Jason Helfman
On Sun, Mar 2, 2014 at 7:26 AM, Daniel Veillard veill...@redhat.com wrote:

  As planned I have tagged libvirt-1.2.2 in git and it seem the git tree
 finally updated despite the horrible network I get in china ATM, the
 tarballs may finally arrive at some time too at the usual place after
 working around the local infrastructure flaws... :
   ftp://libvirt.org/libvirt/

  I am also pushing a libvirt-python-1.2.2 update at:
   ftp://libvirt.org/libvirt/libvirt/


I get this breakage on libvirt 1.2.2 for FreeBSD.

  CCLD libvirt_iohelper
  CC   locking/virtlockd-lock_daemon.o
  CC   locking/virtlockd-lock_daemon_config.o
  CC   locking/virtlockd-lock_daemon_dispatch.o
  CC   locking/virtlockd-lock_protocol.o
  CCLD virtlockd
  GEN  virtlockd.8
gmake[3]: *** No rule to make target `test_libvirt_lockd.aug', needed by
`all-am'.  Stop.
gmake[3]: Leaving directory
`/usr/home/helfman/workspace/redports/devel/libvirt/work/libvirt-1.2.2/src'
gmake[2]: *** [all] Error 2
gmake[2]: Leaving directory
`/usr/home/helfman/workspace/redports/devel/libvirt/work/libvirt-1.2.2/src'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory
`/usr/home/helfman/workspace/redports/devel/libvirt/work/libvirt-1.2.2'
gmake: *** [all] Error 2
*** [do-build] Error code 1

Any ideas?

https://redports.org/buildarchive/20140306065501-14242/

Here is a link to a tarball of one of the build directories.
https://redports.org/~jgh/20140306065501-14242-181603/libvirt-1.2.2.tbz

-jgh

-- 
Jason Helfman  | FreeBSD Committer
j...@freebsd.org | http://people.freebsd.org/~jgh  | The Power to Serve
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] Release of libvirt-1.2.2

2014-03-05 Thread Roman Bogorodskiy
  Jason Helfman wrote:

[libvirt-announce@ CCdropped]

 I get this breakage on libvirt 1.2.2 for FreeBSD.
 
   CCLD libvirt_iohelper
   CC   locking/virtlockd-lock_daemon.o
   CC   locking/virtlockd-lock_daemon_config.o
   CC   locking/virtlockd-lock_daemon_dispatch.o
   CC   locking/virtlockd-lock_protocol.o
   CCLD virtlockd
   GEN  virtlockd.8
 gmake[3]: *** No rule to make target `test_libvirt_lockd.aug', needed by
 `all-am'.  Stop.
 gmake[3]: Leaving directory
 `/usr/home/helfman/workspace/redports/devel/libvirt/work/libvirt-1.2.2/src'
 gmake[2]: *** [all] Error 2
 gmake[2]: Leaving directory
 `/usr/home/helfman/workspace/redports/devel/libvirt/work/libvirt-1.2.2/src'
 gmake[1]: *** [all-recursive] Error 1
 gmake[1]: Leaving directory
 `/usr/home/helfman/workspace/redports/devel/libvirt/work/libvirt-1.2.2'
 gmake: *** [all] Error 2
 *** [do-build] Error code 1
 
 Any ideas?
 
 https://redports.org/buildarchive/20140306065501-14242/
 
 Here is a link to a tarball of one of the build directories.
 https://redports.org/~jgh/20140306065501-14242-181603/libvirt-1.2.2.tbz
 
 -jgh

Looks like build is broken with qemu driver disabled.

This fixes it for me:

diff --git a/src/Makefile.am b/src/Makefile.am
index 25d0370..b35dc65 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1757,7 +1757,9 @@ if WITH_QEMU
 test_libvirt_lockd.aug: locking/test_libvirt_lockd.aug.in \
locking/qemu-lockd.conf $(AUG_GENTEST)
$(AM_V_GEN)$(AUG_GENTEST) locking/qemu-lockd.conf $ $@
-endif WITH_QEMU
+else ! WITH_QEMU
+test_libvirt_lockd.aug:
+endif ! WITH_QEMU
 
 test_virtlockd.aug: locking/test_virtlockd.aug.in \
locking/virtlockd.conf $(AUG_GENTEST)

You'll need to regenerate Makefile.in to get it fixed.

Or, if you don't want to bother with autotools, there's a workaround to
try:

In src/Makefile.in, find a piece like that:

@WITH_QEMU_TRUE@test_libvirt_lockd.aug: locking/test_libvirt_lockd.aug.in \

After this block, add:

@WITH_QEMU_FALSE@test_libvirt_lockd.aug:

And re-run configure. Does it work?

Roman Bogorodskiy

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