[libvirt] [PATCH] manual: Add virsh manual about specified migration host

2014-05-29 Thread Chen Fan
the 'migration_host' description maybe have a bit of difficulty to
understand for user, so add this manual for them.

Signed-off-by: Chen Fan 
---
 tools/virsh.pod | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/virsh.pod b/tools/virsh.pod
index de9a4f7..8d77a2f 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1238,6 +1238,11 @@ seen from the source machine.
 
 When I is not specified, libvirt will automatically determine the
 hypervisor specific URI, by looking up the target host's configured hostname.
+In particular, some hypervisors support having this migration hostname 
specified
+separately by setting 'migration_host' in definition file, if 'migration_host'
+is specified, the hostname or IP address will be used to as the default 
I
+while running migration from source host. if 'migration_host' is not specified,
+the migration hostname is set to the host's configured hostname by default.
 There are a few scenarios where specifying I may help:
 
 =over 4
@@ -1251,7 +1256,9 @@ explicitly specified, using an IP address, or a correct 
hostname.
 interfaces, it might be desirable for the migration data stream to be sent over
 a specific interface for either security or performance reasons.  In this case
 I should be explicitly specified, using an IP address associated
-with the network to be used.
+with the network to be used. In particular, Some hypervisors could be easy to
+specify the default network interface by setting 'migration_host'. then the
+I can be omitted.
 
 =item * The firewall restricts what ports are available.  When libvirt 
generates
 a migration URI, it will pick a port number using hypervisor specific rules.
-- 
1.9.3

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


[libvirt] Libvrt Migrate an Offline VM

2014-05-29 Thread Sijo Jose
Hi,

Is it possible to migrate an Offline VM using libvirt API ?

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

Re: [libvirt] [PATCH] Don't use AI_ADDRCONFIG when binding to wildcard addresses

2014-05-29 Thread Ján Tomko
On 05/29/2014 04:47 PM, Eric Blake wrote:
> On 05/29/2014 03:32 AM, Ján Tomko wrote:
>> https://bugzilla.redhat.com/show_bug.cgi?id=1098659
>>
>> With parallel boot, network addresses might not yet be assigned [1],
>> but binding to wildcard addresses should work.
>>
>> For non-wildcard addresses, ADDRCONFIG is still used. Document this
>> in libvirtd.conf.
>>
>> [1] http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
>> ---
> 
>> -hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
>> +hints.ai_flags = AI_PASSIVE;
>>  hints.ai_socktype = SOCK_STREAM;
>>  
>> +/* Don't use ADDRCONFIG for binding to the wildcard address.
>> + * Just catch the error returned by socket() if the system has
>> + * no IPv6 support.
>> + *
>> + * This allows libvirtd to be started in parallel with the network
>> + * startup in most cases.
>> + */
>> +if (nodename &&
>> +!(virSocketAddrParse(&tmp_addr, nodename, AF_UNSPEC) > 0 &&
>> +  virSocketAddrIsWildcard(&tmp_addr)))
>> +hints.ai_flags = AI_ADDRCONFIG;
> 
> Shouldn't this be |= ?
> 

Functionally it's the same, AI_PASSIVE is ignored if nodename is non-NULL.

But it should be |= if we were using other flags.

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] GSoC student introduction and work plan

2014-05-29 Thread Taowei Luo
Thanks, I will keep this in mind when I submit patches.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] Availability of release candidate 2 of libvirt-1.2.5

2014-05-29 Thread Daniel Veillard
  1.2.5-rc2 is now tagged in git and tarball and signed rpms are
also available at the usual place:

  ftp://libvirt.org/libvirt/

 Still seems to work with my minimal testing, so if there is no
serious issue raised we're probably good for a release over the
w.e. or monday morning !

  But please push it a bit more than me :) and report issues you
may find !

Daniel

-- 
Daniel Veillard  | Open Source and Standards, Red Hat
veill...@redhat.com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | virtualization library  http://libvirt.org/

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


Re: [libvirt] [PATCH 1/2] libxl: Implement basic video device selection

2014-05-29 Thread Jim Fehlig
Hi Stefan,

Thanks for the patches, sorry for the delay...

Stefan Bader wrote:
> This started as an investigation into an issue where libvirt (using the
> libxl driver) and the Xen host, like an old couple, could not agree on
> who is responsible for selecting the VNC port to use.
>
> Things usually (and a bit surprisingly) did work because, just like that
> old couple, they had the same idea on what to do by default. However it
> was possible that this ended up in a big argument.
>
> The problem is that display information exists in two different places:
> in the vfbs list and in the build info. And for launching the device model,
> only the latter is used. But that never gets initialized from libvirt. So
> Xen allows the device model to select a default port while libvirt thinks
> it has told Xen that this is done by libvirt (though the vfbs config).
>
> While fixing that, I made a stab at actually evaluating the configuration
> of the video device. So that it is now possible to at least decide between
> a Cirrus or standard VGA emulation and to modify the VRAM within certain
> limits using libvirt.
>
> [v2: Check return code of VIR_STRDUP and fix indentation]
> [v3: Split out VRAM fixup and return error for unsupported video type]
>
> Signed-off-by: Stefan Bader 
> ---
>  src/libxl/libxl_conf.c |   68 
> 
>  1 file changed, 68 insertions(+)
>
> diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
> index b7fed7f..2b5c469 100644
> --- a/src/libxl/libxl_conf.c
> +++ b/src/libxl/libxl_conf.c
> @@ -1304,6 +1304,64 @@ libxlMakeCapabilities(libxl_ctx *ctx)
>  return NULL;
>  }
>  
> +static int
> +libxlSetBuildGraphics(virDomainDefPtr def, libxl_domain_config *d_config)
> +{
> +libxl_domain_build_info *b_info = &d_config->b_info;
> +
> +/*
> + * Take the first defined video device (graphics card) to display
> + * on the first graphics device (display).
> + * Right now only type and vram info is used and anything beside
> + * type xen and vga is mapped to cirrus.
> + */
> +if (def->nvideos) {
> +switch (def->videos[0]->type) {
> +case VIR_DOMAIN_VIDEO_TYPE_VGA:
> +case VIR_DOMAIN_VIDEO_TYPE_XEN:
> +b_info->u.hvm.vga.kind = LIBXL_VGA_INTERFACE_TYPE_STD;
> +break;
> +case VIR_DOMAIN_VIDEO_TYPE_CIRRUS:
> +b_info->u.hvm.vga.kind = LIBXL_VGA_INTERFACE_TYPE_CIRRUS;
> +break;
> +default:
> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +   "%s",
> +   _("video type not supported by libxl"));
> +return -1;
> +}
> +b_info->video_memkb = def->videos[0]->vram ?
> +  def->videos[0]->vram :
> +  LIBXL_MEMKB_DEFAULT;
> +} else {
> +libxl_defbool_set(&b_info->u.hvm.nographic, 1);
> +}
>   

This part configures a video device.

> +
> +/*
> + * When making the list of displays, only VNC and SDL types were
> + * taken into account. So it seems sensible to connect the default
> + * video device to the first in the vfb list.
> + */
> +if (d_config->num_vfbs) {
> +libxl_device_vfb *vfb0 = &d_config->vfbs[0];
> +
> +b_info->u.hvm.vnc = vfb0->vnc;
> +if (VIR_STRDUP(b_info->u.hvm.vnc.listen, vfb0->vnc.listen) < 0)
> +return -1;
> +if (VIR_STRDUP(b_info->u.hvm.vnc.passwd, vfb0->vnc.passwd) < 0)
> +return -1;
> +b_info->u.hvm.sdl = vfb0->sdl;
> +if (VIR_STRDUP(b_info->u.hvm.sdl.display, vfb0->sdl.display) < 0)
> +return -1;
> +if (VIR_STRDUP(b_info->u.hvm.sdl.xauthority, vfb0->sdl.xauthority) < 
> 0)
> +return -1;
> +if (VIR_STRDUP(b_info->u.hvm.keymap, vfb0->keymap) < 0)
> +return -1;
> +}
> +
> +return 0;
> +}
>   

And this part configures a frame buffer. I think it would be better for
this part to be in libxlMakeVfbList(), similar to commit b55cc5f4. This
function then becomes libxlMakeVideo(), continuing the libxlMake
pattern.

Regards,
Jim

> +
>  int
>  libxlBuildDomainConfig(libxlDriverPrivatePtr driver,
> virDomainObjPtr vm, libxl_domain_config *d_config)
> @@ -1331,6 +1389,16 @@ libxlBuildDomainConfig(libxlDriverPrivatePtr driver,
>  if (libxlMakePCIList(def, d_config) < 0)
>  return -1;
>  
> +/*
> + * Now that any potential VFBs are defined, it is time to update the
> + * build info with the data of the primary display. Some day libxl
> + * might implicitely do so but as it does not right now, better be
> + * explicit.
> + */
> +if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM)
> +if (libxlSetBuildGraphics(def, d_config) < 0)
> +return -1;
> +
>  d_config->on_reboot = def->onReboot;
>  d_config->o

Re: [libvirt] [PATCH 2/2] libxl: Fix up VRAM to minimum requirements

2014-05-29 Thread Jim Fehlig
Stefan Bader wrote:
> This is a bit debatable. On one side it hides configuration errors
> in a way that makes them hard to spot. On the other side there is
> at least one issue with (maybe some older versions) virt-manager.
> Virt-manager sets VRAM directly, not using the default memory setting
> but uses too small values for libxl.

It sounds like virt-manager should be fixed. I don't think the libxl
driver should contain this type of policy. It could report errors on
user-supplied configuration known not to work with libxl, but I don't
think it should be silently changing the configuration.

Regards,
Jim

>  Worse, those versions do not seem
> to allow to change VRAM from the GUI. So switching the video type to
> VGA makes the guest fail to start until one manually adapts the VRAM
> size in the XML definition.
> With this change this would not happen but VRAM will be bigger than
> the GUI says. This would not be that different from current Cirrus
> behaviour. Only that in that case qemu seems to ignore the provided
> size.
>
> Signed-off-by: Stefan Bader 
> ---
>  src/libxl/libxl_conf.c |   27 ++-
>  1 file changed, 26 insertions(+), 1 deletion(-)
>
> diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
> index 2b5c469..9af8abe 100644
> --- a/src/libxl/libxl_conf.c
> +++ b/src/libxl/libxl_conf.c
> @@ -1316,13 +1316,38 @@ libxlSetBuildGraphics(virDomainDefPtr def, 
> libxl_domain_config *d_config)
>   * type xen and vga is mapped to cirrus.
>   */
>  if (def->nvideos) {
> +unsigned int min_vram = 8 * 1024;
> +
>  switch (def->videos[0]->type) {
>  case VIR_DOMAIN_VIDEO_TYPE_VGA:
>  case VIR_DOMAIN_VIDEO_TYPE_XEN:
>  b_info->u.hvm.vga.kind = LIBXL_VGA_INTERFACE_TYPE_STD;
> +/*
> + * Libxl enforces a minimal VRAM size of 8M when using
> + * LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL or
> + * 16M for LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN.
> + * Avoid build failures and go with the minimum if less
> + * is specified.
> + */
> +switch (b_info->device_model_version) {
> +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
> +min_vram = 8 * 1024;
> +break;
> +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
> +default:
> +min_vram = 16 * 1024;
> +}
>  break;
>  case VIR_DOMAIN_VIDEO_TYPE_CIRRUS:
>  b_info->u.hvm.vga.kind = LIBXL_VGA_INTERFACE_TYPE_CIRRUS;
> +switch (b_info->device_model_version) {
> +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
> +min_vram = 4 * 1024; /* Actually the max, too */
> +break;
> +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
> +default:
> +min_vram = 8 * 1024;
> +}
>  break;
>  default:
>  virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> @@ -1330,7 +1355,7 @@ libxlSetBuildGraphics(virDomainDefPtr def, 
> libxl_domain_config *d_config)
> _("video type not supported by libxl"));
>  return -1;
>  }
> -b_info->video_memkb = def->videos[0]->vram ?
> +b_info->video_memkb = (def->videos[0]->vram >= min_vram) ?
>def->videos[0]->vram :
>LIBXL_MEMKB_DEFAULT;
>  } else {
>   

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


Re: [libvirt] libvirt: Xen Driver error : Domain not found: xenGetDomainDefForName

2014-05-29 Thread Jim Fehlig


deepanshus wrote:
> Hi,
>  
> I have successfully installed xen 3.11 kernel but when I am running
> the vm I am getting this error:

What version of Xen?  Your problem appears to be more tools or packaging
related, not the kernel.

>  
>
> libvirt: Xen Driver error : Domain not found: xenGetDomainDefForName
>
>  
>
> I am sending the xend log file as well error file as an attachment. 
>
>  
>
>  
>
> Thanks And Regards,
>
>  
>
> Deepanshu Saxena
>
>
> ---
>
> [ C-DAC is on Social-Media too. Kindly follow us at:
> Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ]
>
> This e-mail is for the sole use of the intended recipient(s) and may
> contain confidential and privileged information. If you are not the
> intended recipient, please contact the sender by reply e-mail and destroy
> all copies and the original message. Any unauthorized review, use,
> disclosure, dissemination, forwarding, printing or copying of this email
> is strictly prohibited and appropriate legal action will be taken.
> ---

Please remove this "warning".  libvir-list is a public mail list.

> [2014-05-29 18:16:54 2395] ERROR (XendDomainInfo:488) VM start failed
> Traceback (most recent call last):
>   File "/usr/lib64/python2.6/site-packages/xen/xend/XendDomainInfo.py", line 
> 473, in start
> XendTask.log_progress(0, 30, self._constructDomain)
>   File "/usr/lib64/python2.6/site-packages/xen/xend/XendTask.py", line 209, 
> in log_progress
> retval = func(*args, **kwds)
>   File "/usr/lib64/python2.6/site-packages/xen/xend/XendDomainInfo.py", line 
> 2545, in _constructDomain
> raise VmError("pool %s not activated" % pool_name)
> VmError: pool Pool-0 not activated
> [2014-05-29 18:16:54 2395] ERROR (XendDomainInfo:108) Domain construction 
> failed
> Traceback (most recent call last):
>   File "/usr/lib64/python2.6/site-packages/xen/xend/XendDomainInfo.py", line 
> 106, in create
> vm.start()
>   File "/usr/lib64/python2.6/site-packages/xen/xend/XendDomainInfo.py", line 
> 473, in start
> XendTask.log_progress(0, 30, self._constructDomain)
>   File "/usr/lib64/python2.6/site-packages/xen/xend/XendTask.py", line 209, 
> in log_progress
> retval = func(*args, **kwds)
>   File "/usr/lib64/python2.6/site-packages/xen/xend/XendDomainInfo.py", line 
> 2545, in _constructDomain
> raise VmError("pool %s not activated" % pool_name)
> VmError: pool Pool-0 not activated
>   

Is xenstored running?  My initial thought is that the xencommons init
script has not been started.  Are you using Xen from your distro or
building/installing your own?

Regards,
Jim

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


Re: [libvirt] [Qemu-devel] [PATCHv2 3/4] qemu: fix RTC_CHANGE event for

2014-05-29 Thread Marcelo Tosatti
On Fri, May 23, 2014 at 11:36:56PM +0200, Paolo Bonzini wrote:
> You can get the current time via the qom-get command, and then
> follow the same algorithm as QEMU:
> 
> time_t seconds;
> 
> if (rtc_date_offset == -1) {
> if (rtc_utc) {
> seconds = mktimegm(tm);
> } else {
> struct tm tmp = *tm;
> tmp.tm_isdst = -1; /* use timezone to figure it out */
> seconds = mktime(&tmp);
> }
> } else {
> seconds = mktimegm(tm) + rtc_date_offset;
> }
> return seconds - time(NULL);
> 
> Unfortunately the QOM path to the RTC device is not stable.  We can
> add a /machine/rtc link, and if the PPC guys implement the link and
> current-time property as well, the same mechanism can work for any
> board.
> 
> Paolo

I like that idea. Questions:

- What guarantees are there that the interface is stable?
(you can argue that "now it is").

- Perhaps add /machine/stable/ path to contain stable
links ?

- How do i go about adding a link to a device again?

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


Re: [libvirt] Weekly meeting minutes May 22nd, 2014

2014-05-29 Thread Jim Fehlig
Daniel P. Berrange wrote:
> Agenda + minutes from 22/05/2014
>
>  * Welcome / rollcall
>* IRC comments from:
>* eblake
>* danpb
>* pkrempa
>* derRichard
>* rbogorodskiy
>* mkletzan
>* nehaljwani
>* mprivozn
>
>  * Next release schedule
>* Freeze: Mon May 26th
>* Release: Mon June 2nd
>
>  * Patches needing review
>* pkrempa's gluster patches
>  * 1-27 are nice to have but not release critical
>  * 28+ need to wait for QEMU work
>* eblake's live commit work
>  * minimum need patch to avoid hang with qemu 2.0
>  * remaining patches should rebase on top of pkrempa, even if it
>misses release
>* vbox snapshot patches - been waiting a long time
>* Jim Fehlig has libxl migration patches - probably desired for the
>  release
>   

Sorry I haven't had time to work on a V8.  Stefan Bader also has some
video device improvements for the libxl driver, which I'll get to
reviewing shortly.  Sadly, these will be a bit late for 1.2.5.

Regards,
Jim

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


Re: [libvirt] [libvirt-users] Host OS, Storage Info

2014-05-29 Thread Ainsworth, Thomas
Martin, et al,

Sorry for the lag in response.

So I started playing with the various virsh commands.  Awesome.
Been doing some reading and I believe I have some things configured not so
well.
As I stated earlier in the thread, we have all of the VM image files on one
RAID5.  Very fast machine.

When using top, the load average is a stable "5.xx".  No I/O wait. GB's of
free memory.  Swap has not been touched.
Using vmstat, I am writing to the RAID5 volume at a constant 150MB/s and
reading at a constant 275MB/s.

With all of that said, here are some results from virsh commands:

# virsh pool-list --all
Name State  Autostart
--
default  active yes


# virsh pool-info default
Name:   default
UUID:x
State:  running
Persistent: yes
Autostart:  yes
Capacity:   30.76 GiB
Allocation: 2.10 GiB
Available:  28.66 GiB


Now, is that ok to have all of the VM's using a default pool?
Or should a pool be created for each VM instance.
I honestly am not even sure what a pool references...?...

The more I read, the more I am moving away from thinking something in the
OS is the cause of my sluggishness.

Suggestions?

Many thanks in advance,

Tom






On Thu, May 22, 2014 at 9:16 AM, Martin Kletzander 
wrote:

> On Thu, May 22, 2014 at 12:16:17PM +0530, Sijo Jose wrote:
>
>> Hi,
>> Is there any way to get host OS information and host Storage in formations
>> using libvirt API...?
>> Rgds
>> -Sijo
>>
>
> Check virsh help (most of the commands you probably want start with
> 'node' or 'vol'/'pool') or have a look at our hvsupport page [1] for
> virNode* and virStorage* functions.
>
> If this isn't what you're looking for, specify your question in a
> better way.
>
> Martin
>
> [1] http://libvirt.org/hvsupport.html
>
> ___
> libvirt-users mailing list
> libvirt-us...@redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-users
>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCHv3 1/2] virsh: Reject negative numbers in vshCommandOptUInt

2014-05-29 Thread Eric Blake
On 05/29/2014 05:54 AM, Peter Krempa wrote:
> Use virStrToLong_uip instead of virStrToLong_ui to reject negative
> numbers in the helper. None of the callers expects the wraparound
> "feature" for negative numbers.

I had to audit all callers, and found the following (fortunately the
list is fairly small):

screenshot [screen]: no one can support 4 billion screens, so forbidding
wraparound makes sense

send-key [holdtime]: waiting 4 million seconds between keys is unlikely,
so forbidding wraparound makes sense

qemu-attach [pid]: pid_t is signed, but negative pids have special
meaning and cannot be attached, forbidding wraparound makes sense

node-memory-tune [shm-pages-to-scan, shm-sleep-millisecs,
shm-merge-across-nodes]: I'm not sure any of these make sense as an
unlimited value, so forbidding wraparound makes sense

iface-bridge [delay] unlimited delay does not work, so forbidding
wraparound makes sense

> 
> Also be explicit about the new semantics in the function docs.

Unfortunately, we now have a discrepancy between this command and
vshCommandOptULongLong and vshCommandOptUL.  So let's look at those, too:

blkdeviotune [total-bytes-sec, read-bytes-sec, write-bytes-sec,
total-iops-sec, read-iops-sec, write-iops-sec]: Here, we allow 0 as
unlimited, so it's probably okay to forbid -1 for maximum.

blockpull, blockcommit [bandwidth]: Here, 0 means the default bandwidth,
which is DIFFERENT than maximum bandwidth.  Allowing -1 might make sense.

dompmsuspend [duration]: the universe will go cold before maximum
duration, so forbidding negative wraparound makes sense

migrate-compcache [size]: sizing this larger than the host has memory is
not going to work, so forbidding negative wraparound might make sense

migrate-setspeed [bandwidth]: Here, 0 means the default bandwidth, which
is DIFFERENT than maximum bandwidth.  Allowing -1 might make sense

domfstrim [minimum]: sizing this larger than the biggest possible file
in the host makes the command a no-op, so forbidding negative wraparound
might make sense

vol-upload, vol-download [offset, length]: Can't a negative offset be
treated as offset from the end of the file? And doesn't -1 as implying
unlimited length make sense?  Here, allowing -1 might make sense


> ---
>  tools/virsh.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Either we should change all three functions, or you should make it
possible to allow negative in some cases per my audit above.  Probably
needs a v4.  Based on patch 2/2, it would still be nice to reach
consensus and fix the bug before 1.2.5, but we're cutting it close.

-- 
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/2] qemu: snapshot: Reject internal active snapshot without memory state

2014-05-29 Thread Peter Krempa
On 05/29/14 16:36, Eric Blake wrote:
> On 05/29/2014 03:07 AM, Peter Krempa wrote:
>> A internal snapshot of a active VM with the memory snapshot disabled
>> explicitly would actually still take the memory snapshot. Reject it
>> explicitly.
>>
>> Before:
>>  $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
>> --memspec snapshot=no
>>  Domain snapshot 1401353155 created
>>
>> After:
>>  $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
>> --memspec snapshot=no
>>  error: Operation not supported: internal snapshot of a running VM must 
>> include the memory state
> 
> Technically, qemu 1.7 added blockdev-snapshot-internal-sync, so we CAN
> take internal disk-only snapshots now.  But as that is more complex to
> implement, I agree with this patch as an intermediate fix (and we'll
> still have to keep this code path for qemu 1.6 and earlier, based on a
> qemu_capabilities.h bit).
> 
>>
>> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1083345
>> ---
>>  src/qemu/qemu_driver.c | 9 +
>>  1 file changed, 9 insertions(+)
> 
> ACK, safe for 1.2.5.
> 

Pushed; Thanks.

I'll open a BZ to track the addition.

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 2/2] qemu: snapshot: Improve detection of mixed snapshots

2014-05-29 Thread Peter Krempa
On 05/29/14 16:38, Eric Blake wrote:
> On 05/29/2014 03:08 AM, Peter Krempa wrote:
>> Currently we don't support mixed (external + internal) snapshots. The
>> code detecting the snapshot type didn't make sure that the memory image
>> was consistent with the snapshot type leading into strange error
>> message:
>>
>>  $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
>> --memspec snapshot=external,file=/tmp/blah
>>  error: internal error: unexpected code path
>>
>> Fix the mixed detection code to detect this kind of mistake:
>>
>>  $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
>> --memspec snapshot=external,file=/tmp/blah
>>  error: unsupported configuration: mixing internal and external targets for 
>> a snapshot is not yet supported
> 
> It may still be nice to support some day down the road, but a better
> error message in the meantime is worth having.
> 
>> ---
>>  src/qemu/qemu_driver.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> ACK; safe for 1.2.5.
> 

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

Re: [libvirt] [PATCH] util: storage: Fix crash of libvirtd on network backed guest block-pull

2014-05-29 Thread Peter Krempa
On 05/29/14 16:58, Eric Blake wrote:
> On 05/29/2014 08:52 AM, Peter Krempa wrote:
>> For guests backed by gluster volumes (or other network storage) we don't
>> fill the backing chain (see qemuDomainDetermineDiskChain). This leaves
>> the "relPath" field of the top image NULL. This causes a crash in
>> virStorageFileChainLookup() when looking up a backing element for such a
>> disk.
>>
>> Since I'm working on adding support for network storage and one of the
>> steps will make the "relPath" field optional let's use STREQ_NULLABLE
>> instead of STREQ in virStorageFileChainLookup() to avoid the problem.
>> ---
>>  src/util/virstoragefile.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> ACK, safe for 1.2.5.
> 

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

Re: [libvirt] [PATCH] util: storage: Fix crash of libvirtd on network backed guest block-pull

2014-05-29 Thread Eric Blake
On 05/29/2014 08:52 AM, Peter Krempa wrote:
> For guests backed by gluster volumes (or other network storage) we don't
> fill the backing chain (see qemuDomainDetermineDiskChain). This leaves
> the "relPath" field of the top image NULL. This causes a crash in
> virStorageFileChainLookup() when looking up a backing element for such a
> disk.
> 
> Since I'm working on adding support for network storage and one of the
> steps will make the "relPath" field optional let's use STREQ_NULLABLE
> instead of STREQ in virStorageFileChainLookup() to avoid the problem.
> ---
>  src/util/virstoragefile.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

ACK, safe for 1.2.5.

> 
> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
> index 2feda67..c9b6187 100644
> --- a/src/util/virstoragefile.c
> +++ b/src/util/virstoragefile.c
> @@ -1591,7 +1591,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
>  if (idx == i)
>  break;
>  } else {
> -if (STREQ(name, chain->relPath))
> +if (STREQ_NULLABLE(name, chain->relPath))
>  break;
>  if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE ||
> chain->type == VIR_STORAGE_TYPE_BLOCK)) {
> 

-- 
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 V2] virsh: forbid negative vcpu argument to vcpupin.

2014-05-29 Thread Eric Blake
On 05/29/2014 05:47 AM, Peter Krempa wrote:

> Still not quite right ... vshCommandOptUInt currently wraps negative
> numbers to their 2's complement and stores them in the uint.

I recently tweaked virstring.c to provide virStrToLong_uip and friends
for rejecting negative input when parsing unsigned numbers.

The intent was that we need to make a case-by-case decision on which of
the two parsing styles to use - sometimes, wrapping -1 to max is
desirable, other times it is not.

> 
> We need to modify the vshCommandOptUInt helper to reject negative numbers.

It may mean that we need two flavors of vshCommandOptUInt.

-- 
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 V2] virsh: forbid negative vcpu argument to vcpupin.

2014-05-29 Thread Peter Krempa
On 05/29/14 16:51, Eric Blake wrote:
> On 05/29/2014 05:47 AM, Peter Krempa wrote:
> 
>> Still not quite right ... vshCommandOptUInt currently wraps negative
>> numbers to their 2's complement and stores them in the uint.
> 
> I recently tweaked virstring.c to provide virStrToLong_uip and friends
> for rejecting negative input when parsing unsigned numbers.
> 
> The intent was that we need to make a case-by-case decision on which of
> the two parsing styles to use - sometimes, wrapping -1 to max is
> desirable, other times it is not.
> 
>>
>> We need to modify the vshCommandOptUInt helper to reject negative numbers.
> 
> It may mean that we need two flavors of vshCommandOptUInt.
> 

Actually we don't. All callers of vshCommandOptUInt don't expect to use
the wrap-to-2's-complement "feature". I've sent a V3 that does exactly that.



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

[libvirt] [PATCH] util: storage: Fix crash of libvirtd on network backed guest block-pull

2014-05-29 Thread Peter Krempa
For guests backed by gluster volumes (or other network storage) we don't
fill the backing chain (see qemuDomainDetermineDiskChain). This leaves
the "relPath" field of the top image NULL. This causes a crash in
virStorageFileChainLookup() when looking up a backing element for such a
disk.

Since I'm working on adding support for network storage and one of the
steps will make the "relPath" field optional let's use STREQ_NULLABLE
instead of STREQ in virStorageFileChainLookup() to avoid the problem.
---
 src/util/virstoragefile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 2feda67..c9b6187 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1591,7 +1591,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
 if (idx == i)
 break;
 } else {
-if (STREQ(name, chain->relPath))
+if (STREQ_NULLABLE(name, chain->relPath))
 break;
 if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE ||
chain->type == VIR_STORAGE_TYPE_BLOCK)) {
-- 
1.9.3

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


Re: [libvirt] [PATCH] Don't use AI_ADDRCONFIG when binding to wildcard addresses

2014-05-29 Thread Eric Blake
On 05/29/2014 03:32 AM, Ján Tomko wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1098659
> 
> With parallel boot, network addresses might not yet be assigned [1],
> but binding to wildcard addresses should work.
> 
> For non-wildcard addresses, ADDRCONFIG is still used. Document this
> in libvirtd.conf.
> 
> [1] http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
> ---

> -hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
> +hints.ai_flags = AI_PASSIVE;
>  hints.ai_socktype = SOCK_STREAM;
>  
> +/* Don't use ADDRCONFIG for binding to the wildcard address.
> + * Just catch the error returned by socket() if the system has
> + * no IPv6 support.
> + *
> + * This allows libvirtd to be started in parallel with the network
> + * startup in most cases.
> + */
> +if (nodename &&
> +!(virSocketAddrParse(&tmp_addr, nodename, AF_UNSPEC) > 0 &&
> +  virSocketAddrIsWildcard(&tmp_addr)))
> +hints.ai_flags = AI_ADDRCONFIG;

Shouldn't this be |= ?

Otherwise, it makes sense to me.

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



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

[libvirt] [PATCH v2] qemu: Properly label FDs when restoring domain with static label

2014-05-29 Thread Shivaprasad G Bhat
The restore of a saved image file fails when the selinux context is static.
The libvirt has to set the conext of save image file handle to that of
the guest before handing off the FD to qemu. 

Signed-off-by: Shivaprasad G Bhat 
---
 src/qemu/qemu_process.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 124fe28..47d1f7d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4052,14 +4052,14 @@ int qemuProcessStart(virConnectPtr conn,
  */
 struct stat stdin_sb;
 
-VIR_DEBUG("setting security label on pipe used for migration");
+VIR_DEBUG("setting security label on fd used for migration or 
restore");
 
 if (fstat(stdin_fd, &stdin_sb) < 0) {
 virReportSystemError(errno,
  _("cannot stat fd %d"), stdin_fd);
 goto cleanup;
 }
-if (S_ISFIFO(stdin_sb.st_mode) &&
+if ((S_ISFIFO(stdin_sb.st_mode) || S_ISREG(stdin_sb.st_mode)) &&
 virSecurityManagerSetImageFDLabel(driver->securityManager, 
vm->def, stdin_fd) < 0)
 goto cleanup;
 }

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


Re: [libvirt] libvirt: Xen Driver error : Domain not found: xenGetDomainDefForName

2014-05-29 Thread Eric Blake
[meta-comment]

On 05/29/2014 07:17 AM, deepanshus wrote:
> Hi,
> 
> I have successfully installed xen 3.11 kernel but when I am running the vm I 
> am
> getting this error:
> 
> 
> libvirt: Xen Driver error : Domain not found: xenGetDomainDefForName

Unfortunately, I'm not familiar enough with xen to help with debugging
this issue.  Instead, I'm writing about your signature:

> This e-mail is for the sole use of the intended recipient(s) and may

Disclaimers like this are unenforceable on publicly-archived mailing
lists.  You may want to consider sending from a personal account rather
than one where your employer tacks on bogus legalese.

-- 
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/2] qemu: snapshot: Improve detection of mixed snapshots

2014-05-29 Thread Eric Blake
On 05/29/2014 03:08 AM, Peter Krempa wrote:
> Currently we don't support mixed (external + internal) snapshots. The
> code detecting the snapshot type didn't make sure that the memory image
> was consistent with the snapshot type leading into strange error
> message:
> 
>  $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
> --memspec snapshot=external,file=/tmp/blah
>  error: internal error: unexpected code path
> 
> Fix the mixed detection code to detect this kind of mistake:
> 
>  $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
> --memspec snapshot=external,file=/tmp/blah
>  error: unsupported configuration: mixing internal and external targets for a 
> snapshot is not yet supported

It may still be nice to support some day down the road, but a better
error message in the meantime is worth having.

> ---
>  src/qemu/qemu_driver.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

ACK; safe for 1.2.5.

-- 
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/2] qemu: snapshot: Reject internal active snapshot without memory state

2014-05-29 Thread Eric Blake
On 05/29/2014 03:07 AM, Peter Krempa wrote:
> A internal snapshot of a active VM with the memory snapshot disabled
> explicitly would actually still take the memory snapshot. Reject it
> explicitly.
> 
> Before:
>  $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
> --memspec snapshot=no
>  Domain snapshot 1401353155 created
> 
> After:
>  $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
> --memspec snapshot=no
>  error: Operation not supported: internal snapshot of a running VM must 
> include the memory state

Technically, qemu 1.7 added blockdev-snapshot-internal-sync, so we CAN
take internal disk-only snapshots now.  But as that is more complex to
implement, I agree with this patch as an intermediate fix (and we'll
still have to keep this code path for qemu 1.6 and earlier, based on a
qemu_capabilities.h bit).

> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1083345
> ---
>  src/qemu/qemu_driver.c | 9 +
>  1 file changed, 9 insertions(+)

ACK, safe for 1.2.5.

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



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

[libvirt] libvirt: Xen Driver error : Domain not found: xenGetDomainDefForName

2014-05-29 Thread deepanshus
Hi,

I have successfully installed xen 3.11 kernel but when I am running the vm I am
getting this error:


libvirt: Xen Driver error : Domain not found: xenGetDomainDefForName



I am sending the xend log file as well error file as an attachment.





Thanks And Regards,



Deepanshu Saxena
---
[ C-DAC is on Social-Media too. Kindly follow us at:
Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ]

This e-mail is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. If you are not the
intended recipient, please contact the sender by reply e-mail and destroy
all copies and the original message. Any unauthorized review, use,
disclosure, dissemination, forwarding, printing or copying of this email
is strictly prohibited and appropriate legal action will be taken.
---

Problem with vm-004: Unexpected issue
STDERR: 2014-05-29 18:16:49,865 - WARNING - mount+edit functionality for qcow2 
images is disabled
2014-05-29 18:16:49,867 - WARNING - no qemu_img configuration, copy-on-write 
support is disabled
libvirt: Xen Driver error : Domain not found: xenGetDomainDefForName
libvirt: Xen Daemon error : POST operation failed: xend_post: error from xen 
daemon: (xend.err 'Error creating domain: pool Pool-0 not activated')
2014-05-29 18:16:54,216 - ERROR - Problem creating the VM: POST operation 
failed: xend_post: error from xen daemon: (xend.err 'Error creating domain: 
pool Pool-0 not activated')
2014-05-29 18:16:54,216 - ERROR - POST operation failed: xend_post: error from 
xen daemon: (xend.err 'Error creating domain: pool Pool-0 not activated')
Traceback (most recent call last):
  File "/opt/nimbus/src/python/workspacecontrol/defaults/lvrt/lvrt_common.py", 
line 123, in create
newvm = self._vmm().createXML(xml, 0)
  File "/usr/lib64/python2.6/site-packages/libvirt.py", line 2909, in createXML
if ret is None:raise libvirtError('virDomainCreateXML() failed', conn=self)
libvirtError: POST operation failed: xend_post: error from xen daemon: 
(xend.err 'Error creating domain: pool Pool-0 not activated')
2014-05-29 18:16:54,244 - ERROR - Problem creating the VM: POST operation 
failed: xend_post: error from xen daemon: (xend.err 'Error creating domain: 
pool Pool-0 not activated')
Traceback (most recent call last):
  File "/opt/nimbus/src/python/workspacecontrol/main/wc_core_creation.py", line 
155, in _common_withnetsecurity
_common_withtmplease(nic_set, kernel, local_file_set, c, netsecurity, 
platform, justprint)
  File "/opt/nimbus/src/python/workspacecontrol/main/wc_core_creation.py", line 
174, in _common_withtmplease
platform.create(local_file_set, nic_set, kernel)
  File "/opt/nimbus/src/python/workspacecontrol/defaults/lvrt/lvrt_common.py", 
line 128, in create
raise UnexpectedError(shorterr)
UnexpectedError: Problem creating the VM: POST operation failed: xend_post: 
error from xen daemon: (xend.err 'Error creating domain: pool Pool-0 not 
activated')
2014-05-29 18:16:54,248 - ERROR - Creation problem: going to back out tmp space 
lease
2014-05-29 18:16:54,249 - ERROR - Backed out tmp space lease
2014-05-29 18:16:54,250 - ERROR - Problem creating the VM: POST operation 
failed: xend_post: error from xen daemon: (xend.err 'Error creating domain: 
pool Pool-0 not activated')
Traceback (most recent call last):
  File "/opt/nimbus/src/python/workspacecontrol/main/wc_core_creation.py", line 
137, in _common_withnetbootstrap
_common_withnetsecurity(vm_name, nic_set, kernel, local_file_set, p, c, 
netsecurity, platform, justprint)
  File "/opt/nimbus/src/python/workspacecontrol/main/wc_core_creation.py", line 
164, in _common_withnetsecurity
raise e
UnexpectedError: Problem creating the VM: POST operation failed: xend_post: 
error from xen daemon: (xend.err 'Error creating domain: pool Pool-0 not 
activated')
2014-05-29 18:16:54,252 - ERROR - Creation problem: going to back out net 
security
2014-05-29 18:16:54,376 - ERROR - Backed out net security
2014-05-29 18:16:54,378 - ERROR - Problem creating the VM: POST operation 
failed: xend_post: error from xen daemon: (xend.err 'Error creating domain: 
pool Pool-0 not activated')
Traceback (most recent call last):
  File "/opt/nimbus/src/python/workspacecontrol/main/wc_core_creation.py", line 
119, in _common_withnics
_common_withnetbootstrap(vm_name, nic_set, kernel, local_file_set, p, c, 
netsecurity, platform, justprint)
  File "/opt/nimbus/src/python/workspacecontrol/main/wc_core_creation.py", line 
146, in _common_withnetbootstrap
raise e
UnexpectedError: Problem creating the VM: POST operation failed: xend_post: 
error from xen daemon: (xend.err 'Error creating domain: pool Pool-0 not 
activated')
2014-05-29 18:16:54,380 - 

[libvirt] [PATCHv3 1/2] virsh: Reject negative numbers in vshCommandOptUInt

2014-05-29 Thread Peter Krempa
Use virStrToLong_uip instead of virStrToLong_ui to reject negative
numbers in the helper. None of the callers expects the wraparound
"feature" for negative numbers.

Also be explicit about the new semantics in the function docs.
---
 tools/virsh.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 15f3025..483dc04 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1501,7 +1501,7 @@ vshCommandOptInt(const vshCmd *cmd, const char *name, int 
*value)
  * @name option name
  * @value result
  *
- * Convert option to unsigned int
+ * Convert option to unsigned int, reject negative numbers
  * See vshCommandOptInt()
  */
 int
@@ -1514,7 +1514,7 @@ vshCommandOptUInt(const vshCmd *cmd, const char *name, 
unsigned int *value)
 if (ret <= 0)
 return ret;

-if (virStrToLong_ui(arg->data, NULL, 10, value) < 0)
+if (virStrToLong_uip(arg->data, NULL, 10, value) < 0)
 return -1;
 return 1;
 }
-- 
1.9.3

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


[libvirt] [PATCHv3 2/2] virsh: forbid negative vcpu argument to vcpupin

2014-05-29 Thread Peter Krempa
From: Jincheng Miao 

The vcpupin command allowed specifying a negative number for the --vcpu
argument. This would the overflow when the underlying virDomainPinVcpu
API was called.

 $ virsh vcpupin r7 -1 0
 error: numerical overflow: input too large: 4294967295

Switch the vCPU variable to a unsigned int and parse it using the
corresponding function.

Also improve the vcpupin test to cover all the defects.

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

Signed-off-by: Jincheng Miao 
Signed-off-by: Peter Krempa 
---

Notes:
Version 3:
- fix multiple problems, improve tests and refactor the error handling a 
bit better

 tests/vcpupin| 29 -
 tools/virsh-domain.c | 35 ++-
 2 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/tests/vcpupin b/tests/vcpupin
index f1fb038..9f34ec0 100755
--- a/tests/vcpupin
+++ b/tests/vcpupin
@@ -34,7 +34,7 @@ fail=0
 $abs_top_builddir/tools/virsh --connect test:///default vcpupin test a 0,1 > 
out 2>&1
 test $? = 1 || fail=1
 cat <<\EOF > exp || fail=1
-error: vcpupin: Invalid or missing vCPU number.
+error: vcpupin: Invalid vCPU number.

 EOF
 compare exp out || fail=1
@@ -43,9 +43,36 @@ compare exp out || fail=1
 $abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 0,1 > 
out 2>&1
 test $? = 1 || fail=1
 cat <<\EOF > exp || fail=1
+error: vcpupin: vCPU index out of range.
+
+EOF
+compare exp out || fail=1
+
+# Negative number
+$abs_top_builddir/tools/virsh --connect test:///default vcpupin test -100 0,1 
> out 2>&1
+test $? = 1 || fail=1
+cat <<\EOF > exp || fail=1
 error: vcpupin: Invalid vCPU number.

 EOF
 compare exp out || fail=1

+# missing argument
+$abs_top_builddir/tools/virsh --connect test:///default vcpupin test --cpulist 
0,1 > out 2>&1
+test $? = 1 || fail=1
+cat <<\EOF > exp || fail=1
+error: vcpupin: Missing vCPU number in pin mode.
+
+EOF
+compare exp out || fail=1
+
+# without arguments. This should succeed but the backend function in the
+# test driver isn't implemented
+$abs_top_builddir/tools/virsh --connect test:///default vcpupin test > out 2>&1
+test $? = 1 || fail=1
+cat <<\EOF > exp || fail=1
+error: this function is not supported by the connection driver: 
virDomainGetVcpuPinInfo
+
+EOF
+compare exp out || fail=1
 (exit $fail); exit $fail
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 84a6706..e76418a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5797,7 +5797,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
 {
 virDomainInfo info;
 virDomainPtr dom;
-int vcpu = -1;
+unsigned int vcpu = 0;
 const char *cpulist = NULL;
 bool ret = false;
 unsigned char *cpumap = NULL;
@@ -5809,6 +5809,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
 bool live = vshCommandOptBool(cmd, "live");
 bool current = vshCommandOptBool(cmd, "current");
 bool query = false; /* Query mode if no cpulist */
+int got_vcpu;
 unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;

 VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
@@ -5830,29 +5831,29 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)

 query = !cpulist;

-/* In query mode, "vcpu" is optional */
-if (vshCommandOptInt(cmd, "vcpu", &vcpu) < !query) {
-vshError(ctl, "%s",
- _("vcpupin: Invalid or missing vCPU number."));
-virDomainFree(dom);
-return false;
+if ((got_vcpu = vshCommandOptUInt(cmd, "vcpu", &vcpu)) < 0) {
+vshError(ctl, "%s", _("vcpupin: Invalid vCPU number."));
+goto cleanup;
 }

-if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) {
-virDomainFree(dom);
-return false;
+/* In pin mode, "vcpu" is necessary */
+if (!query && got_vcpu == 0) {
+vshError(ctl, "%s", _("vcpupin: Missing vCPU number in pin mode."));
+goto cleanup;
 }

 if (virDomainGetInfo(dom, &info) != 0) {
 vshError(ctl, "%s", _("vcpupin: failed to get domain information."));
-virDomainFree(dom);
-return false;
+goto cleanup;
 }

 if (vcpu >= info.nrVirtCpu) {
-vshError(ctl, "%s", _("vcpupin: Invalid vCPU number."));
-virDomainFree(dom);
-return false;
+vshError(ctl, "%s", _("vcpupin: vCPU index out of range."));
+goto cleanup;
+}
+
+if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) {
+goto cleanup;
 }

 cpumaplen = VIR_CPU_MAPLEN(maxcpu);
@@ -5871,7 +5872,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
 vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU Affinity"));
 vshPrintExtra(ctl, "--\n");
 for (i = 0; i < ncpus; i++) {
-   if (vcpu != -1 && i != vcpu)
+   if (got_vcpu && i != vcpu)
continue;

vshPrint(ctl, "%4zu: ", i);
@@ -5880,8 +5881,8 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd

[libvirt] [PATCHv3 0/2] virsh: Fix negative value parsing in vcpuinfo

2014-05-29 Thread Peter Krempa
Jincheng Miao (1):
  virsh: forbid negative vcpu argument to vcpupin

Peter Krempa (1):
  virsh: Reject negative numbers in vshCommandOptUInt

 tests/vcpupin| 29 -
 tools/virsh-domain.c | 35 ++-
 tools/virsh.c|  4 ++--
 3 files changed, 48 insertions(+), 20 deletions(-)

-- 
1.9.3

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


Re: [libvirt] [PATCH V2] virsh: forbid negative vcpu argument to vcpupin.

2014-05-29 Thread Peter Krempa
On 05/29/14 05:34, Jincheng Miao wrote:
> vcpupin will allow argument --vcpu as a signed number,
> and pass it to virDomainPinVcpu directlly without
> checking if this value is positive(valid).
> 
>> virsh vcpupin r7 -1 0
> error: numerical overflow: input too large: 4294967295
> 
> This message is inaccurate, and the negative vcpu is
> non-valuable. So forbid vcpu argument as a negative.
> 
> After patching, the result likes:
>> virsh vcpupin r6 -1
> error: vcpupin: Invalid vCPU number.
> 
>> virsh vcpupin r6 --cpulist 0-1
> error: vcpupin: Missing vCPU number in pin mode.
> 
>> virsh vcpupin r6 --vcpu ABC
> error: vcpupin: Invalid vCPU number in query mode.
> 
> Signed-off-by: Jincheng Miao 
> ---
>  tools/virsh-domain.c |   42 --
>  1 files changed, 24 insertions(+), 18 deletions(-)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 84a6706..e302459 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -5797,7 +5797,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
>  {
>  virDomainInfo info;
>  virDomainPtr dom;
> -int vcpu = -1;
> +unsigned int vcpu;

This needs to be initialized to 0 otherwise it might be used
uninitialized if the user didn's specify any argument.

>  const char *cpulist = NULL;
>  bool ret = false;
>  unsigned char *cpumap = NULL;
> @@ -5809,6 +5809,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
>  bool live = vshCommandOptBool(cmd, "live");
>  bool current = vshCommandOptBool(cmd, "current");
>  bool query = false; /* Query mode if no cpulist */
> +int get_vcpu;

we usually use past tense for such names: s/get_cpu/got_cpu/

>  unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
>  
>  VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
> @@ -5830,29 +5831,34 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
>  
>  query = !cpulist;
>  
> -/* In query mode, "vcpu" is optional */
> -if (vshCommandOptInt(cmd, "vcpu", &vcpu) < !query) {
> -vshError(ctl, "%s",
> - _("vcpupin: Invalid or missing vCPU number."));
> -virDomainFree(dom);
> -return false;
> -}
> -
> -if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) {
> -virDomainFree(dom);
> -return false;
> +get_vcpu = vshCommandOptUInt(cmd, "vcpu", &vcpu);

Still not quite right ... vshCommandOptUInt currently wraps negative
numbers to their 2's complement and stores them in the uint.

This would currently work as:

 $ tools/virsh vcpupin RHEL_nightly -4294967295
 VCPU: CPU Affinity
 --
1: 0-3

We need to modify the vshCommandOptUInt helper to reject negative numbers.

> +if (get_vcpu <= 0) {
> +/* In query mode, "vcpu" is optional */
> +if (query && get_vcpu < 0) {
> +vshError(ctl, "%s",
> + _("vcpupin: Invalid vCPU number in query mode."));
> +goto cleanup;
> +}
> +/* In pin mode, "vcpu" is necessary */
> +if (!query) {
> +vshError(ctl, "%s",
> + _("vcpupin: Missing vCPU number in pin mode."));
> +goto cleanup;
> +}
>  }
>  
>  if (virDomainGetInfo(dom, &info) != 0) {
>  vshError(ctl, "%s", _("vcpupin: failed to get domain information."));
> -virDomainFree(dom);
> -return false;
> +goto cleanup;
>  }
>  
>  if (vcpu >= info.nrVirtCpu) {
>  vshError(ctl, "%s", _("vcpupin: Invalid vCPU number."));
> -virDomainFree(dom);
> -return false;
> +goto cleanup;
> +}
> +
> +if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) {
> +goto cleanup;
>  }
>  
>  cpumaplen = VIR_CPU_MAPLEN(maxcpu);
> @@ -5871,7 +5877,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
>  vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU Affinity"));
>  vshPrintExtra(ctl, "--\n");
>  for (i = 0; i < ncpus; i++) {
> -   if (vcpu != -1 && i != vcpu)
> +   if (get_vcpu > 0 && i != vcpu)

This will be either 0 or 1 here, so the "> 0" part can be omitted.

> continue;
>  
> vshPrint(ctl, "%4zu: ", i);
> @@ -5880,8 +5886,8 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
> if (!ret)
> break;
>  }
> -
>  }
> +
>  VIR_FREE(cpumaps);
>  goto cleanup;
>  }
> 

This patch results into breakage of the vcpupin test as outputs are
changing.

~/libvirt/tests $ VIR_TEST_DEBUG=2 ./vcpupin
--- exp 2014-05-29 13:17:40.170153617 +0200
+++ out 2014-05-29 13:17:40.166820284 +0200
@@ -1,2 +1,2 @@
-error: vcpupin: Invalid or missing vCPU number.
+error: vcpupin: Missing vCPU number in pin mode.

I'm going to post a v3 of this patch with the mistakes fixed and with
the additional patch to fix vshCommandOptUInt.

Also I'm going t

[libvirt] [libvirt-glib] [PATCH] GVirDomainSnapshot: add gvir_domain_snapshot_delete

2014-05-29 Thread Timm Bäder
---
 libvirt-gobject/libvirt-gobject-domain-snapshot.c | 21 +
 libvirt-gobject/libvirt-gobject-domain-snapshot.h |  3 +++
 libvirt-gobject/libvirt-gobject.sym   |  5 +
 3 files changed, 29 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c 
b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
index ab23342..f46c99b 100644
--- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c
+++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
@@ -206,3 +206,24 @@ GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config
 free(xml);
 return conf;
 }
+
+/**
+ * gvir_domain_snapshot_delete:
+ * @snapshot: the domain_snapshot
+ * @error: (allow-none): Place-holder for error or NULL
+ */
+void gvir_domain_snapshot_delete(GVirDomainSnapshot *snapshot, GError **error)
+{
+GVirDomainSnapshotPrivate *priv;
+int status;
+
+g_return_if_fail(GVIR_IS_DOMAIN_SNAPSHOT (snapshot));
+g_return_if_fail(error == NULL || *error == NULL);
+
+priv = snapshot->priv;
+status = virDomainSnapshotDelete(priv->handle, 0);
+if (status < 0) {
+gvir_set_error_literal(error, GVIR_DOMAIN_SNAPSHOT_ERROR, 0,
+   "Unable to delete snapshot");
+}
+}
diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.h 
b/libvirt-gobject/libvirt-gobject-domain-snapshot.h
index 5bd827c..575f56f 100644
--- a/libvirt-gobject/libvirt-gobject-domain-snapshot.h
+++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.h
@@ -69,6 +69,9 @@ GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config
  guint flags,
  GError **err);
 
+void gvir_domain_snapshot_delete (GVirDomainSnapshot *snapshot, GError 
**error);
+
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GOBJECT_DOMAIN_SNAPSHOT_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.sym 
b/libvirt-gobject/libvirt-gobject.sym
index f2419ac..5d12a6a 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -234,4 +234,9 @@ LIBVIRT_GOBJECT_0.1.5 {
gvir_connection_open_read_only_finish;
 } LIBVIRT_GOBJECT_0.1.4;
 
+LIBVIRT_GOBJECT_0.1.9 {
+  global:
+  gvir_domain_shapshot_delete;
+} LIBVIRT_GOBJECT_0.1.5;
+
 #  define new API here using predicted next version number 
-- 
1.9.3

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


Re: [libvirt] GSoC student introduction and work plan

2014-05-29 Thread Michal Privoznik

On 23.05.2014 06:03, Taowei Luo wrote:

Hi, everyone, My name is Taowei Luo. I'm one of the students working for
GSoC this summer. My project is rewriting the vbox driver.



The plan sounds good to me. If you write some patches please make sure 
you won't end up with one huge patch that does all the work. I mean, 
split it into smaller pieces if possible.


BTW: for better picture I suggest to send an example that will transform 
just a tiny bit (while I believe the rest is going to be purely 
mechanical then).


Michal

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


[libvirt] [PATCH] Don't use AI_ADDRCONFIG when binding to wildcard addresses

2014-05-29 Thread Ján Tomko
https://bugzilla.redhat.com/show_bug.cgi?id=1098659

With parallel boot, network addresses might not yet be assigned [1],
but binding to wildcard addresses should work.

For non-wildcard addresses, ADDRCONFIG is still used. Document this
in libvirtd.conf.

[1] http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
---
 daemon/libvirtd.conf   |  4 
 src/rpc/virnetsocket.c | 28 ++--
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/daemon/libvirtd.conf b/daemon/libvirtd.conf
index aeba11d..e5856d4 100644
--- a/daemon/libvirtd.conf
+++ b/daemon/libvirtd.conf
@@ -48,6 +48,10 @@
 # Override the default configuration which binds to all network
 # interfaces. This can be a numeric IPv4/6 address, or hostname
 #
+# If the libvirtd service is started in parallel with network
+# startup (e.g. with systemd), binding to addresses other than
+# the wildcards (0.0.0.0/::) might not be available yet.
+#
 #listen_addr = "192.168.0.1"
 
 
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index a7e1783..87b39f2 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -226,15 +226,29 @@ int virNetSocketNewListenTCP(const char *nodename,
 struct addrinfo hints;
 int fd = -1;
 size_t i;
-int addrInUse = false;
+bool addrInUse = false;
+bool familyNotSupported = false;
+virSocketAddr tmp_addr;
 
 *retsocks = NULL;
 *nretsocks = 0;
 
 memset(&hints, 0, sizeof(hints));
-hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+hints.ai_flags = AI_PASSIVE;
 hints.ai_socktype = SOCK_STREAM;
 
+/* Don't use ADDRCONFIG for binding to the wildcard address.
+ * Just catch the error returned by socket() if the system has
+ * no IPv6 support.
+ *
+ * This allows libvirtd to be started in parallel with the network
+ * startup in most cases.
+ */
+if (nodename &&
+!(virSocketAddrParse(&tmp_addr, nodename, AF_UNSPEC) > 0 &&
+  virSocketAddrIsWildcard(&tmp_addr)))
+hints.ai_flags = AI_ADDRCONFIG;
+
 int e = getaddrinfo(nodename, service, &hints, &ai);
 if (e != 0) {
 virReportError(VIR_ERR_SYSTEM_ERROR,
@@ -251,6 +265,11 @@ int virNetSocketNewListenTCP(const char *nodename,
 
 if ((fd = socket(runp->ai_family, runp->ai_socktype,
  runp->ai_protocol)) < 0) {
+if (errno == EAFNOSUPPORT) {
+familyNotSupported = true;
+runp = runp->ai_next;
+continue;
+}
 virReportSystemError(errno, "%s", _("Unable to create socket"));
 goto error;
 }
@@ -307,6 +326,11 @@ int virNetSocketNewListenTCP(const char *nodename,
 fd = -1;
 }
 
+if (nsocks == 0 && familyNotSupported) {
+virReportSystemError(EAFNOSUPPORT, "%s", _("Unable to bind to port"));
+goto error;
+}
+
 if (nsocks == 0 &&
 addrInUse) {
 virReportSystemError(EADDRINUSE, "%s", _("Unable to bind to port"));
-- 
1.8.3.2

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


[libvirt] [PATCH 1/2] qemu: snapshot: Reject internal active snapshot without memory state

2014-05-29 Thread Peter Krempa
A internal snapshot of a active VM with the memory snapshot disabled
explicitly would actually still take the memory snapshot. Reject it
explicitly.

Before:
 $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
--memspec snapshot=no
 Domain snapshot 1401353155 created

After:
 $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
--memspec snapshot=no
 error: Operation not supported: internal snapshot of a running VM must include 
the memory state

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1083345
---
 src/qemu/qemu_driver.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9becc0a..272687d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13495,6 +13495,15 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
 align_match = false;
 } else {
 def->state = virDomainObjGetState(vm, NULL);
+
+if (virDomainObjIsActive(vm) &&
+def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_NONE) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+   _("internal snapshot of a running VM "
+ "must include the memory state"));
+goto cleanup;
+}
+
 def->memory = (def->state == VIR_DOMAIN_SHUTOFF ?
VIR_DOMAIN_SNAPSHOT_LOCATION_NONE :
VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL);
-- 
1.9.3

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


[libvirt] [PATCH 2/2] qemu: snapshot: Improve detection of mixed snapshots

2014-05-29 Thread Peter Krempa
Currently we don't support mixed (external + internal) snapshots. The
code detecting the snapshot type didn't make sure that the memory image
was consistent with the snapshot type leading into strange error
message:

 $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
--memspec snapshot=external,file=/tmp/blah
 error: internal error: unexpected code path

Fix the mixed detection code to detect this kind of mistake:

 $ virsh snapshot-create-as --domain VM --diskspec vda,snapshot=internal 
--memspec snapshot=external,file=/tmp/blah
 error: unsupported configuration: mixing internal and external targets for a 
snapshot is not yet supported
---
 src/qemu/qemu_driver.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 272687d..59185c6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12755,7 +12755,9 @@ qemuDomainSnapshotPrepare(virConnectPtr conn,
 /* For now, we don't allow mixing internal and external disks.
  * XXX technically, we could mix internal and external disks for
  * offline snapshots */
-if (found_internal && external) {
+if ((found_internal && external) ||
+ (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL && external) ||
+ (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL && 
found_internal)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("mixing internal and external targets for a snapshot "
  "is not yet supported"));
-- 
1.9.3

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


[libvirt] [PATCH 0/2] qemu: Fix few snapshot issues

2014-05-29 Thread Peter Krempa
Peter Krempa (2):
  qemu: snapshot: Reject internal active snapshot without memory state
  qemu: snapshot: Improve detection of mixed snapshots

 src/qemu/qemu_driver.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

-- 
1.9.3

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


Re: [libvirt] [PATCHv2] util: fix virTimeLocalOffsetFromUTC DST processing

2014-05-29 Thread Laine Stump
On 05/28/2014 05:51 PM, Eric Blake wrote:
> On 05/28/2014 04:46 AM, Laine Stump wrote:
>> The original version of virTimeLocalOffsetFromUTC() would fail for
>> certain times of the day if daylight savings time was active. This
>> could most easily be seen by uncommenting the TEST_LOCALOFFSET() cases
>> that include a DST setting.
>
>>  src/util/virtime.c  |  3 +++
>>  tests/virtimetest.c | 61 
>> ++---
>>  2 files changed, 56 insertions(+), 8 deletions(-)
>>
>> diff --git a/src/util/virtime.c b/src/util/virtime.c
>> index 3a56400..c69dff1 100644
>> --- a/src/util/virtime.c
>> +++ b/src/util/virtime.c
>> @@ -377,6 +377,9 @@ virTimeLocalOffsetFromUTC(long *offset)
>>  return -1;
>>  }
>>  
>> +/* tell mktime to figure out itself whether or not DST is in effect */
>> +gmtimeinfo.tm_isdst = -1;
> As pointed out by Wangrui, you also need to fix the bogus reference to
> localtime_r() in the comments at the start of the function.
>
> ACK with that change; worth having in 1.2.5.  The rest of what follows
> is up to you if you ignore it.
>
>> +
>> +/* return true if the date is Jan 1 or Dec 31 (localtime) */
>> +static bool
>> +IsJan1OrDec31(void)
> Function names are usually camelCase, not StudlyCaps (s/Is/is/).
> Bikeshedding: maybe name it isNearYearEnd()?
>

Okay, I made both changes and pushed.

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


[libvirt] [libvirt-python][PATCH] Implement virNodeHugeTLB

2014-05-29 Thread Michal Privoznik
Signed-off-by: Michal Privoznik 
---
 generator.py   |  2 ++
 libvirt-override-virConnect.py |  7 
 libvirt-override.c | 78 ++
 3 files changed, 87 insertions(+)

diff --git a/generator.py b/generator.py
index bdac877..a35c05c 100755
--- a/generator.py
+++ b/generator.py
@@ -522,6 +522,8 @@ skip_function = (
 'virDomainGetTime', # overridden in virDomain.py
 'virDomainSetTime', # overridden in virDomain.py
 
+'virNodeHugeTLB', # overridden in virConnect.py
+
 # 'Ref' functions have no use for bindings users.
 "virConnectRef",
 "virDomainRef",
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index c228eb2..9c46e0f 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -383,3 +383,10 @@
 if ret is None:raise libvirtError('virDomainCreateXMLWithFiles() 
failed', conn=self)
 __tmp = virDomain(self,_obj=ret)
 return __tmp
+
+def hugeTLB(self, node=-1, flags=0):
+"""Get info on huge pages. Pass node=-1 for list of supported
+hugepages sizes """
+ret = libvirtmod.virNodeHugeTLB(self._o, node, flags)
+if ret is None: raise libvirtError('virNodeHugeTLB() failed', 
conn=self)
+return ret
diff --git a/libvirt-override.c b/libvirt-override.c
index a7a6213..1d1dc4e 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -7740,6 +7740,81 @@ libvirt_virDomainSetTime(PyObject *self 
ATTRIBUTE_UNUSED, PyObject *args) {
 }
 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
 
+#if LIBVIR_CHECK_VERSION(1, 2, 6)
+static PyObject *
+libvirt_virNodeHugeTLB(PyObject *self ATTRIBUTE_UNUSED,
+   PyObject *args) {
+virConnectPtr conn;
+PyObject *pyobj_conn, *py_retval = NULL;
+PyObject *dict = NULL;
+int node = -1;
+virTypedParameterPtr params;
+int nparams = 0;
+unsigned int flags;
+int c_retval;
+ssize_t i, j;
+unsigned int count = 0;
+
+if (!PyArg_ParseTuple(args, (char *)"Oii:virNodeHugeTLB",
+  &pyobj_conn, &node, &flags))
+return NULL;
+conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+c_retval = virNodeHugeTLB(conn, node, NULL, &nparams, flags);
+LIBVIRT_END_ALLOW_THREADS;
+
+if (c_retval < 0)
+return VIR_PY_NONE;
+
+if (!nparams)
+return PyDict_New();
+
+if (VIR_ALLOC_N(params, nparams) < 0)
+return PyErr_NoMemory();
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+c_retval = virNodeHugeTLB(conn, node, params, &nparams, flags);
+LIBVIRT_END_ALLOW_THREADS;
+
+if (c_retval < 0) {
+py_retval = VIR_PY_NONE;
+goto cleanup;
+}
+
+if (!(dict = PyDict_New()))
+goto cleanup;
+
+j = i = nparams;
+while (i) {
+PyObject *key, *val;
+
+i--;
+
+if (STREQ(VIR_NODE_HUGE_PAGE_SIZE, params[i].field)) {
+val = getPyVirTypedParameter(params + i, j - i);
+key = libvirt_uintWrap(count++);
+
+if (!val || !key ||
+PyDict_SetItem(dict, key, val) < 0) {
+Py_XDECREF(val);
+Py_XDECREF(key);
+goto cleanup;
+}
+j = i;
+}
+}
+
+py_retval = dict;
+dict = NULL;
+
+ cleanup:
+virTypedParamsFree(params, nparams);
+Py_XDECREF(dict);
+return py_retval;
+}
+#endif /* LIBVIR_CHECK_VERSION(1, 2, 6) */
+
 /
  * *
  * The registration stuff  *
@@ -7921,6 +7996,9 @@ static PyMethodDef libvirtMethods[] = {
 {(char *) "virDomainGetTime", libvirt_virDomainGetTime, METH_VARARGS, 
NULL},
 {(char *) "virDomainSetTime", libvirt_virDomainSetTime, METH_VARARGS, 
NULL},
 #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
+#if LIBVIR_CHECK_VERSION(1, 2, 6)
+{(char *) "virNodeHugeTLB", libvirt_virNodeHugeTLB, METH_VARARGS, NULL},
+#endif /* LIBVIR_CHECK_VERSION(1, 2, 6) */
 {NULL, NULL, 0, NULL}
 };
 
-- 
1.9.3

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


[libvirt] [PATCH 12/12] nodedev: Export NUMA node locality for PCI devices

2014-05-29 Thread Michal Privoznik
A PCI device can be associated with a specific NUMA node. Later, when
a guest is pinned to one NUMA node the PCI device can be assigned on
different NUMA node. This makes DMA transfers travel across nodes and
thus results in suboptimal performance. We should expose the NUMA node
locality for PCI devices so management applications can make better
decisions.

Signed-off-by: Michal Privoznik 
---

Notes:
All the machines I have tried this on had only -1 in the
numa_node file. From the kernel sources it seems that this is the
default, so I'm not printing the  element into the XML in
this case. But I'd like to hear your opinion.

 docs/formatnode.html.in|  6 +++
 docs/schemas/nodedev.rng   | 11 ++
 src/conf/node_device_conf.c| 43 ++
 src/conf/node_device_conf.h|  1 +
 src/node_device/node_device_udev.c |  7 
 tests/nodedevschemadata/pci_1002_71c4.xml  |  1 +
 tests/nodedevschemadata/pci_8086_10c9_sriov_pf.xml |  1 +
 7 files changed, 70 insertions(+)

diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in
index 46ec2bc..3671c8b 100644
--- a/docs/formatnode.html.in
+++ b/docs/formatnode.html.in
@@ -124,6 +124,12 @@
   GigaTransfers per second) and width for the number
   of lanes used. Since the port can't be negotiated, it's not
   exposed in ./pci-express/link/[@validity='sta'].
+  numa
+  
+This optional element contains information on the PCI device
+with respect to NUMA. For example, the optional
+node attribute tells which NUMA node is the PCI
+device associated with.
   
 
   
diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng
index 79e8fd2..10b716f 100644
--- a/docs/schemas/nodedev.rng
+++ b/docs/schemas/nodedev.rng
@@ -184,6 +184,17 @@
 
 
 
+
+
+  
+
+  
+
+  
+
+  
+
+
   
 
   
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 70634cc..57dccc4 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -380,6 +380,9 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def)
 }
 if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCIE)
 virPCIEDeviceInfoFormat(&buf, data->pci_dev.pci_express);
+if (data->pci_dev.numa_node >= 0)
+virBufferAsprintf(&buf, "\n",
+  data->pci_dev.numa_node);
 break;
 case VIR_NODE_DEV_CAP_USB_DEV:
 virBufferAsprintf(&buf, "%d\n", data->usb_dev.bus);
@@ -554,6 +557,41 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def)
 return NULL;
 }
 
+/**
+ * virNodeDevCapsDefParseIntOptional:
+ * @xpath:  XPath to evaluate
+ * @ctxt:   Context
+ * @value:  Where to store parsed value
+ * @def:Node device which is parsed
+ * @invalid_error_fmt:  error message to print on invalid format
+ *
+ * Returns: -1 on error (invalid int format under @xpath)
+ *   0 if @xpath was not found (@value is untouched)
+ *   1 on success
+ */
+static int
+virNodeDevCapsDefParseIntOptional(const char *xpath,
+  xmlXPathContextPtr ctxt,
+  int *value,
+  virNodeDeviceDefPtr def,
+  const char *invalid_error_fmt)
+{
+int ret;
+int val;
+
+ret = virXPathInt(xpath, ctxt, &val);
+if (ret < -1) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   invalid_error_fmt,
+   def->name);
+return -1;
+} else if (ret == -1) {
+return 0;
+}
+*value = val;
+return 1;
+}
+
 static int
 virNodeDevCapsDefParseULong(const char *xpath,
 xmlXPathContextPtr ctxt,
@@ -1222,6 +1260,11 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt,
 goto out;
 }
 
+if (virNodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt,
+  &data->pci_dev.numa_node, def,
+  _("invalid NUMA node ID supplied for 
'%s'")) < 0)
+goto out;
+
 ret = 0;
  out:
 ctxt->node = orignode;
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 563bf6a..6abab5e 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -142,6 +142,7 @@ struct _virNodeDevCapsDef {
 size_t nIommuGroupDevices;
 unsigned int iommuGroupNumber;
 virPCIEDeviceInfoPtr pci_express;
+int numa_node;
 } pci_dev;
 struct {
 unsigned int bus;
diff --git a/src/node_device/node_device_udev.c 
b/

[libvirt] [PATCH 10/12] virCaps: Introduce IOMMU and VFIO capabilities

2014-05-29 Thread Michal Privoznik
There's no need to check for these two host capabilities on each
device attach or detach. It's sufficient to check them on the daemon
start and then just query them from virCaps when needed. Moreover,
this way it's fairly simple to expose them in capabilities XML.

Signed-off-by: Michal Privoznik 
---
 src/conf/capabilities.c  | 46 
 src/conf/capabilities.h  | 11 ++
 src/libvirt_private.syms |  5 +
 src/lxc/lxc_conf.c   |  3 +++
 src/nodeinfo.c   | 15 +
 src/nodeinfo.h   |  1 +
 src/parallels/parallels_driver.c |  3 +++
 src/phyp/phyp_driver.c   |  3 +++
 src/qemu/qemu_capabilities.c |  3 +++
 src/qemu/qemu_driver.c   | 16 --
 src/qemu/qemu_hostdev.c  | 21 ++
 src/uml/uml_conf.c   |  3 +++
 src/vbox/vbox_tmpl.c |  3 +++
 13 files changed, 127 insertions(+), 6 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index cf474d7..9561ba3 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -1068,3 +1068,49 @@ virCapabilitiesGetCpusForNodemask(virCapsPtr caps,
 
 return ret;
 }
+
+
+int
+virCapabilitiesGetKVMLegacy(virCapsPtr caps,
+bool *legacy)
+{
+if (!caps)
+return -1;
+
+*legacy = caps->host.legacyKVMPassthrough;
+return 0;
+}
+
+int
+virCapabilitiesSetKVMLegacy(virCapsPtr caps,
+bool legacy)
+{
+if (!caps)
+return -1;
+
+caps->host.legacyKVMPassthrough = legacy;
+return 0;
+}
+
+
+int
+virCapabilitiesGetVFIO(virCapsPtr caps,
+   bool *vfio)
+{
+if (!caps)
+return -1;
+
+*vfio = caps->host.VFIOPassthrough;
+return 0;
+}
+
+int
+virCapabilitiesSetVFIO(virCapsPtr caps,
+   bool vfio)
+{
+if (!caps)
+return -1;
+
+caps->host.VFIOPassthrough = vfio;
+return 0;
+}
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index ba99e1a..935cd14 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -144,6 +144,9 @@ struct _virCapsHost {
 
 virCPUDefPtr cpu;
 unsigned char host_uuid[VIR_UUID_BUFLEN];
+
+bool legacyKVMPassthrough;
+bool VFIOPassthrough;
 };
 
 typedef int (*virDomainDefNamespaceParse)(xmlDocPtr, xmlNodePtr,
@@ -274,4 +277,12 @@ virCapabilitiesFormatXML(virCapsPtr caps);
 virBitmapPtr virCapabilitiesGetCpusForNodemask(virCapsPtr caps,
virBitmapPtr nodemask);
 
+int virCapabilitiesGetKVMLegacy(virCapsPtr caps,
+bool *legacy);
+int virCapabilitiesSetKVMLegacy(virCapsPtr caps,
+bool legacy);
+int virCapabilitiesGetVFIO(virCapsPtr caps,
+   bool *vfio);
+int virCapabilitiesSetVFIO(virCapsPtr caps,
+   bool vfio);
 #endif /* __VIR_CAPABILITIES_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9a942ec..95f1599 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -58,9 +58,13 @@ virCapabilitiesFormatXML;
 virCapabilitiesFreeMachines;
 virCapabilitiesFreeNUMAInfo;
 virCapabilitiesGetCpusForNodemask;
+virCapabilitiesGetKVMLegacy;
+virCapabilitiesGetVFIO;
 virCapabilitiesHostSecModelAddBaseLabel;
 virCapabilitiesNew;
 virCapabilitiesSetHostCPU;
+virCapabilitiesSetKVMLegacy;
+virCapabilitiesSetVFIO;
 
 
 # conf/cpu_conf.h
@@ -866,6 +870,7 @@ virLockManagerRelease;
 
 
 # nodeinfo.h
+nodeCapsInitKVM;
 nodeCapsInitNUMA;
 nodeGetCellsFreeMemory;
 nodeGetCPUBitmap;
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index a35a5e0..9589290 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -82,6 +82,9 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
 VIR_WARN("Failed to query host NUMA topology, disabling NUMA 
capabilities");
 }
 
+if (nodeCapsInitKVM(caps) < 0)
+VIR_WARN("Failed to query KVM info");
+
 if (virNodeSuspendGetTargetMask(&caps->host.powerMgmt) < 0)
 VIR_WARN("Failed to get host power management capabilities");
 
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index be63a30..d5ce75b 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -52,6 +52,7 @@
 #include "virtypedparam.h"
 #include "virstring.h"
 #include "virnuma.h"
+#include "virhostdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -1821,6 +1822,20 @@ nodeCapsInitNUMA(virCapsPtr caps)
 
 
 int
+nodeCapsInitKVM(virCapsPtr caps)
+{
+bool legacy = virHostdevHostSupportsPassthroughLegacy();
+bool vfio = virHostdevHostSupportsPassthroughVFIO();
+
+if (virCapabilitiesSetKVMLegacy(caps, legacy) < 0 ||
+virCapabilitiesSetVFIO(caps, vfio) < 0)
+return -1;
+
+return 0;
+}
+
+
+int
 nodeGetCellsFreeMemory(unsigned long long *freeMems,
int startCell,
int maxCe

[libvirt] [PATCH 03/12] nodeinfo: Implement nodeHugeTLB

2014-05-29 Thread Michal Privoznik
At the same time, in the qemu driver this is exposed as
qemuNodeHugeTLB.

Signed-off-by: Michal Privoznik 
---
 include/libvirt/libvirt.h.in |  20 +
 src/libvirt.c|  13 +++-
 src/libvirt_private.syms |   1 +
 src/nodeinfo.c   | 177 +++
 src/nodeinfo.h   |   5 ++
 src/qemu/qemu_driver.c   |  14 
 6 files changed, 226 insertions(+), 4 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index cb1cad9..c492129 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -858,6 +858,26 @@ int virNodeSetMemoryParameters(virConnectPtr conn,
int nparams,
unsigned int flags);
 
+/* VIR_NODE_HUGE_PAGE_SIZE:
+ *
+ * Macro for typed parameter that represents a huge page size.
+ * The size is expressed in kibibytes, so for example 2MB is
+ * expressed as 2048. */
+# define VIR_NODE_HUGE_PAGE_SIZE "hugepage_size"
+
+/* VIR_NODE_HUGE_PAGE_AVAILABLE:
+ *
+ * Macro for typed parameter that represents the size of the pool
+ * of huge pages of certain size. It's the sum of allocated plus
+ * free. */
+# define VIR_NODE_HUGE_PAGE_AVAILABLE "hugepage_available"
+
+/* VIR_NODE_HUGE_PAGE_FREE:
+ *
+ * Macro for typed parameter that represents the number of huge
+ * pages in the pool that are not yet allocated. */
+# define VIR_NODE_HUGE_PAGE_FREE "hugepage_free"
+
 int virNodeHugeTLB(virConnectPtr conn,
int type,
virTypedParameterPtr params,
diff --git a/src/libvirt.c b/src/libvirt.c
index de20b0c..ab7c347 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -7569,10 +7569,15 @@ virNodeSetMemoryParameters(virConnectPtr conn,
  * @nparams: pointer to number of memory parameters; input and output
  * @flags: extra flags; not used yet, so callers should always pass 0
  *
- * Get information about host's huge pages. On input, @nparams
- * gives the size of the @params array; on output, @nparams gives
- * how many slots were filled with parameter information, which
- * might be less but will not exceed the input value.
+ * Get information about host's huge pages. The parameters are
+ * positioned. That is, they form a tuple starting with
+ * VIR_NODE_HUGE_PAGE_SIZE followed by other values (e.g.
+ * VIR_NODE_HUGE_PAGE_AVAILABLE and VIR_NODE_HUGE_PAGE_FREE).
+ * Next tuple again starts with the size parameter. On input,
+ * @nparams gives the size of the @params array; on output,
+ * @nparams gives how many slots were filled with parameter
+ * information, which might be less but will not exceed the
+ * input value.
  *
  * As a special case, calling with @params as NULL and @nparams
  * as 0 on input will cause @nparams on output to contain the
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index cb635cd..1d97c89 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -874,6 +874,7 @@ nodeGetFreeMemory;
 nodeGetInfo;
 nodeGetMemoryParameters;
 nodeGetMemoryStats;
+nodeHugeTLB;
 nodeSetMemoryParameters;
 
 
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 56f2b02..be63a30 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -1880,3 +1880,180 @@ nodeGetFreeMemory(void)
 
 return freeMem;
 }
+
+static int
+nodeHugePageDumpInfo(const char *prefix,
+ const char *name,
+ unsigned long long *page_avail,
+ unsigned long long *page_free)
+{
+int ret = -1;
+char *buf = NULL;
+char *path = NULL;
+char *end;
+
+if (virAsprintf(&path, "%s/%s/nr_hugepages", prefix, name) < 0)
+goto cleanup;
+
+if (virFileReadAll(path, 1024, &buf) < 0) {
+virReportSystemError(errno,
+ _("unable to read %s"),
+ path);
+goto cleanup;
+}
+
+if (virStrToLong_ull(buf, &end, 10, page_avail) < 0 ||
+*end != '\n') {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("unable to parse: %s"),
+   buf);
+goto cleanup;
+}
+
+VIR_FREE(path);
+VIR_FREE(buf);
+
+if (virAsprintf(&path, "%s/%s/free_hugepages", prefix, name) < 0)
+goto cleanup;
+
+if (virFileReadAll(path, 1024, &buf) < 0) {
+virReportSystemError(errno,
+ _("unable to read %s"),
+ path);
+goto cleanup;
+}
+
+if (virStrToLong_ull(buf, &end, 10, page_free) < 0 ||
+*end != '\n') {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("unable to parse: %s"),
+   buf);
+goto cleanup;
+}
+
+ret = 0;
+ cleanup:
+VIR_FREE(path);
+VIR_FREE(buf);
+return ret;
+}
+
+#define HUGEPAGES_PREFIX "hugepages-"
+
+static int
+nodeHugePageSupported(const char *prefix,
+  virTypedParameterPtr params,
+  int 

[libvirt] [PATCH 06/12] virInterface: Expose link state & speed

2014-05-29 Thread Michal Privoznik
Currently it is not possible to determine the speed of an interface
and whether a link is actually detected from the API. Orchestrating
platforms want to be able to determine when the link has failed and
where multiple speeds may be available which one the interface is
actually connected at. This commit introduces an extension to our
interface XML (without implementation to interface driver backends):

  




...
  

Where @speed is negotiated link speed in Mbits per second, and state
is the current NIC state (can be one of the following:  "unknown",
"notpresent", "down", "lowerlayerdown","testing", "dormant", "up").

Signed-off-by: Michal Privoznik 
---
 docs/schemas/interface.rng  | 27 +
 src/conf/interface_conf.c   | 39 -
 src/conf/interface_conf.h   | 15 ++
 src/libvirt_private.syms|  2 ++
 tests/interfaceschemadata/bridge-no-address.xml |  1 +
 tests/interfaceschemadata/bridge.xml|  1 +
 tests/interfaceschemadata/ethernet-dhcp.xml |  1 +
 7 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/docs/schemas/interface.rng b/docs/schemas/interface.rng
index 3984b63..d980ef5 100644
--- a/docs/schemas/interface.rng
+++ b/docs/schemas/interface.rng
@@ -41,6 +41,7 @@
 
   
 
+
 
   
 
@@ -271,6 +272,32 @@
 
   
 
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  unknown
+  notpresent
+  down
+  lowerlayerdown
+  testing
+  dormant
+  up
+  
+  
+  
+  
+  
+  
+
+
   

[libvirt] [PATCH 04/12] virpci: Introduce virPCIDeviceIsPCIExpress and friends

2014-05-29 Thread Michal Privoznik
These functions will handle PCIe devices and their link capabilities
to query some info about it.

Signed-off-by: Michal Privoznik 
---
 src/libvirt_private.syms |  3 ++
 src/util/virpci.c| 81 +++-
 src/util/virpci.h|  8 +
 3 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1d97c89..649da16 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1690,6 +1690,8 @@ virPCIDeviceFree;
 virPCIDeviceGetDriverPathAndName;
 virPCIDeviceGetIOMMUGroupDev;
 virPCIDeviceGetIOMMUGroupList;
+virPCIDeviceGetLinkCap;
+virPCIDeviceGetLinkSta;
 virPCIDeviceGetManaged;
 virPCIDeviceGetName;
 virPCIDeviceGetRemoveSlot;
@@ -1698,6 +1700,7 @@ virPCIDeviceGetStubDriver;
 virPCIDeviceGetUnbindFromStub;
 virPCIDeviceGetUsedBy;
 virPCIDeviceIsAssignable;
+virPCIDeviceIsPCIExpress;
 virPCIDeviceListAdd;
 virPCIDeviceListAddCopy;
 virPCIDeviceListCount;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index e0f2344..8ad28b8 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -130,7 +130,13 @@ struct _virPCIDeviceList {
 
 /* PCIe20 7.8.3  Device Capabilities Register (Offset 04h) */
 #define PCI_EXP_DEVCAP  0x4 /* Device capabilities */
-#define PCI_EXP_DEVCAP_FLR (1<<28) /* Function Level Reset */
+#define PCI_EXP_LNKCAP  0xc /* Link Capabilities */
+#define PCI_EXP_LNKSTA  0x12/* Link Status */
+#define PCI_EXP_DEVCAP_FLR (1<<28)  /* Function Level Reset */
+#define PCI_EXP_LNKCAP_SPEED0xf /* Maximum Link Speed */
+#define PCI_EXP_LNKCAP_WIDTH0x003f0 /* Maximum Link Width */
+#define PCI_EXP_LNKSTA_SPEED0x000f  /* Negotiated Link Speed */
+#define PCI_EXP_LNKSTA_WIDTH0x03f0  /* Negotiated Link Width */
 
 /* Header type 1 BR12 3.2 PCI-to-PCI Bridge Configuration Space Header Format 
*/
 #define PCI_PRIMARY_BUS 0x18/* BR12 3.2.5.2 Primary bus number */
@@ -2750,3 +2756,76 @@ virPCIGetVirtualFunctionInfo(const char 
*vf_sysfs_device_path ATTRIBUTE_UNUSED,
 return -1;
 }
 #endif /* __linux__ */
+
+int
+virPCIDeviceIsPCIExpress(virPCIDevicePtr dev)
+{
+int fd;
+int ret = -1;
+
+if ((fd = virPCIDeviceConfigOpen(dev, true)) < 0)
+return ret;
+
+if (virPCIDeviceInit(dev, fd) < 0)
+goto cleanup;
+
+ret = dev->pcie_cap_pos != 0;
+
+ cleanup:
+virPCIDeviceConfigClose(dev, fd);
+return ret;
+}
+
+int
+virPCIDeviceGetLinkCap(virPCIDevicePtr dev,
+   int *port,
+   unsigned int *speed,
+   unsigned int *width)
+{
+uint32_t t;
+int fd;
+int ret = -1;
+
+if ((fd = virPCIDeviceConfigOpen(dev, true) < 0))
+return ret;
+
+if (virPCIDeviceInit(dev, fd) < 0)
+goto cleanup;
+
+t = virPCIDeviceRead32(dev, fd, dev->pcie_cap_pos + PCI_EXP_LNKCAP);
+
+*port = t >> 0x18;
+*speed = t & PCI_EXP_LNKCAP_SPEED;
+*width = (t & PCI_EXP_LNKCAP_WIDTH) >> 4;
+ret = 0;
+
+ cleanup:
+virPCIDeviceConfigClose(dev, fd);
+return ret;
+}
+
+int
+virPCIDeviceGetLinkSta(virPCIDevicePtr dev,
+   unsigned int *speed,
+   unsigned int *width)
+{
+uint32_t t;
+int fd;
+int ret = -1;
+
+if ((fd = virPCIDeviceConfigOpen(dev, true) < 0))
+return ret;
+
+if (virPCIDeviceInit(dev, fd) < 0)
+goto cleanup;
+
+t = virPCIDeviceRead32(dev, fd, dev->pcie_cap_pos + PCI_EXP_LNKSTA);
+
+*speed = t & PCI_EXP_LNKSTA_SPEED;
+*width = (t & PCI_EXP_LNKSTA_WIDTH) >> 4;
+ret = 0;
+
+ cleanup:
+virPCIDeviceConfigClose(dev, fd);
+return ret;
+}
diff --git a/src/util/virpci.h b/src/util/virpci.h
index 20ffe54..0a608c2 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -176,4 +176,12 @@ int virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev,
  char **path,
  char **name);
 
+int virPCIDeviceIsPCIExpress(virPCIDevicePtr dev);
+int virPCIDeviceGetLinkCap(virPCIDevicePtr dev,
+   int *port,
+   unsigned int *speed,
+   unsigned int *width);
+int virPCIDeviceGetLinkSta(virPCIDevicePtr dev,
+   unsigned int *speed,
+   unsigned int *width);
 #endif /* __VIR_PCI_H__ */
-- 
1.9.3

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


[libvirt] [PATCH 07/12] interface_backend_udev: Implement link speed & state

2014-05-29 Thread Michal Privoznik
In previous commit the interface XML is prepared for exporting
information on NIC link speed and state. This commit implement
actual logic for getting such info and writing it into XML.

Signed-off-by: Michal Privoznik 
---
 src/interface/interface_backend_udev.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/src/interface/interface_backend_udev.c 
b/src/interface/interface_backend_udev.c
index c5353ea..c8940ce 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -1036,6 +1036,8 @@ udevGetIfaceDef(struct udev *udev, const char *name)
 const char *mtu_str;
 char *vlan_parent_dev = NULL;
 const char *devtype;
+const char *operstate;
+const char *link_speed;
 
 /* Allocate our interface definition structure */
 if (VIR_ALLOC(ifacedef) < 0)
@@ -1059,6 +1061,23 @@ udevGetIfaceDef(struct udev *udev, const char *name)
udev_device_get_sysattr_value(dev, "address")) < 0)
 goto error;
 
+operstate = udev_device_get_sysattr_value(dev, "operstate");
+if ((ifacedef->state = virInterfaceStateTypeFromString(operstate)) <= 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Unable to parse operstate: %s"),
+   operstate);
+goto error;
+}
+
+link_speed = udev_device_get_sysattr_value(dev, "speed");
+if (link_speed &&
+virStrToLong_ul(link_speed, NULL, 10, &ifacedef->speed) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Unable to parse speed: %s"),
+   link_speed);
+goto error;
+}
+
 /* MTU */
 mtu_str = udev_device_get_sysattr_value(dev, "mtu");
 if (virStrToLong_ui(mtu_str, NULL, 10, &mtu) < 0) {
-- 
1.9.3

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


[libvirt] [PATCH 08/12] interface_backend_netcf: Implement link speed & state

2014-05-29 Thread Michal Privoznik
While the previous commit was pretty straightforward, things are
different with netcf as it doesn't exposed the bits we need yet.
However, we can work around it by fetching the info we need from
SYSFS.

Signed-off-by: Michal Privoznik 
---
 src/interface/interface_backend_netcf.c | 99 +
 1 file changed, 99 insertions(+)

diff --git a/src/interface/interface_backend_netcf.c 
b/src/interface/interface_backend_netcf.c
index 1b9ace5..40181ef 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -33,6 +33,7 @@
 #include "virlog.h"
 #include "virstring.h"
 #include "viraccessapicheck.h"
+#include "virfile.h"
 
 #define VIR_FROM_THIS VIR_FROM_INTERFACE
 
@@ -240,6 +241,96 @@ static struct netcf_if *interfaceDriverGetNetcfIF(struct 
netcf *ncf, virInterfac
 return iface;
 }
 
+/* Okay, the following two doesn't really belong here as they dump the info
+ * from SYSFS rather than netcf. But netcf is not yet exposing the info we
+ * need, so what. */
+#define SYSFS_PREFIX "/sys/class/net/"
+
+static int
+interfaceGetState(const char *name,
+  virInterfaceState *state)
+{
+int ret = -1;
+char *path = NULL;
+char *buf = NULL;
+char *tmp;
+
+if (virAsprintf(&path, SYSFS_PREFIX "%s/operstate", name) < 0)
+goto cleanup;
+
+if (virFileReadAll(path, 1024, &buf) < 0) {
+virReportSystemError(errno,
+ _("unable to read: %s"),
+ path);
+goto cleanup;
+}
+
+if (!(tmp = strchr(buf, '\n'))) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Unable to parse: %s"),
+   buf);
+goto cleanup;
+}
+
+*tmp = '\0';
+
+/* We shouldn't allow 0 here, because
+ * virInterfaceState enum starts from 1. */
+if ((*state = virInterfaceStateTypeFromString(buf)) <= 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Unable to parse: %s"),
+   buf);
+goto cleanup;
+}
+
+ret = 0;
+ cleanup:
+VIR_FREE(buf);
+VIR_FREE(path);
+return ret;
+}
+
+static int
+interfaceGetSpeed(const char *name,
+  unsigned long *speed)
+{
+int ret = -1;
+char *path = NULL;
+char *buf = NULL;
+char *tmp;
+
+if (virAsprintf(&path, SYSFS_PREFIX "%s/speed", name) < 0)
+goto cleanup;
+
+if (virFileReadAll(path, 1024, &buf) < 0) {
+/* Some devices doesn't report speed, in which case we get EINVAL */
+if (errno == EINVAL) {
+ret = 0;
+goto cleanup;
+}
+virReportSystemError(errno,
+ _("unable to read: %s"),
+ path);
+goto cleanup;
+}
+
+if (virStrToLong_ul(buf, &tmp, 10, speed) < 0 ||
+*tmp != '\n') {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Unable to parse: %s"),
+   buf);
+goto cleanup;
+}
+
+ret = 1;
+ cleanup:
+VIR_FREE(buf);
+VIR_FREE(path);
+return ret;
+}
+
+/* Ond of sysfs hacks */
+
 static int
 netcfInterfaceObjIsActive(struct netcf_if *iface,
   bool *active)
@@ -840,6 +931,14 @@ static char *netcfInterfaceGetXMLDesc(virInterfacePtr 
ifinfo,
 if (virInterfaceGetXMLDescEnsureACL(ifinfo->conn, ifacedef) < 0)
 goto cleanup;
 
+if (interfaceGetState(ifacedef->name, &ifacedef->state) < 0)
+goto cleanup;
+
+/* querying inteface speed makes sense only sometimes */
+if (ifacedef->state == VIR_INTERFACE_STATE_UP &&
+interfaceGetSpeed(ifacedef->name, &ifacedef->speed) < 0)
+goto cleanup;
+
 ret = virInterfaceDefFormat(ifacedef);
 if (!ret) {
 /* error was already reported */
-- 
1.9.3

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


[libvirt] [PATCH 11/12] Expose IOMMU and VFIO capabilities from virCaps

2014-05-29 Thread Michal Privoznik
This piece of information may be useful for management application to
decide if a domain with a device passthrough can be started on given
host or not.

Signed-off-by: Michal Privoznik 
---

Notes:
I'm not very happy with the element names, but they're the best I
could come up with so far. If you have any better suggestion I am
all ears.

 docs/formatcaps.html.in  |  8 +++-
 docs/schemas/capability.rng  | 12 
 src/conf/capabilities.c  |  4 
 tests/capabilityschemadata/caps-qemu-kvm.xml |  2 ++
 tests/capabilityschemadata/caps-test.xml |  2 ++
 tests/capabilityschemadata/caps-test2.xml|  2 ++
 tests/capabilityschemadata/caps-test3.xml|  2 ++
 tests/xencapsdata/xen-i686-pae-hvm.xml   |  2 ++
 tests/xencapsdata/xen-i686-pae.xml   |  2 ++
 tests/xencapsdata/xen-i686.xml   |  2 ++
 tests/xencapsdata/xen-ia64-be-hvm.xml|  2 ++
 tests/xencapsdata/xen-ia64-be.xml|  2 ++
 tests/xencapsdata/xen-ia64-hvm.xml   |  2 ++
 tests/xencapsdata/xen-ia64.xml   |  2 ++
 tests/xencapsdata/xen-ppc64.xml  |  2 ++
 tests/xencapsdata/xen-x86_64-hvm.xml |  2 ++
 tests/xencapsdata/xen-x86_64.xml |  2 ++
 17 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/docs/formatcaps.html.in b/docs/formatcaps.html.in
index d060a5b..eb8c905 100644
--- a/docs/formatcaps.html.in
+++ b/docs/formatcaps.html.in
@@ -35,6 +35,8 @@ BIOS you will see
   
   
 
+true
+true
   
 
   
@@ -78,7 +80,11 @@ BIOS you will see
   Suspend-to-Disk (S4) and Hybrid-Suspend (a combination of S3
   and S4). In case the host does not support
   any such feature, then an empty 
-  tag will be shown. 
+  tag will be shown. Then, two elements
+   and 
+  expose the fact, whether the host supports legacy device
+  passthrough with IOMMU cooperation or newer Virtual function
+  I/O.
 The second block (in blue) indicates the paravirtualization
   support of the Xen support, you will see the os_type of xen
   to indicate a paravirtual kernel, then architecture
diff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rng
index d2d9776..3b378eb 100644
--- a/docs/schemas/capability.rng
+++ b/docs/schemas/capability.rng
@@ -48,6 +48,18 @@
   
 
   
+  
+  
+  false
+  true
+  
+  
+  
+  
+  false
+  true
+  
+  
 
   
 
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 9561ba3..a91f37b 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -901,6 +901,10 @@ virCapabilitiesFormatXML(virCapsPtr caps)
 virBufferAddLit(&buf, "\n");
 }
 
+/* KVM and VFIO features */
+virBufferAsprintf(&buf, "%s\n", caps->host.legacyKVMPassthrough 
? "true" : "false");
+virBufferAsprintf(&buf, "%s\n", caps->host.VFIOPassthrough ? 
"true" : "false");
+
 virBufferAdjustIndent(&buf, -2);
 virBufferAddLit(&buf, "\n\n");
 
diff --git a/tests/capabilityschemadata/caps-qemu-kvm.xml 
b/tests/capabilityschemadata/caps-qemu-kvm.xml
index 55faa16..1a7fca9 100644
--- a/tests/capabilityschemadata/caps-qemu-kvm.xml
+++ b/tests/capabilityschemadata/caps-qemu-kvm.xml
@@ -28,6 +28,8 @@
   system_u:system_r:svirt_t:s0
   system_u:system_r:svirt_tcg_t:s0
 
+false
+false
   
 
   
diff --git a/tests/capabilityschemadata/caps-test.xml 
b/tests/capabilityschemadata/caps-test.xml
index 64f9bb6..72bfafc 100644
--- a/tests/capabilityschemadata/caps-test.xml
+++ b/tests/capabilityschemadata/caps-test.xml
@@ -36,6 +36,8 @@
 
   
 
+true
+false
   
 
   
diff --git a/tests/capabilityschemadata/caps-test2.xml 
b/tests/capabilityschemadata/caps-test2.xml
index a99c1b8..04c9b09 100644
--- a/tests/capabilityschemadata/caps-test2.xml
+++ b/tests/capabilityschemadata/caps-test2.xml
@@ -33,6 +33,8 @@
 tcp
   
 
+false
+true
   
 
   
diff --git a/tests/capabilityschemadata/caps-test3.xml 
b/tests/capabilityschemadata/caps-test3.xml
index 7e21f85..9374077 100644
--- a/tests/capabilityschemadata/caps-test3.xml
+++ b/tests/capabilityschemadata/caps-test3.xml
@@ -85,6 +85,8 @@
   107:107
   107:107
 
+true
+true
   
 
 
diff --git a/tests/xencapsdata/xen-i686-pae-hvm.xml 
b/tests/xencapsdata/xen-i686-pae-hvm.xml
index 872e5f6..4f3c720 100644
--- a/tests/xencapsdata/xen-i686-pae-hvm.xml
+++ b/tests/xencapsdata/xen-i686-pae-hvm.xml
@@ -14,6 +14,8 @@
 xenmigr
   
 
+false
+false
   
 
   
diff --git a/tests/xencapsdata/xen-i686-pae.xml 
b/tests/xencapsdata/xen-i686-pae.xml
index 3dba6eb..f24306e

[libvirt] [PATCH 09/12] virhostdev: Move IOMMU and VFIO funcs from qemu

2014-05-29 Thread Michal Privoznik
The functions in question are qemuHostdevHostSupportsPassthroughLegacy
and qemuHostdevHostSupportsPassthroughVFIO. At the same time the
functions are renamed to match 'vir' prefix instead of 'qemu' one.

Signed-off-by: Michal Privoznik 
---
 src/libvirt_private.syms |  2 ++
 src/qemu/qemu_driver.c   |  4 +--
 src/qemu/qemu_hostdev.c  | 76 ++--
 src/qemu/qemu_hostdev.h  |  2 --
 src/util/virhostdev.c| 73 ++
 src/util/virhostdev.h|  4 +++
 6 files changed, 83 insertions(+), 78 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5e908d6..9a942ec 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1340,6 +1340,8 @@ virHookPresent;
 
 
 # util/virhostdev.h
+virHostdevHostSupportsPassthroughLegacy;
+virHostdevHostSupportsPassthroughVFIO;
 virHostdevManagerGetDefault;
 virHostdevPCINodeDeviceDetach;
 virHostdevPCINodeDeviceReAttach;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index aa7deb3..d8d0e89 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11313,8 +11313,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
 int ret = -1;
 virNodeDeviceDefPtr def = NULL;
 char *xml = NULL;
-bool legacy = qemuHostdevHostSupportsPassthroughLegacy();
-bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
+bool legacy = virHostdevHostSupportsPassthroughLegacy();
+bool vfio = virHostdevHostSupportsPassthroughVFIO();
 virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
 
 virCheckFlags(0, -1);
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 706db0c..39dacb2 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -23,7 +23,6 @@
 
 #include 
 
-#include 
 #include 
 #include 
 #include 
@@ -84,84 +83,13 @@ qemuUpdateActiveSCSIHostdevs(virQEMUDriverPtr driver,
 }
 
 
-bool
-qemuHostdevHostSupportsPassthroughVFIO(void)
-{
-DIR *iommuDir = NULL;
-struct dirent *iommuGroup = NULL;
-bool ret = false;
-int direrr;
-
-/* condition 1 - /sys/kernel/iommu_groups/ contains entries */
-if (!(iommuDir = opendir("/sys/kernel/iommu_groups/")))
-goto cleanup;
-
-while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) {
-/* skip ./ ../ */
-if (STRPREFIX(iommuGroup->d_name, "."))
-continue;
-
-/* assume we found a group */
-break;
-}
-
-if (direrr < 0 || !iommuGroup)
-goto cleanup;
-/* okay, iommu is on and recognizes groups */
-
-/* condition 2 - /dev/vfio/vfio exists */
-if (!virFileExists("/dev/vfio/vfio"))
-goto cleanup;
-
-ret = true;
-
- cleanup:
-if (iommuDir)
-closedir(iommuDir);
-
-return ret;
-}
-
-
-#if HAVE_LINUX_KVM_H
-# include 
-bool
-qemuHostdevHostSupportsPassthroughLegacy(void)
-{
-int kvmfd = -1;
-bool ret = false;
-
-if ((kvmfd = open("/dev/kvm", O_RDONLY)) < 0)
-goto cleanup;
-
-# ifdef KVM_CAP_IOMMU
-if ((ioctl(kvmfd, KVM_CHECK_EXTENSION, KVM_CAP_IOMMU)) <= 0)
-goto cleanup;
-
-ret = true;
-# endif
-
- cleanup:
-VIR_FORCE_CLOSE(kvmfd);
-
-return ret;
-}
-#else
-bool
-qemuHostdevHostSupportsPassthroughLegacy(void)
-{
-return false;
-}
-#endif
-
-
 static bool
 qemuPrepareHostdevPCICheckSupport(virDomainHostdevDefPtr *hostdevs,
   size_t nhostdevs,
   virQEMUCapsPtr qemuCaps)
 {
-bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy();
-bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
+bool supportsPassthroughKVM = virHostdevHostSupportsPassthroughLegacy();
+bool supportsPassthroughVFIO = virHostdevHostSupportsPassthroughVFIO();
 size_t i;
 
 /* assign defaults for hostdev passthrough */
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 05bd965..75cec9c 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -33,8 +33,6 @@ int qemuUpdateActiveUSBHostdevs(virQEMUDriverPtr driver,
 virDomainDefPtr def);
 int qemuUpdateActiveSCSIHostdevs(virQEMUDriverPtr driver,
  virDomainDefPtr def);
-bool qemuHostdevHostSupportsPassthroughLegacy(void);
-bool qemuHostdevHostSupportsPassthroughVFIO(void);
 int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
  const char *name,
  const unsigned char *uuid,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 9dd1df2..f791a10 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -24,6 +24,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -32,6 +33,10 @@
 #include 
 #include 
 
+#if HAVE_LINUX_KVM_H
+# include 
+#endif
+
 #include "virhostdev.h"
 #include "viralloc.h"
 #include "virstring.h"
@@ -1635,3 +1640,71 @@ virHostdevUpd

[libvirt] [PATCH 05/12] nodedev: Introduce to PCI devices

2014-05-29 Thread Michal Privoznik
This new element is there to represent PCI-Express capabilities
of a PCI devices, like link speed, number of lanes, etc.

Signed-off-by: Michal Privoznik 
---
 docs/formatnode.html.in|  19 
 docs/schemas/nodedev.rng   |  26 +
 src/conf/node_device_conf.c| 123 -
 src/conf/node_device_conf.h|  31 +-
 src/node_device/node_device_udev.c |  31 ++
 .../pci_8086_4238_pcie_wireless.xml|  26 +
 tests/nodedevxml2xmltest.c |   1 +
 7 files changed, 254 insertions(+), 3 deletions(-)
 create mode 100644 tests/nodedevschemadata/pci_8086_4238_pcie_wireless.xml

diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in
index b424c96..46ec2bc 100644
--- a/docs/formatnode.html.in
+++ b/docs/formatnode.html.in
@@ -110,6 +110,21 @@
 have a list of address subelements, one
 for each VF on this PF.
   
+  pci-express
+  
+  This optional element contains information on PCI Express part of
+  the device. For example, it can contain a child element
+  link which addresses the PCI Express device's link.
+  While a device has it's own capabilities
+  (validity='cap'), the actual run time capabilities
+  are negotiated on the device initialization
+  (validity='sta'). The link element then
+  contains three attributes: port which says in which
+  port is the device plugged in, speed (in
+  GigaTransfers per second) and width for the number
+  of lanes used. Since the port can't be negotiated, it's not
+  exposed in ./pci-express/link/[@validity='sta'].
+  
 
   
   usb_device
@@ -291,6 +306,10 @@
   
+ + + + diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 81ab4d4..79e8fd2 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -158,6 +158,32 @@ + + + + + + +cap +sta + + + + + + + + + + + + + + + + + + diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index e65b5e4..70634cc 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -58,6 +58,9 @@ VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST, "80203", "80211") +VIR_ENUM_IMPL(virPCIELinkSpeed, VIR_PCIE_LINK_SPEED_LAST, + "", "2.5", "5", "8") + static int virNodeDevCapsDefParseString(const char *xpath, xmlXPathContextPtr ctxt, @@ -218,6 +221,35 @@ void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, } } +static void +virPCIELinkFormat(virBufferPtr buf, + virPCIELinkPtr lnk, + const char *attrib) +{ +virBufferAsprintf(buf, "port >= 0) +virBufferAsprintf(buf, " port='%d'", lnk->port); +if (lnk->speed) +virBufferAsprintf(buf, " speed='%s'", + virPCIELinkSpeedTypeToString(lnk->speed)); +virBufferAsprintf(buf, " width='%d'", lnk->width); +virBufferAddLit(buf, "/>\n"); +} + +static void +virPCIEDeviceInfoFormat(virBufferPtr buf, +virPCIEDeviceInfoPtr info) +{ +virBufferAddLit(buf, "\n"); +virBufferAdjustIndent(buf, 2); + +virPCIELinkFormat(buf, &info->link_cap, "cap"); +virPCIELinkFormat(buf, &info->link_sta, "sta"); + +virBufferAdjustIndent(buf, -2); +virBufferAddLit(buf, "\n"); +} + char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) { virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -346,6 +378,8 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); } +if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCIE) +virPCIEDeviceInfoFormat(&buf, data->pci_dev.pci_express); break; case VIR_NODE_DEV_CAP_USB_DEV: virBuffer

[libvirt] [PATCH 01/12] Introduce virNodeHugeTLB

2014-05-29 Thread Michal Privoznik
The API queries huge page info in the host and reports it back
to the caller. This may be handy for management application to
decide whether to run a domain with huge pages enabled or not.

Signed-off-by: Michal Privoznik 
---
 daemon/remote.c  | 54 
 include/libvirt/libvirt.h.in |  6 +
 src/driver.h |  7 ++
 src/libvirt.c| 54 
 src/libvirt_public.syms  |  5 
 src/remote/remote_driver.c   | 48 +++
 src/remote/remote_protocol.x | 19 +++-
 src/remote_protocol-structs  | 13 +++
 8 files changed, 205 insertions(+), 1 deletion(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 34c96c9..95ff973 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -6115,6 +6115,60 @@ remoteDispatchDomainGetTime(virNetServerPtr server 
ATTRIBUTE_UNUSED,
 return rv;
 }
 
+static int remoteDispatchNodeHugeTlb(virNetServerPtr server ATTRIBUTE_UNUSED,
+ virNetServerClientPtr client,
+ virNetMessagePtr msg ATTRIBUTE_UNUSED,
+ virNetMessageErrorPtr rerr,
+ remote_node_huge_tlb_args *args,
+ remote_node_huge_tlb_ret *ret)
+{
+virTypedParameterPtr params = NULL;
+int nparams = 0;
+int rv = -1;
+struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
+
+if (!priv->conn) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+goto cleanup;
+}
+
+if (args->nparams > REMOTE_NODE_MEMORY_PARAMETERS_MAX) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
+goto cleanup;
+}
+if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
+goto cleanup;
+nparams = args->nparams;
+
+if (virNodeHugeTLB(priv->conn, args->type, params, &nparams, args->flags) 
< 0)
+goto cleanup;
+
+/* In this case, we need to send back the number of parameters
+ * supported
+ */
+if (args->nparams == 0) {
+ret->nparams = nparams;
+goto success;
+}
+
+if (remoteSerializeTypedParameters(params, nparams,
+   &ret->params.params_val,
+   &ret->params.params_len,
+   args->flags) < 0)
+goto cleanup;
+
+
+ success:
+rv = 0;
+
+ cleanup:
+if (rv < 0)
+virNetMessageSaveError(rerr);
+virTypedParamsFree(params, nparams);
+return rv;
+}
+
+
 /*- Helpers. -*/
 
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 260c971..cb1cad9 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -858,6 +858,12 @@ int virNodeSetMemoryParameters(virConnectPtr conn,
int nparams,
unsigned int flags);
 
+int virNodeHugeTLB(virConnectPtr conn,
+   int type,
+   virTypedParameterPtr params,
+   int *nparams,
+   unsigned int flags);
+
 /*
  *  node CPU map
  */
diff --git a/src/driver.h b/src/driver.h
index 5ac89d6..4acde08 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1070,6 +1070,12 @@ typedef int
  virTypedParameterPtr params,
  int nparams,
  unsigned int flags);
+typedef int
+(*virDrvNodeHugeTLB)(virConnectPtr conn,
+ int type,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags);
 
 typedef int
 (*virDrvNodeGetCPUMap)(virConnectPtr conn,
@@ -1376,6 +1382,7 @@ struct _virDriver {
 virDrvDomainGetMetadata domainGetMetadata;
 virDrvNodeGetMemoryParameters nodeGetMemoryParameters;
 virDrvNodeSetMemoryParameters nodeSetMemoryParameters;
+virDrvNodeHugeTLB nodeHugeTLB;
 virDrvNodeGetCPUMap nodeGetCPUMap;
 virDrvDomainFSTrim domainFSTrim;
 virDrvDomainSendProcessSignal domainSendProcessSignal;
diff --git a/src/libvirt.c b/src/libvirt.c
index f01b6dd..de20b0c 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -7561,6 +7561,60 @@ virNodeSetMemoryParameters(virConnectPtr conn,
 
 
 /**
+ * virNodeHugeTLB:
+ * @conn: pointer to the hypervisor connection
+ * @type: type
+ * @params: pointer to memory parameter object
+ *  (return value, allocated by the caller)
+ * @nparams: pointer to number of memory parameters; input and output
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Get information about host's huge pages. On input, @nparams
+ * gives the size of the @params array; on output, @n

[libvirt] [PATCH 02/12] Initial virsh exposure of virNodeHugeTLB

2014-05-29 Thread Michal Privoznik
The API is exposed as 'hugepage' command.

Signed-off-by: Michal Privoznik 
---
 tools/virsh-host.c | 62 ++
 tools/virsh.pod|  7 ++
 2 files changed, 69 insertions(+)

diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index cac6086..e71a341 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -644,6 +644,62 @@ cmdHostname(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 }
 
 /*
+ * "hugepages" command
+ */
+static const vshCmdInfo info_hugepages[] = {
+{.name = "help",
+ .data = N_("print hugepages info")
+},
+{.name = "desc",
+ .data = N_("print hugepages info")
+},
+{.name = NULL}
+};
+
+static const vshCmdOptDef opts_hugepages[] = {
+{.name = "node",
+ .type = VSH_OT_INT,
+ .help = N_("NUMA node")
+},
+{.name = NULL}
+};
+
+static bool
+cmdHugepages(vshControl *ctl, const vshCmd *cmd)
+{
+virTypedParameterPtr params = NULL;
+int nparams = 0;
+int node = -1; /* Overall stats */
+unsigned int flags = 0;
+bool ret = false;
+size_t i;
+
+if (vshCommandOptInt(cmd, "node", &node) < 0)
+return false;
+
+if (virNodeHugeTLB(ctl->conn, node, NULL, &nparams, flags) < 0)
+goto cleanup;
+
+params = vshCalloc(ctl, nparams, sizeof(*params));
+
+if (virNodeHugeTLB(ctl->conn, node, params, &nparams, flags) < 0)
+goto cleanup;
+
+vshPrint(ctl, _("Supported huge page sizes:\n"));
+for (i = 0; i < nparams; i++) {
+char *str = vshGetTypedParamValue(ctl, ¶ms[i]);
+vshPrint(ctl, "\t%-15s\t%s\n", params[i].field, str);
+VIR_FREE(str);
+}
+
+ret = 0;
+ cleanup:
+virTypedParamsFree(params, nparams);
+return ret;
+}
+
+
+/*
  * "uri" command
  */
 static const vshCmdInfo info_uri[] = {
@@ -964,6 +1020,12 @@ const vshCmdDef hostAndHypervisorCmds[] = {
  .info = info_hostname,
  .flags = 0
 },
+{.name = "hugepages",
+ .handler = cmdHugepages,
+ .opts = opts_hugepages,
+ .info = info_hugepages,
+ .flags = 0
+},
 {.name = "maxvcpus",
  .handler = cmdMaxvcpus,
  .opts = opts_maxvcpus,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 02671b4..5ba591e 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -279,6 +279,13 @@ Prints the hypervisor canonical URI, can be useful in 
shell mode.
 
 Print the hypervisor hostname.
 
+=item B [I]
+
+Print information on host huge pages. By default overall statistics are 
printed.
+To narrow down selection to a single NUMA node use pass it's number to I.
+As a special case, if NUMA node number equals to value of -1, the aggregated
+stats are printed out.
+
 =item B
 
 Print the XML representation of the hypervisor sysinfo, if available.
-- 
1.9.3

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


[libvirt] [PATCH 00/12] Couple of host info getting improvements

2014-05-29 Thread Michal Privoznik
The rationale is to fill in the gaps as described here:

https://wiki.openstack.org/wiki/VirtDriverGuestCPUMemoryPlacement

Note that these are targeted for 1.2.6.

Michal Privoznik (12):
  Introduce virNodeHugeTLB
  Initial virsh exposure of virNodeHugeTLB
  nodeinfo: Implement nodeHugeTLB
  virpci: Introduce virPCIDeviceIsPCIExpress and friends
  nodedev: Introduce  to PCI devices
  virInterface: Expose link state & speed
  interface_backend_udev: Implement link speed & state
  interface_backend_netcf: Implement link speed & state
  virhostdev: Move IOMMU and VFIO funcs from qemu
  virCaps: Introduce IOMMU and VFIO capabilities
  Expose IOMMU and VFIO capabilities from virCaps
  nodedev: Export NUMA node locality for PCI devices

 daemon/remote.c|  54 ++
 docs/formatcaps.html.in|   8 +-
 docs/formatnode.html.in|  25 +++
 docs/schemas/capability.rng|  12 ++
 docs/schemas/interface.rng |  27 +++
 docs/schemas/nodedev.rng   |  37 
 include/libvirt/libvirt.h.in   |  26 +++
 src/conf/capabilities.c|  50 ++
 src/conf/capabilities.h|  11 ++
 src/conf/interface_conf.c  |  39 -
 src/conf/interface_conf.h  |  15 ++
 src/conf/node_device_conf.c| 166 +-
 src/conf/node_device_conf.h|  32 +++-
 src/driver.h   |   7 +
 src/interface/interface_backend_netcf.c|  99 +++
 src/interface/interface_backend_udev.c |  19 ++
 src/libvirt.c  |  59 +++
 src/libvirt_private.syms   |  13 ++
 src/libvirt_public.syms|   5 +
 src/lxc/lxc_conf.c |   3 +
 src/node_device/node_device_udev.c |  38 
 src/nodeinfo.c | 192 +
 src/nodeinfo.h |   6 +
 src/parallels/parallels_driver.c   |   3 +
 src/phyp/phyp_driver.c |   3 +
 src/qemu/qemu_capabilities.c   |   3 +
 src/qemu/qemu_driver.c |  30 +++-
 src/qemu/qemu_hostdev.c|  93 ++
 src/qemu/qemu_hostdev.h|   2 -
 src/remote/remote_driver.c |  48 ++
 src/remote/remote_protocol.x   |  19 +-
 src/remote_protocol-structs|  13 ++
 src/uml/uml_conf.c |   3 +
 src/util/virhostdev.c  |  73 
 src/util/virhostdev.h  |   4 +
 src/util/virpci.c  |  81 -
 src/util/virpci.h  |   8 +
 src/vbox/vbox_tmpl.c   |   3 +
 tests/capabilityschemadata/caps-qemu-kvm.xml   |   2 +
 tests/capabilityschemadata/caps-test.xml   |   2 +
 tests/capabilityschemadata/caps-test2.xml  |   2 +
 tests/capabilityschemadata/caps-test3.xml  |   2 +
 tests/interfaceschemadata/bridge-no-address.xml|   1 +
 tests/interfaceschemadata/bridge.xml   |   1 +
 tests/interfaceschemadata/ethernet-dhcp.xml|   1 +
 tests/nodedevschemadata/pci_1002_71c4.xml  |   1 +
 tests/nodedevschemadata/pci_8086_10c9_sriov_pf.xml |   1 +
 .../pci_8086_4238_pcie_wireless.xml|  26 +++
 tests/nodedevxml2xmltest.c |   1 +
 tests/xencapsdata/xen-i686-pae-hvm.xml |   2 +
 tests/xencapsdata/xen-i686-pae.xml |   2 +
 tests/xencapsdata/xen-i686.xml |   2 +
 tests/xencapsdata/xen-ia64-be-hvm.xml  |   2 +
 tests/xencapsdata/xen-ia64-be.xml  |   2 +
 tests/xencapsdata/xen-ia64-hvm.xml |   2 +
 tests/xencapsdata/xen-ia64.xml |   2 +
 tests/xencapsdata/xen-ppc64.xml|   2 +
 tests/xencapsdata/xen-x86_64-hvm.xml   |   2 +
 tests/xencapsdata/xen-x86_64.xml   |   2 +
 tools/virsh-host.c |  62 +++
 tools/virsh.pod|   7 +
 61 files changed, 1371 insertions(+), 87 deletions(-)
 create mode 100644 tests/nodedevschemadata/pci_8086_4238_pcie_wireless.xml

-- 
1.9.3

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


Re: [libvirt] [PATCH v5] bhyve: implement PCI address allocation

2014-05-29 Thread Roman Bogorodskiy
  Ján Tomko wrote:

> > One more thing that bothers me: after this change user needs to
> > re-define a domain, otherwise domain will have no addresses and will
> > fail to start.
> > 
> > Could/should it be handled somehow?
>
> Yes, it would be nice not to break upgrades :)
> In QEMU driver, this is done by calling AssignAddresses from QemuProcessStart.

Thanks, I'll take a look how Qemu driver does that.

PS Looks like I'm late with getting this feature into the current
release as it's unlikely I'll be able to get to it until this weekend. 

Roman Bogorodskiy

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


Re: [libvirt] [PATCH] Add capability to example AppArmor profile

2014-05-29 Thread Jamie Strandboge
On 05/29/2014 01:03 AM, Steven Leung wrote:
> I encountered an AppArmor denial in Ubuntu 14.04.  I had filed a bug
> here https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1324251
> 
...

> +  # to create and modify with 9p shares
> +  capability fowner,
> +  capability fsetid,

I commented on this in the bug. This may be ok, but would like more info.

-- 
Jamie Strandboge http://www.ubuntu.com/



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