Re: [libvirt] Entering freeze for libvirt-1.2.19

2015-08-28 Thread Martin Kletzander

On Fri, Aug 28, 2015 at 06:25:01AM +0200, Michal Privoznik wrote:

On 27.08.2015 11:41, Martin Kletzander wrote:

On Thu, Aug 27, 2015 at 09:52:53AM +0800, Daniel Veillard wrote:


  So I have tagged rc1 in git and pushed signed tarball and rpms to
the usual place:
 ftp://libvirt.org/libvirt/

The release works just fine in my limited testing, but others should
try it out to check portability and more advanced functionalities.

I will likely push rc2 at the end of the week-end and the final release
on Tuesday or Wednesday, assuming no big issue is raised in the meantime.

 thanks for giving it a try.
 I also note that we have some CI test failing, not for core libvirt
but perl bindings, virt-manager, ... it would be good to investigate
before
we push the release:
 https://ci.centos.org/view/libvirt-project/



Having a quick look it seems there's still the rename API missing in
libvirt-python and that's why all the stuff on top of python is
failing.  I'll see what I can do, even though I'm out till end of the
week.


I don't know what you mean. I can see this in build/libvirt.py after I build 
libvirt-python:



Sorry for that, I based that solely on the CI which seems broken
because it works for me.  And not that it only works for me, I also
already tried using the rename API in python myself and it was
successful.  Sorry for the noise then.

Anyway, some things in the CI are still weirdly broken, and I don't
know if it's all related to the CI settings or not.  But it might not
be limiting for us.

Martin


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

Re: [libvirt] [PATCH v3 2/5] vz: add migration backbone code

2015-08-28 Thread Nikolay Shirokovskiy


On 27.08.2015 13:34, Daniel P. Berrange wrote:
 On Tue, Aug 25, 2015 at 12:04:14PM +0300, nshirokovs...@virtuozzo.com wrote:
 From: Nikolay Shirokovskiy nshirokovs...@virtuozzo.com

 This patch makes basic vz migration possible. For example by virsh:
   virsh -c vz:///system migrate --direct $NAME $STUB vz+ssh://$DST/system

 $STUB could be anything as it is required virsh argument but it is not
 used in direct migration.

 Vz migration is implemented as direct migration. The reason is that vz sdk do
 all the job. Prepare phase function is used to pass session uuid from
 destination to source so we don't introduce new rpc call.
 
 Looking more closely at migration again, the scenario you have is pretty
 much identical to the Xen scenario, in that the hypervisor actually
 manages the migration, but you still need a connection to dest libvirtd
 to fetch some initialization data.
 
 You have claimed you are implementing, what we describe as direct, unmanaged
 migration on this page:
 
   http://libvirt.org/migration.html
 
 But based on the fact that you need to talk to dest libvirtd, you should
 in fact implement 'direct, managed' migration - this name is slightly
 misleading as the VZ SDK is still actually managing it.
 
 Since you don't need to have the begin/confirm phases, you also don't
 need to implement the V3 migration protocol - it is sufficient to just
 use V1.
 
 This doesn't need many changes in your patch fortunately.
 
 

I've been looking at common migration code for rather long time and think that
using direct managed scheme for vz migration could lead to problems. Let me
share my concerns.

1. Migration protocol of version1 differs from version3 not only by number of
stages. Version3 supports extended parameters like
VIR_MIGRATE_PARAM_GRAPHICS_URI which have meaning for vz migration too. Thus in
future we could move to implementing version3 as well.

2. Direct managed stages doesn't have a meaning do anything on source, then on
destination and so on. They interconnected and this interconnection is given in
migration algorithm. For version3 (virDomainMigrateVersion3Full) it is more
noticeable. If finish3 phase fail then we cancel migration on confirm3 phase.
See, we treat this phases specifically - on perform3 we think we move data, on
finish we think we start domain on destination, on comfirm we think we stop
domain on source. That is how qemu migration works and that is how we think of
phases when we implement direct managed algorithm. So phases have some
contracts. If we implement vz migration thru this scheme we could not keep
these contracts as perform3 phase not only move data, but also kill source
domain and start destination. The worst things the user could get are an
erroneous warnings in logs and overall migration failure reports on actual
migration success in case of side effect failures like rpc or OOM. The worser
is that you should keep in mind that phases imlementation contracts are vague.

So as as version1 scheme is quite simple and phase contracts are looser that
for version3 we could go this way but i see potential problems (at least for
developer). Thus suggest keep contracts of phases of all versions of direct
managed migration clear and hide all differences by implementing p2p or direct
scheme.

The questing arises how these two differ. Documentation states that p2p is when
libvirt daemon manages migrations and direct is when all managing is done by
hypervisor. As vz migration needs some help from destination daemon it looks
like a candidate for p2p. But as this help is as just little as help
authenticate i suggest to think of it as of direct. From implementation point
of view there is no difference, from user point of view the difference is only
in flags. Another argument is that if we take qemu we see that p2p is just go
thru same steps as direct managed, the most of difference is that managing move
from client to daemon. That is p2p and direct managed are some kind of coupled.
If there is p2p then direct managed should be possible too and this is not the
case of vz migration.








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


Re: [libvirt] [PATCH] network type ethernet not needs to be reconnected

2015-08-28 Thread Vasiliy Tolstov
2015-08-24 14:56 GMT+03:00 Vasiliy Tolstov v.tols...@selfip.ru:
 2015-08-24 14:45 GMT+03:00 Laine Stump la...@laine.org:
 I've been looking back at the history of why this code was added in the
 first place to make sure we're not inadvertently breaking something else.

 It looks like originally that code did check that ipaddr hadn't changed
 (when there was a single IP address), which wasn't needed but also
 didn't hurt anything (since ipaddr would always be 0 for type='ethernet'
 in the qemu driver. Then recently (commit aa2cc7) support for multiple
 IP addresses with type='ethernet' was added (apparently for LXC, but
 also added for openvz), any code that had touched ethernet.ipaddr was
 changed to look at nips and the ip array instead, but the code that
 replaced the unnecessary but innocuous check in qemu_hotplug.c was done
 incorrectly. So the correct thing *is* to simply remove the check.

 All of that is a long winded way of saying ACK. I'll push it in awhile.


 Thanks!


I don't see this change in current master. Does it goes to 1.2.19 or to 1.2.20?

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

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


Re: [libvirt] [PATCH 3/4] lxc_container: Turn lxcAttachNS into calling virProcessSetNamespaces

2015-08-28 Thread Daniel P. Berrange
On Fri, Aug 28, 2015 at 06:40:39AM -0400, John Ferlan wrote:
 
 
 On 08/26/2015 09:06 PM, Michal Privoznik wrote:
  Now that virProcessSetNamespaces() does accept FD list in the
  correct format, we can simply turn lxcAttachNS into calling
  virProcessSetNamespaces().
  
  Signed-off-by: Michal Privoznik mpriv...@redhat.com
  ---
   src/lxc/lxc_container.c | 22 +++---
   1 file changed, 3 insertions(+), 19 deletions(-)
  
  diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
  index feb8fad..eb7cad6 100644
  --- a/src/lxc/lxc_container.c
  +++ b/src/lxc/lxc_container.c
  @@ -2184,25 +2184,9 @@ static int 
  lxcContainerDropCapabilities(virDomainDefPtr def ATTRIBUTE_UNUSED,
*/
   static int lxcAttachNS(int *ns_fd)
   {
  -size_t i;
  -if (ns_fd)
  -for (i = 0; i  VIR_LXC_DOMAIN_NAMESPACE_LAST; i++) {
  -if (ns_fd[i]  0)
  -continue;
  -VIR_DEBUG(Setting into namespace\n);
  -/* We get EINVAL if new NS is same as the current
  - * NS, or if the fd namespace doesn't match the
  - * type passed to setns()'s second param. Since we
  - * pass 0, we know the EINVAL is harmless
  - */
  -if (setns(ns_fd[i], 0)  0 
  -errno != EINVAL) {
  -virReportSystemError(errno, _(failed to set namespace 
  '%s'),
  - virLXCDomainNamespaceTypeToString(i));
  -return -1;
  -}
  -VIR_FORCE_CLOSE(ns_fd[i]);
  -}
  +if (ns_fd 
  +virProcessSetNamespaces(VIR_LXC_DOMAIN_NAMESPACE_LAST, ns_fd)  0)
 
 Coverity wasn't very happy with this one - I got:
 
 (1) Event suspicious_sizeof:  Passing argument ns_fd of type int *
 and argument VIR_LXC_DOMAIN_NAMESPACE_LAST to function
 virProcessSetNamespaces is suspicious because a multiple of sizeof
 (int) /*4*/ is expected.

IIUC, coverity is saying here that 'size_t nfdlist' is supposed to
be a multiple of sizeof(int), which is clearly wrong. it is the
number of int elements in the array, so sizeof() doesn't apply.

I don't see any code change required here at all, I think coverity
is simply wrong.


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

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


[libvirt] [libvirt-test-api][PATCH] Add new test case for allocPages API

2015-08-28 Thread Luyao Huang
Signed-off-by: Luyao Huang lhu...@redhat.com
---
 cases/test_connection.conf |  4 ++
 repos/virconn/connection_allocPages.py | 88 ++
 2 files changed, 92 insertions(+)
 create mode 100644 repos/virconn/connection_allocPages.py

diff --git a/cases/test_connection.conf b/cases/test_connection.conf
index 336b1ad..600ec32 100644
--- a/cases/test_connection.conf
+++ b/cases/test_connection.conf
@@ -77,3 +77,7 @@ virconn:connection_getMemoryParameters
 virconn:connection_getMemoryStats
 conn
 qemu:///system
+
+virconn:connection_allocPages
+conn
+qemu:///system
diff --git a/repos/virconn/connection_allocPages.py 
b/repos/virconn/connection_allocPages.py
new file mode 100644
index 000..9ddd474
--- /dev/null
+++ b/repos/virconn/connection_allocPages.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+
+import libvirt
+from libvirt import libvirtError
+import lxml
+import lxml.etree
+
+required_params = ()
+optional_params = {'conn': ''}
+
+HOST_HUGEPAGE = 
'/sys/devices/system/node/node%d/hugepages/hugepages-%dkB/nr_hugepages'
+
+def get_host_pagesize(conn):
+ret = []
+tree = lxml.etree.fromstring(conn.getCapabilities())
+
+set = tree.xpath(/capabilities/host/cpu/pages)
+for n in set:
+ret.append(int(n.attrib['size']))
+
+return ret
+
+def get_host_pagecount(pagesize):
+try:
+return int(open(HOST_HUGEPAGE % (0, pagesize)).read())
+except IOError:
+return -1
+
+def connection_allocPages(params):
+
+   test API for allocPages in class virConnect
+
+logger = params['logger']
+fail=0
+
+try:
+conn=libvirt.open(params['conn'])
+logger.info(get connection to libvirtd)
+list1 = get_host_pagesize(conn)
+
+except libvirtError, e:
+logger.error(API error message: %s % e.message)
+return 1
+
+for i in list1:
+logger.info(test hugepage size %d % i)
+
+if get_host_pagecount(i) == -1:
+logger.info(Skip system page size %d % i)
+continue
+
+ test flag VIR_NODE_ALLOC_PAGES_SET 
+try:
+cur_count = get_host_pagecount(i)
+conn.allocPages({i : cur_count + 1}, 0, 1, 
libvirt.VIR_NODE_ALLOC_PAGES_SET)
+if get_host_pagecount(i) != cur_count + 1:
+logger.info(libvirt set a wrong page count to %dKiB hugepage 
% i)
+fail = 1
+except libvirtError, e:
+if Allocated only in e.message:
+tmp_count = int(e.message.replace( , )[-1:])
+
+if tmp_count != get_host_pagecount(i):
+logger.info(libvirt output %dKiB hugepage count is not 
right % i)
+fail = 1
+else:
+logger.error(API error message: %s % e.message)
+return 1
+
+ test flag VIR_NODE_ALLOC_PAGES_ADD 
+try:
+cur_count = get_host_pagecount(i)
+conn.allocPages({i : 1}, 0, 1, libvirt.VIR_NODE_ALLOC_PAGES_ADD)
+if get_host_pagecount(i) != cur_count + 1:
+logger.info(libvirt set a wrong page count to %dKiB hugepage 
% i)
+fail = 1
+except libvirtError, e:
+if Allocated only in e.message:
+tmp_count = int(e.message.replace( , )[-1:])
+
+if tmp_count != get_host_pagecount(i):
+logger.info(libvirt output %dKiB hugepage count is not 
right % i)
+fail = 1
+else:
+logger.error(API error message: %s % e.message)
+return 1
+
+return fail
-- 
1.8.3.1

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


Re: [libvirt] Entering freeze for libvirt-1.2.19

2015-08-28 Thread Daniel P. Berrange
On Fri, Aug 28, 2015 at 08:20:22AM +0200, Martin Kletzander wrote:
 On Fri, Aug 28, 2015 at 06:25:01AM +0200, Michal Privoznik wrote:
 On 27.08.2015 11:41, Martin Kletzander wrote:
 On Thu, Aug 27, 2015 at 09:52:53AM +0800, Daniel Veillard wrote:
 
   So I have tagged rc1 in git and pushed signed tarball and rpms to
 the usual place:
  ftp://libvirt.org/libvirt/
 
 The release works just fine in my limited testing, but others should
 try it out to check portability and more advanced functionalities.
 
 I will likely push rc2 at the end of the week-end and the final release
 on Tuesday or Wednesday, assuming no big issue is raised in the meantime.
 
  thanks for giving it a try.
  I also note that we have some CI test failing, not for core libvirt
 but perl bindings, virt-manager, ... it would be good to investigate
 before
 we push the release:
  https://ci.centos.org/view/libvirt-project/
 
 
 Having a quick look it seems there's still the rename API missing in
 libvirt-python and that's why all the stuff on top of python is
 failing.  I'll see what I can do, even though I'm out till end of the
 week.
 
 I don't know what you mean. I can see this in build/libvirt.py after I build 
 libvirt-python:
 
 
 Sorry for that, I based that solely on the CI which seems broken
 because it works for me.  And not that it only works for me, I also
 already tried using the rename API in python myself and it was
 successful.  Sorry for the noise then.
 
 Anyway, some things in the CI are still weirdly broken, and I don't
 know if it's all related to the CI settings or not.  But it might not
 be limiting for us.

Yeah, the CI is somewhat broken for the Perl binding too - both show
issues finding the correct libvirt.so that was just built from git,
so fail to resolve symbols correctly. I think this is a CI configuration
mistake / build root corruption, as it previously used to work fine
about a week ago.


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

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


Re: [libvirt] [PATCH] Revert LXC: show used memory as 0 when domain is not active

2015-08-28 Thread Daniel P. Berrange
On Thu, Aug 27, 2015 at 04:47:24PM -0600, Eric Blake wrote:
 On 08/27/2015 04:38 PM, Jim Fehlig wrote:
 
  This reverts commit 1ce7c1d20cfd5afb26d2dbc88201085d52415d0e,
  which introduced a significant semantic change to the
  virDomainGetInfo() API. Additionally, the change was only
  made to 2 of the 15 virt drivers.
 
 
  I guess we should probably do this in the stable branch too, since I
  think it made it into the most recent release.

  Erm, the change is out for a while now:
 
  git desc 1ce7c1d20cfd5afb26d2dbc88201085d52415d0e
  v1.2.6-225-g1ce7c1d
  
 
  Oh yes, so it is. I'm still inclined to say we should be reverting it as
  I think it is wrong. The change was based on the misleading field name
  shown by virsh. The info-memory field shows the current balloon target,
  and conceptually this should be equal to the max memory if the ballooon
  driver is not active. As such I think it should be equal to max memory
  if shutoff too.

  
  Yikes, I forgot to commit this before leaving for travel/vacation. Is it
  still ok to commit to master? And just to be clear, then cherry pick to
  1.2.7-1.2.18 maint branches?
 
 Yes, that sounds like the best way to handle it.

Agreed


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

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


Re: [libvirt] [PATCH] virVMXParseDisk: Recognize scsi-passthru

2015-08-28 Thread Matthias Bolte
2015-08-28 11:36 GMT+02:00 Michal Privoznik mpriv...@redhat.com:
 https://bugzilla.redhat.com/show_bug.cgi?id=1172544

 So, imagine you have this config:

 scsi0:1.present = TRUE
 scsi0:1.deviceType = scsi-passthru
 scsi0:1.fileName = /vmfs/devices/cdrom/mpx.vmhba32:C0:T0:L0
 scsi0:1.allowGuestConnectionControl = FALSE

 So far, libvirt does not recognize this pattern and fails. What
 if we produce the following XML to it?

 disk type='block' device='disk'
   source dev='/vmfs/devices/cdrom/mpx.vmhba32:C0:T0:L0'/
   target dev='sdb' bus='scsi'/
   address type='drive' controller='0' bus='0' target='0' unit='1'/
 /disk

 Signed-off-by: Michal Privoznik mpriv...@redhat.com
 ---
  src/vmx/vmx.c | 11 +++
  1 file changed, 11 insertions(+)

 diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
 index 36e2891..6d83d81 100644
 --- a/src/vmx/vmx.c
 +++ b/src/vmx/vmx.c
 @@ -2187,6 +2187,17 @@ virVMXParseDisk(virVMXContext *ctx, 
 virDomainXMLOptionPtr xmlopt, virConfPtr con
   * function to parse a CDROM device may handle it.
   */
  goto ignore;
 +} else if (STREQ_NULLABLE(deviceType, scsi-passthru)) {
 +char *tmp;
 +
 +virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK);
 +if (!(tmp = ctx-parseFileName(fileName, ctx-opaque)))
 +goto cleanup;
 +if (virDomainDiskSetSource(*def, tmp)  0) {
 +VIR_FREE(tmp);
 +goto cleanup;
 +}
 +VIR_FREE(tmp);
  } else {
  virReportError(VIR_ERR_INTERNAL_ERROR,
 _(Invalid or not yet handled value '%s' 
 --
 2.4.6


It looks like you're dealing with this in the wrong part of the
parser. But let me have a more detailed look at the reported issue.

-- 
Matthias Bolte
http://photron.blogspot.com

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


Re: [libvirt] [PATCH 3/4] lxc_container: Turn lxcAttachNS into calling virProcessSetNamespaces

2015-08-28 Thread John Ferlan


On 08/26/2015 09:06 PM, Michal Privoznik wrote:
 Now that virProcessSetNamespaces() does accept FD list in the
 correct format, we can simply turn lxcAttachNS into calling
 virProcessSetNamespaces().
 
 Signed-off-by: Michal Privoznik mpriv...@redhat.com
 ---
  src/lxc/lxc_container.c | 22 +++---
  1 file changed, 3 insertions(+), 19 deletions(-)
 
 diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
 index feb8fad..eb7cad6 100644
 --- a/src/lxc/lxc_container.c
 +++ b/src/lxc/lxc_container.c
 @@ -2184,25 +2184,9 @@ static int 
 lxcContainerDropCapabilities(virDomainDefPtr def ATTRIBUTE_UNUSED,
   */
  static int lxcAttachNS(int *ns_fd)
  {
 -size_t i;
 -if (ns_fd)
 -for (i = 0; i  VIR_LXC_DOMAIN_NAMESPACE_LAST; i++) {
 -if (ns_fd[i]  0)
 -continue;
 -VIR_DEBUG(Setting into namespace\n);
 -/* We get EINVAL if new NS is same as the current
 - * NS, or if the fd namespace doesn't match the
 - * type passed to setns()'s second param. Since we
 - * pass 0, we know the EINVAL is harmless
 - */
 -if (setns(ns_fd[i], 0)  0 
 -errno != EINVAL) {
 -virReportSystemError(errno, _(failed to set namespace 
 '%s'),
 - virLXCDomainNamespaceTypeToString(i));
 -return -1;
 -}
 -VIR_FORCE_CLOSE(ns_fd[i]);
 -}
 +if (ns_fd 
 +virProcessSetNamespaces(VIR_LXC_DOMAIN_NAMESPACE_LAST, ns_fd)  0)

Coverity wasn't very happy with this one - I got:

(1) Event suspicious_sizeof:Passing argument ns_fd of type int *
and argument VIR_LXC_DOMAIN_NAMESPACE_LAST to function
virProcessSetNamespaces is suspicious because a multiple of sizeof
(int) /*4*/ is expected.

Changing 'arg1' to virProcessSetNamespaces from size_t to unsigned int
cleared the error - whether that's right or not, I'm not sure.  I do
note the only other caller virDomainLxcEnterNamespace passes an
'unsigned int' which is why I tried that first.

John
 +return -1;
  return 0;
  }
  
 

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


Re: [libvirt] Please give me a wiki account

2015-08-28 Thread Daniel P. Berrange
On Thu, Aug 27, 2015 at 06:49:55PM -0700, Ian Kelling wrote:
 I saw a page I'd like to improve a bit. wiki username IanKelling.

I have created this account and replied offlist with password.

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

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


Re: [libvirt] [PATCH] migration: remove direct migration dependency on version1 of driver

2015-08-28 Thread Nikolay Shirokovskiy


On 28.08.2015 08:54, Michal Privoznik wrote:
 On 27.08.2015 12:23, Nikolay Shirokovskiy wrote:
 From: Nikolay Shirokovskiy Nikolay Shirokovskiy nshirokovs...@virtuozzo.com

 Direct migration should work if *perform3 is present but *perform
 is not. This is situation when driver migration is implemented
 after new version of driver function is introduced. We should not
 be forced to support old version too as its parameter space is
 subspace of newer one.

 Signed-off-by: Nikolay Shirokovskiy nshirokovs...@virtuozzo.com
 ---
  src/libvirt-domain.c |3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)

 diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
 index 6ab50ba..c89775b 100644
 --- a/src/libvirt-domain.c
 +++ b/src/libvirt-domain.c
 @@ -3427,7 +3427,8 @@ virDomainMigrateDirect(virDomainPtr domain,
   NULLSTR(xmlin), flags, NULLSTR(dname), 
 NULLSTR(dconnuri),
   NULLSTR(miguri), bandwidth);
  
 -if (!domain-conn-driver-domainMigratePerform) {
 +if (!domain-conn-driver-domainMigratePerform 
 +!domain-conn-driver-domainMigratePerform3) {
  virReportUnsupportedError();
  return -1;
  }

 
 
 Hm.. domainMigratePerform3 will be used iff connection driver has
 VIR_DRV_FEATURE_MIGRATION_V3 feature. But this check will require that
 regardless. What if we check the presence of implementation with respect
 to that?
I see you mean actual driver could be behind remote one and checking
for perform3 always gives true so we need to check for feature instead?
 

 Moreover, can you please send patches rebased to current HEAD?
Sorry, most time i rebase.
 
 Michal
 

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


[libvirt] [PATCH] virVMXParseDisk: Recognize scsi-passthru

2015-08-28 Thread Michal Privoznik
https://bugzilla.redhat.com/show_bug.cgi?id=1172544

So, imagine you have this config:

scsi0:1.present = TRUE
scsi0:1.deviceType = scsi-passthru
scsi0:1.fileName = /vmfs/devices/cdrom/mpx.vmhba32:C0:T0:L0
scsi0:1.allowGuestConnectionControl = FALSE

So far, libvirt does not recognize this pattern and fails. What
if we produce the following XML to it?

disk type='block' device='disk'
  source dev='/vmfs/devices/cdrom/mpx.vmhba32:C0:T0:L0'/
  target dev='sdb' bus='scsi'/
  address type='drive' controller='0' bus='0' target='0' unit='1'/
/disk

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
 src/vmx/vmx.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 36e2891..6d83d81 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2187,6 +2187,17 @@ virVMXParseDisk(virVMXContext *ctx, 
virDomainXMLOptionPtr xmlopt, virConfPtr con
  * function to parse a CDROM device may handle it.
  */
 goto ignore;
+} else if (STREQ_NULLABLE(deviceType, scsi-passthru)) {
+char *tmp;
+
+virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK);
+if (!(tmp = ctx-parseFileName(fileName, ctx-opaque)))
+goto cleanup;
+if (virDomainDiskSetSource(*def, tmp)  0) {
+VIR_FREE(tmp);
+goto cleanup;
+}
+VIR_FREE(tmp);
 } else {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_(Invalid or not yet handled value '%s' 
-- 
2.4.6

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


[libvirt] [PATCH libvirt-java] Require at least Java 8

2015-08-28 Thread Wido den Hollander
Signed-off-by: Wido den Hollander w...@widodh.nl
---
 INSTALL  | 2 +-
 build.properties | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/INSTALL b/INSTALL
index 581512d..2cdd829 100644
--- a/INSTALL
+++ b/INSTALL
@@ -11,7 +11,7 @@ main item you may need to change in this file is the jars.dir
 property. This property should point to a directory which contains 
 the junit.jar and jna.jar files.
 
-You will need a Java Development Kit accepting the version 1.6
+You will need a Java Development Kit accepting the version 1.8
 of the language since the bindings use enums as well as the new 
 for loop syntax
 
diff --git a/build.properties b/build.properties
index bcc7b8c..c7c1a43 100644
--- a/build.properties
+++ b/build.properties
@@ -1,8 +1,8 @@
 version=0.5.1
 release=1
 libvirt.required=0.9.12
-java.required=1.6.0
-java.target=1.6
-java.source=1.6
+java.required=1.8.0
+java.target=1.8
+java.source=1.8
 rpm.topdir=/home/veillard/rpms
 jar.dir=/usr/share/java
-- 
1.9.1

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


[libvirt] (no subject)

2015-08-28 Thread Wido den Hollander

The current code of libvirt-java does not build with Java 7.

This patch updates the build.properties and INSTALL that we 
require Java 8 to build libvirt-java.

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


[libvirt] [sandbox PATCH v4 03/21] Image: Add Hooking Mechanism

2015-08-28 Thread Eren Yagdiran
Any custom source provider can be added to virt-sandbox-image as a source
---
 .gitignore   |  1 +
 bin/Makefile.am  | 16 
 bin/virt-sandbox-image.in|  3 +++
 configure.ac |  2 ++
 virt-sandbox-image/Makefile.am   | 13 +
 virt-sandbox-image/sources/Source.py | 27 +++
 virt-sandbox-image/sources/__init__.py   | 26 ++
 virt-sandbox-image/virt-sandbox-image.py | 15 +--
 8 files changed, 93 insertions(+), 10 deletions(-)
 create mode 100644 bin/virt-sandbox-image.in
 create mode 100644 virt-sandbox-image/Makefile.am
 create mode 100644 virt-sandbox-image/sources/Source.py
 create mode 100644 virt-sandbox-image/sources/__init__.py
 mode change 100644 = 100755 virt-sandbox-image/virt-sandbox-image.py

diff --git a/.gitignore b/.gitignore
index f77ea12..ef5b5aa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,3 +56,4 @@ bin/virt-sandbox
 bin/virt-sandbox-service-util
 build/
 bin/*.1
+bin/virt-sandbox-image
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 416f86f..df4c7dc 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -3,7 +3,11 @@ bin_PROGRAMS = virt-sandbox
 
 libexec_PROGRAMS = virt-sandbox-service-util
 
-bin_SCRIPTS = virt-sandbox-service
+bin_SCRIPTS = virt-sandbox-service \
+  virt-sandbox-image
+
+virt-sandbox-image: virt-sandbox-image.in
+   sed -e 's,[@]pkgpythondir[@],$(pkgpythondir),g'  $ $@
 
 virtsandboxcompdir = $(datarootdir)/bash-completion/completions/
 
@@ -20,8 +24,11 @@ POD_FILES = \
virt-sandbox-service-reload.pod \
virt-sandbox-service-upgrade.pod \
$(NULL)
-EXTRA_DIST = $(bin_SCRIPTS) $(POD_FILES) 
virt-sandbox-service-bash-completion.sh virt-sandbox-service.logrotate
-EXTRA_DIST += virt-sandbox-service-bash-completion.sh
+EXTRA_DIST = virt-sandbox-service \
+ virt-sandbox-image.in \
+ $(POD_FILES) \
+ virt-sandbox-service-bash-completion.sh \
+ virt-sandbox-service.logrotate
 
 man1_MANS = \
virt-sandbox.1 \
@@ -64,7 +71,8 @@ virt-sandbox-service-reload.1: 
virt-sandbox-service-reload.pod Makefile
 virt-sandbox-service-upgrade.1: virt-sandbox-service-upgrade.pod Makefile
$(AM_V_GEN)$(POD2MAN) $ $(srcdir)/$@
 
-CLEANFILES = $(man1_MANS)
+CLEANFILES = $(man1_MANS) \
+ virt-sandbox-image
 
 virt_sandbox_SOURCES = virt-sandbox.c
 virt_sandbox_CFLAGS = \
diff --git a/bin/virt-sandbox-image.in b/bin/virt-sandbox-image.in
new file mode 100644
index 000..732bb38
--- /dev/null
+++ b/bin/virt-sandbox-image.in
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec @pkgpythondir@/virt-sandbox-image.py $@
diff --git a/configure.ac b/configure.ac
index 8f6da04..69b5870 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,11 +124,13 @@ dnl Should be in m4/virt-gettext.m4 but intltoolize is too
 dnl dumb to find it there
 IT_PROG_INTLTOOL([0.35.0])
 
+AM_PATH_PYTHON
 
 AC_OUTPUT(Makefile
   libvirt-sandbox/Makefile
   libvirt-sandbox/tests/Makefile
   bin/Makefile
+  virt-sandbox-image/Makefile
   examples/Makefile
   docs/Makefile
   docs/libvirt-sandbox/Makefile
diff --git a/virt-sandbox-image/Makefile.am b/virt-sandbox-image/Makefile.am
new file mode 100644
index 000..5ab4d2e
--- /dev/null
+++ b/virt-sandbox-image/Makefile.am
@@ -0,0 +1,13 @@
+
+EXTRA_DIST = \
+   virt-sandbox-image.py \
+   sources
+
+install-data-local:
+   $(mkinstalldirs) $(DESTDIR)/$(pkgpythondir)/sources
+   $(INSTALL) -m 0755 $(srcdir)/virt-sandbox-image.py 
$(DESTDIR)$(pkgpythondir)
+   $(INSTALL) -m 0644 $(srcdir)/sources/__init__.py 
$(DESTDIR)$(pkgpythondir)/sources
+   $(INSTALL) -m 0644 $(srcdir)/sources/Source.py 
$(DESTDIR)$(pkgpythondir)/sources
+
+uninstall-local:
+   rm -f $(DESTDIR)$(pkgpythondir)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
new file mode 100644
index 000..508ca80
--- /dev/null
+++ b/virt-sandbox-image/sources/Source.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2015 Universitat Polit??cnica de Catalunya.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  

[libvirt] [sandbox PATCH v4 10/21] Image: Add get_command function to Source

2015-08-28 Thread Eren Yagdiran
Provide a way to know how a template can be started depending on the used source
DockerSource will need to parse the topmost config file in order to find the 
igniter command
---
 virt-sandbox-image/sources/DockerSource.py | 14 ++
 virt-sandbox-image/sources/Source.py   |  4 
 2 files changed, 18 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 760ba6c..3e0362b 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -29,6 +29,15 @@ import os
 import subprocess
 import shutil
 
+class DockerConfParser():
+
+def __init__(self,jsonfile):
+with open(jsonfile) as json_file:
+self.json_data = json.load(json_file)
+def getRunCommand(self):
+cmd = self.json_data['container_config']['Cmd'][2]
+return cmd[cmd.index('') + 1:cmd.rindex('')]
+
 class DockerSource(Source):
 
 www_auth_username = None
@@ -363,5 +372,10 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_command(self,configfile):
+configParser = DockerConfParser(configfile)
+commandToRun = configParser.getRunCommand()
+return commandToRun
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index d66e61e..9daf62d 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -37,3 +37,7 @@ class Source():
 @abstractmethod
 def delete_template(self,**args):
   pass
+
+@abstractmethod
+def get_command(self,**args):
+  pass
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 07/21] Image: Add download function

2015-08-28 Thread Eren Yagdiran
Refactor download function from virt-sandbox-image to use
the newly introduced Source abstract class. The docker-specific
download code is moved to a new DockerSource class.
---
 virt-sandbox-image/Makefile.am |   1 +
 virt-sandbox-image/sources/DockerSource.py | 214 +
 virt-sandbox-image/sources/Source.py   |   4 +
 virt-sandbox-image/virt-sandbox-image.py   | 204 +--
 4 files changed, 251 insertions(+), 172 deletions(-)
 create mode 100644 virt-sandbox-image/sources/DockerSource.py

diff --git a/virt-sandbox-image/Makefile.am b/virt-sandbox-image/Makefile.am
index 5ab4d2e..8188c80 100644
--- a/virt-sandbox-image/Makefile.am
+++ b/virt-sandbox-image/Makefile.am
@@ -8,6 +8,7 @@ install-data-local:
$(INSTALL) -m 0755 $(srcdir)/virt-sandbox-image.py 
$(DESTDIR)$(pkgpythondir)
$(INSTALL) -m 0644 $(srcdir)/sources/__init__.py 
$(DESTDIR)$(pkgpythondir)/sources
$(INSTALL) -m 0644 $(srcdir)/sources/Source.py 
$(DESTDIR)$(pkgpythondir)/sources
+   $(INSTALL) -m 0644 $(srcdir)/sources/DockerSource.py 
$(DESTDIR)$(pkgpythondir)/sources
 
 uninstall-local:
rm -f $(DESTDIR)$(pkgpythondir)
diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
new file mode 100644
index 000..f3cf5f3
--- /dev/null
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -0,0 +1,214 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2015 Universitat Polit??cnica de Catalunya.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+#
+# Author: Eren Yagdiran erenyagdi...@gmail.com
+#
+
+from Source import Source
+import urllib2
+import sys
+import json
+import traceback
+import os
+import subprocess
+import shutil
+
+class DockerSource(Source):
+
+www_auth_username = None
+www_auth_password = None
+
+def __init__(self):
+self.default_index_server = index.docker.io
+
+def _check_cert_validate(self):
+major = sys.version_info.major
+SSL_WARNING = SSL certificates couldn't be validated by default. You 
need to have 2.7.9/3.4.3 or higher
+SSL_WARNING +=\nSee https://bugs.python.org/issue22417\n;
+py2_7_9_hexversion = 34015728
+py3_4_3_hexversion = 50594800
+if  (major == 2 and sys.hexversion  py2_7_9_hexversion) or (major == 
3 and sys.hexversion  py3_4_3_hexversion):
+sys.stderr.write(SSL_WARNING)
+
+def download_template(self,**args):
+name = args['name']
+registry = args['registry'] if args['registry'] is not None else 
self.default_index_server
+username = args['username']
+password = args['password']
+templatedir = args['templatedir']
+self._download_template(name,registry,username,password,templatedir)
+
+def _download_template(self,name, server,username,password,destdir):
+
+if username is not None:
+self.www_auth_username = username
+self.www_auth_password = password
+
+self._check_cert_validate()
+tag = latest
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+try:
+(data, res) = self._get_json(server, /v1/repositories/ + name + 
/images,
+   {X-Docker-Token: true})
+except urllib2.HTTPError, e:
+raise ValueError([Image '%s' does not exist % name])
+
+registryserver = res.info().getheader('X-Docker-Endpoints')
+token = res.info().getheader('X-Docker-Token')
+checksums = {}
+for layer in data:
+pass
+(data, res) = self._get_json(registryserver, /v1/repositories/ + 
name + /tags,
+   { Authorization: Token  + token })
+
+cookie = res.info().getheader('Set-Cookie')
+
+if not tag in data:
+raise ValueError([Tag '%s' does not exist for image '%s' % (tag, 
name)])
+imagetagid = data[tag]
+
+(data, res) = self._get_json(registryserver, /v1/images/ + 
imagetagid + /ancestry,
+   { Authorization: Token +token })
+
+if data[0] != imagetagid:
+raise ValueError([Expected first layer id '%s' to match image id 

[libvirt] [sandbox PATCH v4 02/21] Fix virt-sandbox-image

2015-08-28 Thread Eren Yagdiran
Authentication fix for Docker REST API.
---
 virt-sandbox-image/virt-sandbox-image.py | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 4f5443b..a9cb0ff 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -1,8 +1,10 @@
 #!/usr/bin/python -Es
 #
 # Authors: Daniel P. Berrange berra...@redhat.com
+#  Eren Yagdiran erenyagdi...@gmail.com
 #
 # Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2015 Universitat Polit??cnica de Catalunya.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -166,7 +168,7 @@ def download_template(name, server, destdir):
 # or more parents, in a linear stack. Here we are getting the list
 # of layers for the image with the tag we used.
 (data, res) = get_json(registryserver, /v1/images/ + imagetagid + 
/ancestry,
-   { Cookie: cookie })
+   { Authorization: Token  + token })
 
 if data[0] != imagetagid:
 raise ValueError([Expected first layer id '%s' to match image id 
'%s',
@@ -188,9 +190,9 @@ def download_template(name, server, destdir):
 if not os.path.exists(jsonfile) or not os.path.exists(datafile):
 # The '/json' URL gives us some metadata about the layer
 res = save_data(registryserver, /v1/images/ + layerid + 
/json,
-{ Cookie: cookie }, jsonfile)
+{ Authorization: Token  + token }, 
jsonfile)
 createdFiles.append(jsonfile)
-layersize = int(res.info().getheader(x-docker-size))
+layersize = int(res.info().getheader(Content-Length))
 
 datacsum = None
 if layerid in checksums:
@@ -199,7 +201,7 @@ def download_template(name, server, destdir):
 # and the '/layer' URL is the actual payload, provided
 # as a tar.gz archive
 save_data(registryserver, /v1/images/ + layerid + /layer,
-  { Cookie: cookie }, datafile, datacsum, layersize)
+  { Authorization: Token  + token }, datafile, 
datacsum, layersize)
 createdFiles.append(datafile)
 
 # Strangely the 'json' data for a layer doesn't include
-- 
2.1.0

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

[libvirt] [sandbox PATCH v4 12/21] Image: Add check_connect function

2015-08-28 Thread Eren Yagdiran
Check if user-specified connect argument is valid
---
 virt-sandbox-image/virt-sandbox-image.py | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index d6b682f..c46abd4 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -122,6 +122,12 @@ def create(args):
 except Exception,e:
 print Create Error %s % str(e)
 
+def check_connect(connectstr):
+supportedDrivers = ['lxc:///','qemu:///session','qemu:///system']
+if not connectstr in supportedDrivers:
+raise ValueError(%s is not supported by Virt-sandbox %connectstr)
+return True
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 16/21] Image: Add Volume Support

2015-08-28 Thread Eren Yagdiran
Volumes let user to map host-paths into sandbox. Docker containers
need volumes for data persistence.
---
 virt-sandbox-image/sources/DockerSource.py | 12 
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   | 22 ++
 3 files changed, 38 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 87fbcf3..1022107 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -28,6 +28,7 @@ import traceback
 import os
 import subprocess
 import shutil
+import collections
 
 class DockerConfParser():
 
@@ -37,6 +38,13 @@ class DockerConfParser():
 def getRunCommand(self):
 cmd = self.json_data['container_config']['Cmd'][2]
 return cmd[cmd.index('') + 1:cmd.rindex('')]
+def getVolumes(self):
+volumes = self.json_data['container_config']['Volumes']
+volumelist = []
+if isinstance(volumes,collections.Iterable):
+  for key,value in volumes.iteritems():
+volumelist.append(key)
+return volumelist
 
 class DockerSource(Source):
 
@@ -393,5 +401,9 @@ class DockerSource(Source):
 commandToRun = configParser.getRunCommand()
 return commandToRun
 
+def get_volume(self,configfile):
+configParser = DockerConfParser(configfile)
+return configParser.getVolumes()
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 9a3da59..8cc508e 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -45,3 +45,7 @@ class Source():
 @abstractmethod
 def get_disk(self,**args):
   pass
+
+@abstractmethod
+def get_volume(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 058738a..79f8d8c 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -132,6 +132,7 @@ def check_connect(connectstr):
 
 def run(args):
 try:
+global storage_dir
 if args.connect is not None:
 check_connect(args.connect)
 source = dynamic_source_loader(args.source)
@@ -150,6 +151,25 @@ def run(args):
 if networkArgs is not None:
 params.append('-N')
 params.append(networkArgs)
+allVolumes = source.get_volume(configfile)
+volumeArgs = args.volume
+if volumeArgs is not None:
+allVolumes = allVolumes + volumeArgs
+for volume in allVolumes:
+volumeSplit = volume.split(:)
+volumelen = len(volumeSplit)
+if volumelen == 2:
+hostPath = volumeSplit[0]
+guestPath = volumeSplit[1]
+elif volumelen == 1:
+guestPath = volumeSplit[0]
+hostPath = storage_dir + guestPath
+if not os.path.exists(hostPath):
+os.makedirs(hostPath)
+else:
+pass
+params.append(--mount)
+params.append(host-bind:%s=%s %(guestPath,hostPath))
 params.append('--')
 params.append(commandToRun)
 cmd = cmd + params
@@ -234,6 +254,8 @@ def gen_run_args(subparser):
 help=_(Igniter command for image))
 parser.add_argument(-n,--network,
 help=_(Network params for running template))
+parser.add_argument(-v,--volume,action=append,
+help=_(Volume params for running template))
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 04/21] Image: virt-sandbox-image default dir constants

2015-08-28 Thread Eren Yagdiran
Conflicts:
virt-sandbox-image/virt-sandbox-image.py
---
 virt-sandbox-image/virt-sandbox-image.py | 8 
 1 file changed, 8 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index fa9e1c8..55aea6a 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -32,6 +32,14 @@ import sys
 import urllib2
 import subprocess
 
+default_privileged_template_dir = /var/lib/libvirt/templates
+default_home_dir = os.environ['HOME']
+default_unprivileged_template_dir = default_home_dir + 
/.local/share/libvirt/templates
+default_privileged_storage_dir = default_privileged_template_dir + /storage
+default_unprivileged_storage_dir = default_unprivileged_template_dir + 
/storage
+debug = False
+verbose = False
+
 import importlib
 def dynamic_source_loader(name):
 name = name[0].upper() + name[1:]
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 05/21] Image: Discard caching bytecode

2015-08-28 Thread Eren Yagdiran
---
 virt-sandbox-image/virt-sandbox-image.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 55aea6a..9e98bf2 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -40,6 +40,8 @@ default_unprivileged_storage_dir = 
default_unprivileged_template_dir + /storage
 debug = False
 verbose = False
 
+sys.dont_write_byte_code = True
+
 import importlib
 def dynamic_source_loader(name):
 name = name[0].upper() + name[1:]
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 15/21] Image: Add network support

2015-08-28 Thread Eren Yagdiran
Virt-sandbox-image will pass exact network arguments to virt-sandbox
---
 virt-sandbox-image/virt-sandbox-image.py | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index c182874..058738a 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -145,9 +145,13 @@ def run(args):
 if args.connect is not None:
 cmd.append(-c)
 cmd.append(args.connect)
-params = ['-m','host-image:/=%s,format=%s' %(diskfile,format),
-   '--',
-   commandToRun]
+params = ['-m','host-image:/=%s,format=%s' %(diskfile,format)]
+networkArgs = args.network
+if networkArgs is not None:
+params.append('-N')
+params.append(networkArgs)
+params.append('--')
+params.append(commandToRun)
 cmd = cmd + params
 subprocess.call(cmd)
 subprocess.call([rm, -rf, diskfile])
@@ -228,6 +232,8 @@ def gen_run_args(subparser):
 help=_(Template directory for saving templates))
 parser.add_argument(-i,--igniter,
 help=_(Igniter command for image))
+parser.add_argument(-n,--network,
+help=_(Network params for running template))
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 06/21] Image: Add check_writable and runtime resolver

2015-08-28 Thread Eren Yagdiran
These helper functions are for selecting right directories according
to running user privileges
---
 virt-sandbox-image/virt-sandbox-image.py | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 9e98bf2..5917dd6 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -32,6 +32,8 @@ import sys
 import urllib2
 import subprocess
 
+template_dir = None
+storage_dir = None
 default_privileged_template_dir = /var/lib/libvirt/templates
 default_home_dir = os.environ['HOME']
 default_unprivileged_template_dir = default_home_dir + 
/.local/share/libvirt/templates
@@ -40,6 +42,29 @@ default_unprivileged_storage_dir = 
default_unprivileged_template_dir + /storage
 debug = False
 verbose = False
 
+def check_dir_writable(path):
+if not os.access(path,os.W_OK):
+return False
+return True
+
+def runtime_dir_resolver():
+global default_privileged_template_dir
+global default_privileged_storage_dir
+global default_unprivileged_template_dir
+global default_unprivileged_storage_dir
+global template_dir
+global storage_dir
+if(check_dir_writable(default_privileged_template_dir)):
+template_dir = default_privileged_template_dir
+storage_dir = default_privileged_storage_dir
+return
+template_dir = default_unprivileged_template_dir
+storage_dir = default_unprivileged_storage_dir
+if not os.path.exists(template_dir):
+os.makedirs(template_dir)
+if not os.path.exists(storage_dir):
+os.makedirs(storage_dir)
+
 sys.dont_write_byte_code = True
 
 import importlib
@@ -380,8 +405,8 @@ def gen_create_args(subparser):
 parser.set_defaults(func=create)
 
 if __name__ == '__main__':
+runtime_dir_resolver()
 parser = argparse.ArgumentParser(description='Sandbox Container Image 
Tool')
-
 subparser = parser.add_subparsers(help=_(commands))
 gen_download_args(subparser)
 gen_delete_args(subparser)
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 11/21] Image: Add run args

2015-08-28 Thread Eren Yagdiran
Commandline parameters for running a template
---
 virt-sandbox-image/virt-sandbox-image.py | 13 +
 1 file changed, 13 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 1da5150..d6b682f 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -178,6 +178,18 @@ def gen_create_args(subparser):
 help=_(format format for image))
 parser.set_defaults(func=create)
 
+def gen_run_args(subparser):
+parser = subparser.add_parser(run,
+  help=_(Run a already built image))
+requires_name(parser)
+requires_source(parser)
+requires_connect(parser)
+parser.add_argument(-t,--template-dir,
+help=_(Template directory for saving templates))
+parser.add_argument(-i,--igniter,
+help=_(Igniter command for image))
+parser.set_defaults(func=run)
+
 if __name__ == '__main__':
 runtime_dir_resolver()
 parser = argparse.ArgumentParser(description='Sandbox Container Image 
Tool')
@@ -185,6 +197,7 @@ if __name__ == '__main__':
 gen_download_args(subparser)
 gen_delete_args(subparser)
 gen_create_args(subparser)
+gen_run_args(subparser)
 
 try:
 args = parser.parse_args()
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 18/21] Add config for environment variables

2015-08-28 Thread Eren Yagdiran
Add the config gobject to store custom environment variables.
This will allow creating custom environment variables on a sandbox
with a parameter formatted like --env key1=val1

Add testcase for custom environment variables

make check now includes testcase for environment variables
---
 libvirt-sandbox/libvirt-sandbox-config.c | 171 ++-
 libvirt-sandbox/libvirt-sandbox-config.h |  13 +++
 libvirt-sandbox/libvirt-sandbox.sym  |   6 ++
 libvirt-sandbox/tests/test-config.c  |  10 ++
 4 files changed, 199 insertions(+), 1 deletion(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-config.c 
b/libvirt-sandbox/libvirt-sandbox-config.c
index 2506072..780d174 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -64,6 +64,7 @@ struct _GVirSandboxConfigPrivate
 GList *networks;
 GList *mounts;
 GList *disks;
+GHashTable* envs;
 
 gchar *secLabel;
 gboolean secDynamic;
@@ -276,6 +277,8 @@ static void gvir_sandbox_config_finalize(GObject *object)
 g_list_foreach(priv-networks, (GFunc)g_object_unref, NULL);
 g_list_free(priv-networks);
 
+g_hash_table_destroy(priv-envs);
+
 g_list_foreach(priv-disks, (GFunc)g_object_unref, NULL);
 g_list_free(priv-disks);
 
@@ -483,6 +486,7 @@ static void gvir_sandbox_config_init(GVirSandboxConfig 
*config)
 priv-arch = g_strdup(uts.machine);
 priv-secDynamic = TRUE;
 
+priv-envs = g_hash_table_new(g_str_hash, g_str_equal);
 priv-uid = geteuid();
 priv-gid = getegid();
 priv-username = g_strdup(g_get_user_name());
@@ -1144,6 +1148,102 @@ gboolean 
gvir_sandbox_config_has_networks(GVirSandboxConfig *config)
 return priv-networks ? TRUE : FALSE;
 }
 
+/**
+ * gvir_sandbox_config_add_env:
+ * @config: (transfer none): the sandbox config
+ * @key: (transfer none): the key for environment variable
+ * @value: (transfer none): the value for environment variable
+ *
+ * Adds a new environment variable to the sandbox
+ *
+ */
+void gvir_sandbox_config_add_env(GVirSandboxConfig *config,
+ gchar *k,
+ gchar *v)
+{
+gchar * key = g_strdup(k);
+gchar * value = g_strdup(v);
+GVirSandboxConfigPrivate *priv = config-priv;
+g_hash_table_insert(priv-envs,key,value);
+}
+
+/**
+ * gvir_sandbox_config_get_envs:
+ * @config: (transfer none): the sandbox config
+ *
+ * Retrieves the hashtable of custom environment variables in the sandbox
+ *
+ * Returns: (transfer full) (element-type gchar gchar): the hashtable of 
environment variables
+ */
+GHashTable *gvir_sandbox_config_get_envs(GVirSandboxConfig *config)
+{
+GVirSandboxConfigPrivate *priv = config-priv;
+return priv-envs;
+}
+
+/**
+ * gvir_sandbox_config_add_env_strv:
+ * @config: (transfer none): the sandbox config
+ * @envs: (transfer none)(array zero-terminated=1): the list of environment 
variables
+ *
+ * Parses @envs whose elements are in the format KEY=VALUE
+ *
+ * --env KEY=VALUE
+ */
+gboolean gvir_sandbox_config_add_env_strv(GVirSandboxConfig *config,
+  gchar **envs,
+  GError **error)
+{
+gsize i = 0;
+while (envs  envs[i]) {
+if (!gvir_sandbox_config_add_env_opts(config,
+   envs[i],
+   error))
+return FALSE;
+i++;
+}
+return TRUE;
+}
+
+/**
+ * gvir_sandbox_config_add_env_opts:
+ * @config: (transfer none): the sandbox config
+ * @env: (transfer none): the env config
+ *
+ * Parses @env in the format KEY=VALUE
+ * creating #GVirSandboxConfigEnv instances for each element. For
+ * example
+ *
+ * --env KEY=VALUE
+ */
+
+gboolean gvir_sandbox_config_add_env_opts(GVirSandboxConfig *config,
+   const char *opt,
+   GError **error)
+{
+gchar *tmp = NULL;
+gchar *key = NULL;
+gchar *value = NULL;
+
+if (!(tmp = g_strdup(opt)))
+return FALSE;
+
+key  = strchr(tmp, '=');
+
+if (!key) {
+g_set_error(error, GVIR_SANDBOX_CONFIG_ERROR, 0,
+_(Wrong environment format on %s), opt);
+return FALSE;
+}
+
+*key = '\0';
+value = key + 1;
+
+gvir_sandbox_config_add_env(config, tmp, value);
+
+g_free(tmp);
+return TRUE;
+}
 
 /**
  * gvir_sandbox_config_add_disk:
@@ -1163,7 +1263,6 @@ void gvir_sandbox_config_add_disk(GVirSandboxConfig 
*config,
 priv-disks = g_list_append(priv-disks, dsk);
 }
 
-
 /**
  * gvir_sandbox_config_get_disks:
  * @config: (transfer none): the sandbox config
@@ -1172,6 +1271,7 @@ void gvir_sandbox_config_add_disk(GVirSandboxConfig 
*config,
  *
  * Returns: (transfer full) (element-type GVirSandboxConfigMount): the list of 
disks
  */
+
 GList *gvir_sandbox_config_get_disks(GVirSandboxConfig *config)
 {
  

[libvirt] [sandbox PATCH v4 21/21] Image: Add custom environment support

2015-08-28 Thread Eren Yagdiran
Any custom key=value pair can be used as a custom environment variable
in virt-sandbox-image.
e.g virt-sandbox-image run ubuntu /var/lib/libvirt/templates -c lxc:/// -i 
/bin/bash -e key1=val1
---
 virt-sandbox-image/sources/DockerSource.py | 10 ++
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   | 17 +
 3 files changed, 31 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 1022107..122e595 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -45,6 +45,12 @@ class DockerConfParser():
   for key,value in volumes.iteritems():
 volumelist.append(key)
 return volumelist
+def getEnvs(self):
+lst = self.json_data['container_config']['Env']
+if lst is not None and isinstance(lst,list):
+  return lst
+else:
+  return []
 
 class DockerSource(Source):
 
@@ -405,5 +411,9 @@ class DockerSource(Source):
 configParser = DockerConfParser(configfile)
 return configParser.getVolumes()
 
+def get_env(self,configfile):
+configParser = DockerConfParser(configfile)
+return configParser.getEnvs()
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 8cc508e..c467ce2 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -49,3 +49,7 @@ class Source():
 @abstractmethod
 def get_volume(self,**args):
   pass
+
+@abstractmethod
+def get_env(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 79f8d8c..285e99c 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -170,6 +170,20 @@ def run(args):
 pass
 params.append(--mount)
 params.append(host-bind:%s=%s %(guestPath,hostPath))
+
+allEnvs = source.get_env(configfile)
+envArgs = args.env
+if envArgs is not None:
+allEnvs = allEnvs + envArgs
+for env in allEnvs:
+envsplit = env.split(=)
+envlen = len(envsplit)
+if envlen == 2:
+params.append(--env)
+params.append(env)
+else:
+pass
+
 params.append('--')
 params.append(commandToRun)
 cmd = cmd + params
@@ -256,6 +270,9 @@ def gen_run_args(subparser):
 help=_(Network params for running template))
 parser.add_argument(-v,--volume,action=append,
 help=_(Volume params for running template))
+parser.add_argument(-e,--env,action=append,
+help=_(Environment params for running template))
+
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 09/21] Image: Add delete function

2015-08-28 Thread Eren Yagdiran
Refactoring delete function from virt-sandbox-image to DockerSource. Delete 
function
can delete templates by name.
---
 virt-sandbox-image/sources/DockerSource.py | 53 +++
 virt-sandbox-image/sources/Source.py   |  4 +++
 virt-sandbox-image/virt-sandbox-image.py   | 58 --
 3 files changed, 64 insertions(+), 51 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 09eea85..760ba6c 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -310,5 +310,58 @@ class DockerSource(Source):
 cmd = cmd + params
 subprocess.call(cmd)
 
+def delete_template(self,**args):
+imageusage = {}
+imageparent = {}
+imagenames = {}
+name = args['name']
+destdir = args['templatedir']
+destdir = destdir if destdir is not None else default_template_dir
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+
+parent = template.get(parent,None)
+if parent:
+if parent not in imageusage:
+imageusage[parent] = []
+imageusage[parent].append(imagetagid)
+imageparent[imagetagid] = parent
+
+
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+
+imagetagid = imagenames[name]
+while imagetagid != None:
+debug(Remove %s\n % imagetagid)
+parent = imageparent.get(imagetagid,None)
+
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+   os.remove(indexfile)
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+os.remove(jsonfile)
+datafile = destdir + / + imagetagid + /template.tar.gz
+if os.path.exists(datafile):
+os.remove(datafile)
+imagedir = destdir + / + imagetagid
+shutil.rmtree(imagedir)
+
+if parent:
+if len(imageusage[parent]) != 1:
+debug(Parent %s is shared\n % parent)
+parent = None
+imagetagid = parent
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 6ac08dc..d66e61e 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -33,3 +33,7 @@ class Source():
 @abstractmethod
 def create_template(self,**args):
   pass
+
+@abstractmethod
+def delete_template(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 745401c..1da5150 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -94,55 +94,6 @@ def debug(msg):
 def info(msg):
 sys.stdout.write(msg)
 
-def delete_template(name, destdir):
-imageusage = {}
-imageparent = {}
-imagenames = {}
-imagedirs = os.listdir(destdir)
-for imagetagid in imagedirs:
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-with open(indexfile, r) as f:
-index = json.load(f)
-imagenames[index[name]] = imagetagid
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-with open(jsonfile, r) as f:
-template = json.load(f)
-
-parent = template.get(parent, None)
-if parent:
-if parent not in imageusage:
-imageusage[parent] = []
-imageusage[parent].append(imagetagid)
-imageparent[imagetagid] = parent
-
-if not name in imagenames:
-raise ValueError([Image %s does not exist locally % name])
-
-imagetagid = imagenames[name]
-while imagetagid != None:
-debug(Remove %s\n %  imagetagid)
-parent = imageparent.get(imagetagid, None)
-
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-os.remove(indexfile)
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-os.remove(jsonfile)
-datafile = destdir + / + imagetagid + 

[libvirt] [sandbox PATCH v4 13/21] Image: Add get_disk function to Source

2015-08-28 Thread Eren Yagdiran
Provide a way to know which disk image to use for the sandbox depending on the 
used source
DockerSource will need to locate the topmost disk image among all the layers 
images
---
 virt-sandbox-image/sources/DockerSource.py | 16 
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   |  9 +
 3 files changed, 29 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 3e0362b..87fbcf3 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -372,6 +372,22 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_disk(self,**args):
+name = args['name']
+destdir = args['templatedir']
+sandboxid = args['id']
+imageList = self._get_image_list(name,destdir)
+toplayer = imageList[0]
+diskfile = destdir + / + toplayer + /template.qcow2
+configfile = destdir + / + toplayer + /template.json
+tempfile = destdir + / + toplayer + / + sandboxid + .qcow2
+cmd = [qemu-img,create,-q,-f,qcow2]
+cmd.append(-o)
+cmd.append(backing_fmt=qcow2,backing_file=%s % diskfile)
+cmd.append(tempfile)
+subprocess.call(cmd)
+return (tempfile,configfile)
+
 def get_command(self,configfile):
 configParser = DockerConfParser(configfile)
 commandToRun = configParser.getRunCommand()
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 9daf62d..9a3da59 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -41,3 +41,7 @@ class Source():
 @abstractmethod
 def get_command(self,**args):
   pass
+
+@abstractmethod
+def get_disk(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index c46abd4..a73619c 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -31,6 +31,8 @@ import shutil
 import sys
 import urllib2
 import subprocess
+import random
+import string
 
 template_dir = None
 storage_dir = None
@@ -128,6 +130,12 @@ def check_connect(connectstr):
 raise ValueError(%s is not supported by Virt-sandbox %connectstr)
 return True
 
+def requires_id(parser):
+randomid = ''.join(random.choice(string.lowercase) for i in range(10))
+parser.add_argument(-d,--id,
+default=randomid,
+help=_(id of the running sandbox))
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
@@ -187,6 +195,7 @@ def gen_create_args(subparser):
 def gen_run_args(subparser):
 parser = subparser.add_parser(run,
   help=_(Run a already built image))
+requires_id(parser)
 requires_name(parser)
 requires_source(parser)
 requires_connect(parser)
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 14/21] Image: Add run function

2015-08-28 Thread Eren Yagdiran
Run an already-built template
If there is no execution command specified by user, source.get_command will
find the command to invoke
---
 virt-sandbox-image/virt-sandbox-image.py | 25 +
 1 file changed, 25 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index a73619c..c182874 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -130,6 +130,31 @@ def check_connect(connectstr):
 raise ValueError(%s is not supported by Virt-sandbox %connectstr)
 return True
 
+def run(args):
+try:
+if args.connect is not None:
+check_connect(args.connect)
+source = dynamic_source_loader(args.source)
+diskfile,configfile = 
source.get_disk(name=args.name,templatedir=args.template_dir,id=args.id)
+
+format = qcow2
+commandToRun = args.igniter
+if commandToRun is None:
+commandToRun = source.get_command(configfile)
+cmd = ['virt-sandbox']
+if args.connect is not None:
+cmd.append(-c)
+cmd.append(args.connect)
+params = ['-m','host-image:/=%s,format=%s' %(diskfile,format),
+   '--',
+   commandToRun]
+cmd = cmd + params
+subprocess.call(cmd)
+subprocess.call([rm, -rf, diskfile])
+
+except Exception,e:
+print Run Error %s % str(e)
+
 def requires_id(parser):
 randomid = ''.join(random.choice(string.lowercase) for i in range(10))
 parser.add_argument(-d,--id,
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 08/21] Image: Refactor create function

2015-08-28 Thread Eren Yagdiran
Move the docker-related code to the DockerSource and use
the Source mechanism
---
 virt-sandbox-image/sources/DockerSource.py | 100 +
 virt-sandbox-image/sources/Source.py   |   4 ++
 virt-sandbox-image/virt-sandbox-image.py   |  76 +-
 3 files changed, 121 insertions(+), 59 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index f3cf5f3..09eea85 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -210,5 +210,105 @@ class DockerSource(Source):
 debug(FAIL %s\n % str(e))
 raise
 
+def create_template(self,**args):
+name = args['name']
+connect = args['connect']
+templatedir = args['templatedir']
+format = args['format']
+format = format if format is not None else self.default_disk_format
+
+self._create_template(name,
+   connect,
+   templatedir,
+   format)
+
+def _create_template(self,name,connect,templatedir,format):
+self._check_disk_format(format)
+imagelist = self._get_image_list(name,templatedir)
+imagelist.reverse()
+
+parentImage = None
+for imagetagid in imagelist:
+templateImage = templatedir + / + imagetagid + /template. + 
format
+cmd = [qemu-img,create,-f,qcow2]
+if parentImage is not None:
+cmd.append(-o)
+cmd.append(backing_fmt=qcow2,backing_file=%s % parentImage)
+cmd.append(templateImage)
+if parentImage is None:
+cmd.append(10G)
+subprocess.call(cmd)
+
+if parentImage is None:
+self._format_disk(templateImage,format,connect)
+
+self._extract_tarballs(templatedir + / + imagetagid + 
/template.,format,connect)
+parentImage = templateImage
+
+
+def _check_disk_format(self,format):
+supportedFormats = ['qcow2']
+if not format in supportedFormats:
+raise ValueError([Unsupported image format %s % format])
+
+def _get_image_list(self,name,destdir):
+imageparent = {}
+imagenames = {}
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+parent = template.get(parent,None)
+if parent:
+imageparent[imagetagid] = parent
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+imagetagid = imagenames[name]
+imagelist = []
+while imagetagid != None:
+imagelist.append(imagetagid)
+parent = imageparent.get(imagetagid,None)
+imagetagid = parent
+return imagelist
+
+def _format_disk(self,disk,format,connect):
+cmd = ['virt-sandbox']
+if connect is not None:
+cmd.append(-c)
+cmd.append(connect)
+cmd.append(-p)
+params = ['--disk=file:disk_image=%s,format=%s' %(disk,format),
+  '/sbin/mkfs.ext3',
+  '/dev/disk/by-tag/disk_image']
+cmd = cmd + params
+subprocess.call(cmd)
+
+def _extract_tarballs(self,directory,format,connect):
+tempdir = /mnt
+tarfile = directory + tar.gz
+diskfile = directory + qcow2
+cmd = ['virt-sandbox']
+if connect is not None:
+cmd.append(-c)
+cmd.append(connect)
+cmd.append(-p)
+params = ['-m',
+  'host-image:/mnt=%s,format=%s' %(diskfile,format),
+  '--',
+  '/bin/tar',
+  'zxf',
+  '%s' %tarfile,
+  '-C',
+  '/mnt']
+cmd = cmd + params
+subprocess.call(cmd)
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 8751689..6ac08dc 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -29,3 +29,7 @@ class Source():
 @abstractmethod
 def download_template(self,**args):
 pass
+
+@abstractmethod
+def create_template(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 4f371d7..745401c 100755
--- 

[libvirt] [sandbox PATCH v4 01/21] Add virt-sandbox-image

2015-08-28 Thread Eren Yagdiran
From: Daniel P Berrange berra...@redhat.com

virt-sandbox-image.py is a python script that lets you download Docker
images easily. It is a proof of concept code and consumes Docker Rest API.
---
 po/POTFILES.in   |   1 +
 virt-sandbox-image/virt-sandbox-image.py | 394 +++
 2 files changed, 395 insertions(+)
 create mode 100644 virt-sandbox-image/virt-sandbox-image.py

diff --git a/po/POTFILES.in b/po/POTFILES.in
index afcb050..7204112 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,3 +11,4 @@ libvirt-sandbox/libvirt-sandbox-context-interactive.c
 libvirt-sandbox/libvirt-sandbox-init-common.c
 libvirt-sandbox/libvirt-sandbox-rpcpacket.c
 libvirt-sandbox/libvirt-sandbox-util.c
+virt-sandbox-image/virt-sandbox-image.py
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
new file mode 100644
index 000..4f5443b
--- /dev/null
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -0,0 +1,394 @@
+#!/usr/bin/python -Es
+#
+# Authors: Daniel P. Berrange berra...@redhat.com
+#
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+import argparse
+import gettext
+import hashlib
+import json
+import os
+import os.path
+import shutil
+import sys
+import urllib2
+import subprocess
+
+default_index_server = index.docker.io
+default_template_dir = /var/lib/libvirt/templates
+
+debug = True
+verbose = True
+
+gettext.bindtextdomain(libvirt-sandbox, /usr/share/locale)
+gettext.textdomain(libvirt-sandbox)
+try:
+gettext.install(libvirt-sandbox,
+localedir=/usr/share/locale,
+unicode=False,
+codeset = 'utf-8')
+except IOError:
+import __builtin__
+__builtin__.__dict__['_'] = unicode
+
+
+def debug(msg):
+sys.stderr.write(msg)
+
+def info(msg):
+sys.stdout.write(msg)
+
+def get_url(server, path, headers):
+url = https://; + server + path
+debug(  Fetching %s... % url)
+req = urllib2.Request(url=url)
+
+if json:
+req.add_header(Accept, application/json)
+
+for h in headers.keys():
+req.add_header(h, headers[h])
+
+return urllib2.urlopen(req)
+
+def get_json(server, path, headers):
+try:
+res = get_url(server, path, headers)
+data = json.loads(res.read())
+debug(OK\n)
+return (data, res)
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+def save_data(server, path, headers, dest, checksum=None, datalen=None):
+try:
+res = get_url(server, path, headers)
+
+csum = None
+if checksum is not None:
+csum = hashlib.sha256()
+
+pattern = [., o, O, o]
+patternIndex = 0
+donelen = 0
+
+with open(dest, w) as f:
+while 1:
+buf = res.read(1024*64)
+if not buf:
+break
+if csum is not None:
+csum.update(buf)
+f.write(buf)
+
+if datalen is not None:
+donelen = donelen + len(buf)
+debug(\x1b[s%s (%5d Kb of %5d Kb)\x1b8 % (
+pattern[patternIndex], (donelen/1024), (datalen/1024)
+))
+patternIndex = (patternIndex + 1) % 4
+
+debug(\x1b[K)
+if csum is not None:
+csumstr = sha256: + csum.hexdigest()
+if csumstr != checksum:
+debug(FAIL checksum '%s' does not match '%s' % (csumstr, 
checksum))
+os.remove(dest)
+raise IOError(Checksum '%s' for data does not match '%s' % 
(csumstr, checksum))
+debug(OK\n)
+return res
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+
+def download_template(name, server, destdir):
+tag = latest
+
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+
+# First we must ask the index server about the image name. THe
+# index server will return an auth token we can use when talking
+# to the registry server. We need this token even when anonymous
+try:
+(data, res) = get_json(server, /v1/repositories/ + name + /images,
+  

[libvirt] [sandbox PATCH v4 19/21] Add environment parameter to virt-sandbox

2015-08-28 Thread Eren Yagdiran
Allow users to add custom environment variables to their sandbox.
---
 bin/virt-sandbox.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 195515f..e90b698 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -64,6 +64,7 @@ int main(int argc, char **argv) {
 GError *error = NULL;
 gchar *name = NULL;
 gchar **disks = NULL;
+gchar **envs = NULL;
 gchar **mounts = NULL;
 gchar **includes = NULL;
 gchar *includefile = NULL;
@@ -95,6 +96,8 @@ int main(int argc, char **argv) {
   N_(root directory of the sandbox), DIR },
 { disk, ' ', 0, G_OPTION_ARG_STRING_ARRAY, disks,
   N_(add a disk in the guest), TYPE:TAGNAME=SOURCE,format=FORMAT },
+{ env, 'e', 0, G_OPTION_ARG_STRING_ARRAY, envs,
+  N_(add a environment variable for the sandbox), KEY=VALUE },
 { mount, 'm', 0, G_OPTION_ARG_STRING_ARRAY, mounts,
   N_(mount a filesystem in the guest), TYPE:TARGET=SOURCE },
 { include, 'i', 0, G_OPTION_ARG_STRING_ARRAY, includes,
@@ -185,6 +188,13 @@ int main(int argc, char **argv) {
 gvir_sandbox_config_set_username(cfg, root);
 }
 
+if (envs 
+!gvir_sandbox_config_add_env_strv(cfg, envs, error)) {
+g_printerr(_(Unable to parse custom environment variables: %s\n),
+   error  error-message ? error-message : _(Unknown 
failure));
+goto cleanup;
+}
+
 if (disks 
 !gvir_sandbox_config_add_disk_strv(cfg, disks, error)) {
 g_printerr(_(Unable to parse disks: %s\n),
@@ -329,6 +339,10 @@ inheriting the host's root filesystem.
 NB. CDIR must contain a matching install of the libvirt-sandbox
 package. This restriction may be lifted in a future version.
 
+=item B--env key=value
+
+Sets up a custom environment variable on a running sandbox.
+
 =item B--disk TYPE:TAGNAME=SOURCE,format=FORMAT
 
 Sets up a disk inside the sandbox by using BSOURCE with a symlink named as 
BTAGNAME
-- 
2.1.0

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


Re: [libvirt] [PATCH] network type ethernet not needs to be reconnected

2015-08-28 Thread Laine Stump

On 08/28/2015 06:42 AM, Vasiliy Tolstov wrote:

2015-08-24 14:56 GMT+03:00 Vasiliy Tolstov v.tols...@selfip.ru:

2015-08-24 14:45 GMT+03:00 Laine Stump la...@laine.org:

I've been looking back at the history of why this code was added in the
first place to make sure we're not inadvertently breaking something else.

It looks like originally that code did check that ipaddr hadn't changed
(when there was a single IP address), which wasn't needed but also
didn't hurt anything (since ipaddr would always be 0 for type='ethernet'
in the qemu driver. Then recently (commit aa2cc7) support for multiple
IP addresses with type='ethernet' was added (apparently for LXC, but
also added for openvz), any code that had touched ethernet.ipaddr was
changed to look at nips and the ip array instead, but the code that
replaced the unnecessary but innocuous check in qemu_hotplug.c was done
incorrectly. So the correct thing *is* to simply remove the check.

All of that is a long winded way of saying ACK. I'll push it in awhile.


Thanks!


I don't see this change in current master. Does it goes to 1.2.19 or to 1.2.20?



It was pushed on on Monday, commit id 
bbc705d1309b8ec2eb4cdae011dc702802c96d11. It will be in 1.2.19. I took 
the liberty of expanding the commit log message, so you may not have 
recognized it:



commit bbc705d1309b8ec2eb4cdae011dc702802c96d11
Author: Vasiliy Tolstov v.tols...@selfip.ru
Date:   Sat Aug 22 15:33:15 2015 +

Eliminate incorrect and unnecessary check for changed IP address

Commit aa2cc7 modified a previously unnecessary but innocuous check
for interface IP address during interface update incorrectly, causing
all attempted updates (e.g. changing link state) to interfaces of
type='ethernet' for QEMU to fail.

This patch fixes the issue by completely removing the check for IP
address, which is pointless since QEMU doesn't support setting
interface IP addresses from the domain interface XML anyway.

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


[libvirt] [sandbox PATCH v4 17/21] Image: man file for virt-sandbox-image

2015-08-28 Thread Eren Yagdiran
---
 bin/Makefile.am|   5 ++
 bin/virt-sandbox-image.pod | 172 +
 2 files changed, 177 insertions(+)
 create mode 100644 bin/virt-sandbox-image.pod

diff --git a/bin/Makefile.am b/bin/Makefile.am
index df4c7dc..5d7ff8a 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -23,6 +23,7 @@ POD_FILES = \
virt-sandbox-service-delete.pod \
virt-sandbox-service-reload.pod \
virt-sandbox-service-upgrade.pod \
+   virt-sandbox-image.pod \
$(NULL)
 EXTRA_DIST = virt-sandbox-service \
  virt-sandbox-image.in \
@@ -40,6 +41,7 @@ man1_MANS = \
virt-sandbox-service-delete.1 \
virt-sandbox-service-reload.1 \
virt-sandbox-service-upgrade.1 \
+   virt-sandbox-image.1 \
$(NULL)
 
 POD2MAN = pod2man -c Virtualization Support -r $(PACKAGE)-$(VERSION)
@@ -71,6 +73,9 @@ virt-sandbox-service-reload.1: 
virt-sandbox-service-reload.pod Makefile
 virt-sandbox-service-upgrade.1: virt-sandbox-service-upgrade.pod Makefile
$(AM_V_GEN)$(POD2MAN) $ $(srcdir)/$@
 
+virt-sandbox-image.1: virt-sandbox-image.pod Makefile
+   $(AM_V_GEN)$(POD2MAN) $ $(srcdir)/$@
+
 CLEANFILES = $(man1_MANS) \
  virt-sandbox-image
 
diff --git a/bin/virt-sandbox-image.pod b/bin/virt-sandbox-image.pod
new file mode 100644
index 000..a85fcd9
--- /dev/null
+++ b/bin/virt-sandbox-image.pod
@@ -0,0 +1,172 @@
+=head1 NAME
+
+virt-sandbox-image - Sandbox Container Image Tool
+
+=head1 SYNOPSIS
+
+  {download,create,run,delete}
+
+  commands:
+
+download  Download template data
+
+createCreate image from template data
+
+run   Run an already built image
+
+deleteDelete template data
+
+=head1 DESCRIPTION
+
+virt-sandbox-image.py is a sandbox container image tool developed in python.
+This tool can download,create,run and delete templates which are provided by
+different sources. This tool comes with Docker source by default. Other sources
+can be implemented by extending source class
+
+=head1 OPTIONS
+
+=over 4
+
+=item Bdownload name -s source -r registry -u username -p password -t 
template_directory
+
+Download a template by given name with a specified source.
+
+=over 6
+
+=item Bname
+
+Template name to download
+
+=item B-s or --source
+
+Source parameter will try load source module under sources/ directory. Each 
source has to implement Source.py base class and register itself with a proper 
name
+Default source is Docker.
+
+=item B-r or --registry
+
+Custom registry url for downloading data. This might need privileged 
credentials which can be specified by --username and --password parameters.
+
+=item B-u or --username
+
+Username for custom registry authentication
+
+=item B-p or --password
+
+Password for custom registry authentication
+
+=item B-t or --template-dir
+
+Custom directory for downloading template data
+
+=back
+
+=item Bcreate name imagepath format -s source -d driver
+
+Create already downloaded template into image with given format.
+
+=over 5
+
+=item Bname
+
+Template name to download.
+
+=item Bimagepath
+
+Image path where template image will be stored.
+
+=item Bformat
+
+Image format e.g qcow2
+
+=item B-s or --source
+
+Source parameter will try load source module under sources/ directory. Each 
source has to implement Source.py base class and register itself with a proper 
name
+Default source is Docker.
+
+=item B-d or --driver
+
+Driver parameter can be specified with only supported driver by 
libvirt-sandbox. These are lxc:///, qemu:///session, qemu:///system.
+
+=back
+
+=item Brun name imagepath format -c command -n network -v volume -s source -d 
driver
+
+Run already built image.
+
+=over 6
+
+=item Bname
+
+Template name to download.
+
+=item Bimagepath
+
+Image path where template image will be stored.
+
+=item B-c or --command
+
+Command for running a image. If it is not specified, virt-sandbox-image will 
try to load command params from specified source. E.g /bin/bash
+
+=item B-n or --network
+
+Network params will be passed directly to the virt-sandbox. More information 
about network params, See Cvirt-sandbox(8)
+
+=item B-v or --volume
+
+Volume params are for binding host-paths to the guest. E.g -v /home:/home will 
map /home directory from host to the guest.
+
+=item B-d or --driver
+
+Driver parameter can be specified with only supported driver by 
libvirt-sandbox. These are lxc:///, qemu:///session, qemu:///system.
+
+=back
+
+=item Bdelete name imagepath -s source 
+
+Delete downloaded template data and its built image.
+
+=over 3
+
+=item Bname
+
+Template name to delete.
+
+=item Bimagepath
+
+Image path where template data or image stays.
+
+=item B-s or --source
+
+Source parameter will try load source module under sources/ directory. Each 
source has to implement Source.py base class and register itself with a proper 
name
+Default source is Docker.
+
+=back
+
+=back

[libvirt] [sandbox PATCH v4 00/21] *** virt-sandbox-image v4 ***

2015-08-28 Thread Eren Yagdiran
Hi,

Running sandbox now has its own disk layer.
virt-sandbox now using GHashMap to store key value pairs for environment 
variables
and some minor changes.

Daniel P Berrange (1):
  Add virt-sandbox-image

Eren Yagdiran (20):
  Fix virt-sandbox-image
  Image: Add Hooking Mechanism
  Image: virt-sandbox-image default dir constants
  Image: Discard caching bytecode
  Image: Add check_writable and runtime resolver
  Image: Add download function
  Image: Refactor create function
  Image: Add delete function
  Image: Add get_command function to Source
  Image: Add run args
  Image: Add check_connect function
  Image: Add get_disk function to Source
  Image: Add run function
  Image: Add network support
  Image: Add Volume Support
  Image: man file for virt-sandbox-image
  Add config for environment variables
  Add environment parameter to virt-sandbox
  init-common: Exporting custom environment variables
  Image: Add custom environment support

 .gitignore|   1 +
 bin/Makefile.am   |  21 +-
 bin/virt-sandbox-image.in |   3 +
 bin/virt-sandbox-image.pod| 172 +++
 bin/virt-sandbox.c|  14 +
 configure.ac  |   2 +
 libvirt-sandbox/libvirt-sandbox-config.c  | 171 ++-
 libvirt-sandbox/libvirt-sandbox-config.h  |  13 +
 libvirt-sandbox/libvirt-sandbox-init-common.c |  18 ++
 libvirt-sandbox/libvirt-sandbox.sym   |   6 +
 libvirt-sandbox/tests/test-config.c   |  10 +
 po/POTFILES.in|   1 +
 virt-sandbox-image/Makefile.am|  14 +
 virt-sandbox-image/sources/DockerSource.py| 419 ++
 virt-sandbox-image/sources/Source.py  |  55 
 virt-sandbox-image/sources/__init__.py|  26 ++
 virt-sandbox-image/virt-sandbox-image.py  | 306 +++
 17 files changed, 1247 insertions(+), 5 deletions(-)
 create mode 100644 bin/virt-sandbox-image.in
 create mode 100644 bin/virt-sandbox-image.pod
 create mode 100644 virt-sandbox-image/Makefile.am
 create mode 100644 virt-sandbox-image/sources/DockerSource.py
 create mode 100644 virt-sandbox-image/sources/Source.py
 create mode 100644 virt-sandbox-image/sources/__init__.py
 create mode 100755 virt-sandbox-image/virt-sandbox-image.py

-- 
2.1.0

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


Re: [libvirt] [PATCH] lxc: ensure setns() syscall is defined

2015-08-28 Thread Guido Günther
Hi,
On Wed, Aug 26, 2015 at 03:53:43PM +0100, Daniel P. Berrange wrote:
 Older versions of glibc don't provide the setns() syscall
 function wrapper, so we must define it ourselves to prevent
 build failure on old distros.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 
 Pushed as a RHEL-6 build-break fix

This also fixes the build on Debian Wheezy. Thanks!
 -- Guido

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


[libvirt] [sandbox PATCH v4 20/21] init-common: Exporting custom environment variables

2015-08-28 Thread Eren Yagdiran
Common-init reads config file and exports custom environment
variables from config file and applies them to the running sandbox.
---
 libvirt-sandbox/libvirt-sandbox-init-common.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c 
b/libvirt-sandbox/libvirt-sandbox-init-common.c
index d35f760..16abf25 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -336,6 +336,21 @@ static gboolean setup_network(GVirSandboxConfig *config, 
GError **error)
 }
 
 
+static gboolean setup_custom_env(GVirSandboxConfig *config, GError **error)
+{
+gboolean ret = FALSE;
+GHashTableIter iter;
+gpointer key, value;
+g_hash_table_iter_init (iter, gvir_sandbox_config_get_envs(config));
+while (g_hash_table_iter_next (iter, key, value)){
+if(setenv(key,value,1)!=0)
+goto cleanup;
+}
+ret = TRUE;
+  cleanup:
+return ret;
+}
+
 static int change_user(const gchar *user,
uid_t uid,
gid_t gid,
@@ -1262,6 +1277,9 @@ int main(int argc, char **argv) {
 if (!setup_disk_tags())
 exit(EXIT_FAILURE);
 
+if (!setup_custom_env(config, error))
+goto error;
+
 if (!setup_network(config, error))
 goto error;
 
-- 
2.1.0

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


Re: [libvirt] [PATCH 6/9] Add functions for adding usb controllers to addrs

2015-08-28 Thread John Ferlan

Perhaps needs a bit more meat/description for the commit message...

On 08/12/2015 10:52 AM, Ján Tomko wrote:
 ---
  src/conf/domain_addr.c   | 88 
 
  src/conf/domain_addr.h   |  4 +++
  src/libvirt_private.syms |  1 +
  3 files changed, 93 insertions(+)
 
 diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
 index 3962357..024d47b 100644
 --- a/src/conf/domain_addr.c
 +++ b/src/conf/domain_addr.c
 @@ -1239,3 +1239,91 @@ void 
 virDomainUSBAddressSetFree(virDomainUSBAddressSetPtr addrs)
  VIR_FREE(addrs-buses);
  VIR_FREE(addrs);
  }
 +
 +
 +static int virDomainUSBAddressSetAddController(virDomainUSBAddressSetPtr 
 addrs,
 +   virDomainControllerDefPtr 
 cont)

static int
virDomain*

 +{
 +virDomainUSBAddressHubPtr hub = NULL;
 +size_t ports = 0;

Perhaps easier if use 'nports'

 +int ret = -1;
 +int model = cont-model;
 +
 +VIR_DEBUG(addrs=%p controller type=%d model=%d,
 +  addrs, cont-type, cont-model);
 +
 +if (VIR_ALLOC(hub)  0)
 +goto cleanup;

This should be paired this with the ports allocation and have a separate
API to also be used by next patch

 +
 +if (model == -1)
 +model = VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI;
 +
 +switch ((virDomainControllerModelUSB)model) {
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX3_UHCI:
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_PIIX4_UHCI:
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_VT82C686B_UHCI:
 +ports = 2;
 +break;
 +
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_EHCI:
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1:
 +ports = 6;
 +break;
 +
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI1:
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI2:
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI3:
 +return 0;
 +/* FIXME * check the companions? */
 +ports = 2;
 +break;

This needs to be fixed/resolved.

 +
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_PCI_OHCI:
 +ports = 3;
 +break;
 +
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI:
 +ports = 15;
 +
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE:
 +case VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST:
 +ret = 0;
 +goto cleanup;
 +}
 +
 +if (cont-idx = addrs-nbuses) {
 +if (VIR_EXPAND_N(addrs-buses, addrs-nbuses, cont-idx - 
 addrs-nbuses + 1)  0)
 +goto cleanup;
 +}

So if I read this correctly, someone defining a single controller in
their XML with an index of 5 (or 10 or 100 or anything up to 0xfff -
which is supposed to be the bus# max) will be creating that many
AddressSets. There's no requirement that one numbers their controllers
starting at '0' - just that the index is used as the order to be loaded.
Perhaps not what is desired.  Perhaps need some sort of number of
controllers of type 'model' found API rather than a straight 'idx' to
'nbuses' comparison.

Once it's figured out which controller index is being used, that could
be set in 'addrs-ctlr_idx'.  Could also create a companion search API
or two that could take the 'ctlr_idx' and find the controller knowing
the eventual USB device type.

Since there's no guarantee of having cont-idx start at 0 and run
through some maximum, should this use a VIR_INSERT_ELEMENT type
algorithm to keep things ordered?  Using ctlr_idx for ordering (if it
even matters).


 +
 +if (VIR_ALLOC_N(hub-ports, ports + 1)  0)
 +goto cleanup;
 +hub-nports = ports + 1;
 +

Mental note #1 - why are we allocating an extra port?  Answered later on
- using port#0 is not valid (nor is using 0 in dotted notation - eg
1.0.1 would equate to just 1).  Since this isn't obvious - it might be
beneficial to add a note as to why we're adding 1.

Mental note #2 - this is what I'll refer to later as the root usb hub...

The VIR_ALLOC(hub) and this VIR_ALLOC_N should have a separate API to be
shared in next patch as well. It can take a parameter of 'nports'.

What's not fully clear (and something I note in the next patch) is
whether a root hub port can contain a device or if it has to contain
another hub.  I would think physically the answer would be a device
could live on the root hub, but dealing with the physical world is not
something I know all that well..


 +VIR_DEBUG(Added %zu ports on hub %p, hub-nports - 1, hub);
 +
 +/* FIXME: is there a bus already? */
 +addrs-buses[cont-idx] = hub;

Wouldn't this be solved with VIR_INSERT_ELEMENT?  If buses[cont-idx] !=
NULL before this line what does that say - something's wrong with the
algorithm. At the very least you'll leak memory and lose at least 1
device and possibly more.

 +hub = NULL;
 +
 +ret = 0;
 + cleanup:
 +VIR_FREE(hub);
 +return ret;
 +}
 +
 +
 +int virDomainUSBAddressSetAddControllers(virDomainUSBAddressSetPtr addrs,
 + virDomainDefPtr 

Re: [libvirt] [PATCH 8/9] Assign addresses to USB devices

2015-08-28 Thread John Ferlan


On 08/12/2015 10:52 AM, Ján Tomko wrote:
 Automatically assign addresses to USB devices.
 
 Just like reserving, this is only done for newly defined domains.
 
 https://bugzilla.redhat.com/show_bug.cgi?id=1215968
 ---
  src/conf/domain_addr.c | 88 
 +-
  src/conf/domain_addr.h |  6 ++
  src/libvirt_private.syms   |  1 +
  src/qemu/qemu_command.c| 87 +
  ...qemuhotplug-console-compat-2+console-virtio.xml |  4 +-
  .../qemuxml2argvdata/qemuxml2argv-bios-nvram.args  |  2 +-
  tests/qemuxml2argvdata/qemuxml2argv-bios.args  |  2 +-
  .../qemuxml2argv-console-compat-2.xml  |  4 +-
  .../qemuxml2argv-controller-order.args |  7 +-
  .../qemuxml2argv-controller-order.xml  |  2 +
  .../qemuxml2argv-disk-usb-device-removable.args|  3 +-
  .../qemuxml2argv-disk-usb-device.args  |  3 +-
  .../qemuxml2argv-graphics-spice-timeout.args   |  2 +-
  ...muxml2argv-hostdev-usb-address-device-boot.args |  2 +-
  .../qemuxml2argv-hostdev-usb-address-device.args   |  3 +-
  .../qemuxml2argv-hugepages-numa.args   |  2 +-
  .../qemuxml2argv-pseries-usb-kbd.args  |  2 +-
  .../qemuxml2argv-serial-spiceport.args |  2 +-
  .../qemuxml2argv-smartcard-controller.args |  2 +-
  .../qemuxml2argv-smartcard-host-certificates.args  |  2 +-
  .../qemuxml2argv-smartcard-host.args   |  2 +-
  ...emuxml2argv-smartcard-passthrough-spicevmc.args |  3 +-
  .../qemuxml2argv-smartcard-passthrough-tcp.args|  2 +-
  .../qemuxml2argv-sound-device.args |  2 +-
  .../qemuxml2argv-usb-port-autoassign.args  | 15 
  .../qemuxml2argv-usb-port-autoassign.xml   | 27 +++
  tests/qemuxml2argvtest.c   |  6 +-
  27 files changed, 260 insertions(+), 23 deletions(-)
  create mode 100644 
 tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.args
  create mode 100644 
 tests/qemuxml2argvdata/qemuxml2argv-usb-port-autoassign.xml
 

NB: Less thorough thinking than last 3...

 diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
 index cda6e08..15f4753 100644
 --- a/src/conf/domain_addr.c
 +++ b/src/conf/domain_addr.c
 @@ -1392,9 +1392,95 @@ int 
 virDomainUSBAddressSetAddControllers(virDomainUSBAddressSetPtr addrs,
  }
  
  
 +static int
 +virDomainUSBAddressFindFreePort(virDomainUSBAddressHubPtr hub,
 +unsigned int *portpath,
 +unsigned int idx)
 +{
 +size_t i;
 +
 +/* Look for free ports on the current hub */
 +for (i = 1; i  hub-nports; i++) {
 +if (!hub-ports[i]) {
 +VIR_DEBUG(Found a free port %zu at level %u, i, idx);
 +portpath[idx] = i;
 +return 0;
 +}
 +}

This seems to indicate something can be plugged directly into the root
hub...  Definitely would help me for some kind of picture sigh.

 +
 +VIR_DEBUG(No ports found on hub %p, trying the hubs on it, hub);
 +
 +if (idx = VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH - 1)
 +return -1;
 +
 +/* Recursively search through the ports
 + * that contain another hub */
 +for (i = 1; i  hub-nports; i++) {
 +VIR_DEBUG(level: %u port: %zu, nports: %zu, idx, i,
 +  hub-ports[i]-nports);
 +
 +if (hub-ports[i]-nports 
 +virDomainUSBAddressFindFreePort(hub-ports[i],
 +portpath,
 +idx + 1) == 0) {
 +portpath[idx] = i;
 +return 0;
 +}
 +
 +}
 +return -1;
 +}
 +
 +
 +int
 +virDomainUSBAddressAssign(virDomainUSBAddressSetPtr addrs,
 +  virDomainDeviceInfoPtr info,
 +  bool isHub)
 +{
 +unsigned int portpath[VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH] = { 0 };
 +virDomainDeviceDefPtr dev = NULL;
 +char *portstr;
 +size_t i;
 +int ret = -1;
 +
 +if (isHub) {
 +if (VIR_ALLOC(dev)  0)
 +goto cleanup;
 +dev-type = VIR_DOMAIN_DEVICE_HUB;
 +if (VIR_ALLOC(dev-data.hub)  0)
 +goto cleanup;
 +dev-data.hub-type = VIR_DOMAIN_HUB_TYPE_USB;
 +}
 +
 +for (i = 0; i  addrs-nbuses; i++) {
 +virDomainUSBAddressHubPtr hub = addrs-buses[i];
 +if (!hub)
 +continue;
 +
 +if (virDomainUSBAddressFindFreePort(hub, portpath, 0) == 0) {
 +info-type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB;
 +info-addr.usb.bus = i;
 +portstr = virDomainUSBAddressGetPortString(portpath);

What happens if portstr == NULL ?

 +memcpy(info-addr.usb.port, portpath, 
 VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH);
 +VIR_DEBUG(Assigning USB addr bus=%u port=%s,
 +  info-addr.usb.bus, portstr);
 

[libvirt] Should external snapshots be possible with type volume image files?

2015-08-28 Thread Stefan Bader
At least up to libvirt version 1.2.16 an external snapshot fails when the image
file (supported type like QCOW2) is  not specified as type='file' by as
type='volume' to a pool that consists of image files (type directory).
The reason there is that the source element of the disk definition does not
contain the full path but only references to pool and volume name. Which would
require an additional indirection in order to find that it actually is a file
and what the path is. And that would make things more complicated.
So my question is whether this should work and needs fixing in code or was never
meant to be used that way. If the latter, then maybe needs a clarification in
the documentation. At least the wiki did read for me as only requiring to be a
image file of a supported type. And we got at least one bug report about it.

Thanks,
Stefan



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

Re: [libvirt] [PATCH 7/9] Reserve existing USB addresses

2015-08-28 Thread John Ferlan


On 08/12/2015 10:52 AM, Ján Tomko wrote:
 If USB addresses have been provided for all USB devices,
 or we are defining a new domain, reserve the addresses.
 
 Check if they fit on the USB controllers the domain has,
 and error out if two devices try to use the same address.
 
 Do not error out on missing hubs.
 
 The input-usbmouse test used port=4 even though the implicit
 USB controller only has two.
 ---
  src/conf/domain_addr.c | 109 
  src/conf/domain_addr.h |   6 +
  src/libvirt_private.syms   |   1 +
  src/qemu/qemu_command.c| 137 
 -
  src/qemu/qemu_domain.h |   1 +
  .../qemuxml2argv-input-usbmouse-addr.args  |   2 +-
  .../qemuxml2argv-input-usbmouse-addr.xml   |   2 +-
  .../qemuxml2argv-usb-hub-conflict.xml  |  22 
  tests/qemuxml2argvtest.c   |   3 +
  9 files changed, 280 insertions(+), 3 deletions(-)
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-hub-conflict.xml
 

Wouldn't qemuDomainObjPrivateFree need to be updated as well to free
'usbaddrs' (similar to pciaddrs, ccwaddrs, vioserialaddrs)?

What about qemuProcessStop where the various addr's have their free
routines called and then the *addrs pointer set to NULL?


 diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
 index 024d47b..cda6e08 100644
 --- a/src/conf/domain_addr.c
 +++ b/src/conf/domain_addr.c
 @@ -1313,6 +1313,69 @@ static int 
 virDomainUSBAddressSetAddController(virDomainUSBAddressSetPtr addrs,
  }
  
  
 +/* Finds the port specified by the port path in the device info.
 + * The USB bus is expected to exist.
 + * The USB hubs will be auto-created.
 + */
 +static int

ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)

 +virDomainUSBAddressFindPort(virDomainUSBAddressHubPtr **port,
 +virDomainUSBAddressSetPtr addrs,
 +virDomainDeviceInfoPtr info)
 +{
 +ssize_t i;
 +virDomainUSBAddressHubPtr *hub = NULL;
 +char *portstr = NULL;
 +int ret = -1;
 +
 +portstr = virDomainUSBAddressGetPortString(info-addr.usb.port);

What happens if portstr == NULL ?

 +
 +if (addrs-nbuses = info-addr.usb.bus ||
 +!addrs-buses[info-addr.usb.bus]) {

Personally it's easier to think about it as if info-addr.usb.bus 
addrs-nbuses...

This would perhaps be a place where a find a bus by ctlr_idx number
could be useful - considering earlier review comments where I noted we
may not want to create 'cont-idx' buses.

 +virReportError(VIR_ERR_XML_ERROR, _(Missing USB bus %u),
 +   info-addr.usb.bus);
 +goto cleanup;
 +}
 +hub = (addrs-buses[info-addr.usb.bus]);

I would think !hub would be a problem here since it's the root/bus
hub...  To start out with at least the root hub better point to
something...  Hence my ATTRIBUTE_NONNULL above...

 +
 +for (i = 0; i  VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH; i++) {
 +int portnum = info-addr.usb.port[i];
 +if (!portnum)
 +break;

oh or oy - here's the nested ports (eg the dotted octet's)...

Assuming we have port='1', then we fall into the rest of this when it
feels to me that we shouldn't. It would seem we're allocating perhaps an
extra layer that we don't want to. To me it seems the current algorithm
would allocate an AddressHub off the bus/root hub at index[0] with
nports=9.

Assuming a 2 port root usb hub, after return from here we'd end up with:

AddressSet
+-+  AddressHub
| buses[] | ++
| nbuses  |  | ports[]| ++  AddressHub
+-+  | nports |  |ports[0]| ++
 ++  |ports[1]|  | ports[]| ...
  nports == 2++  | nports |
 ++
 nports == 9

Then the caller would allocate another AddressHub with nports=0 at the
AddressHub on the right at ports[0]. I guess I would have assumed that
the AddressHub would nports=0 could be allocated at ports[0] off the
root/usb hub.

So the rather than actually plugging something directly into the root
usb hub, the algorithm creates an unnecessary hub, leaving

host - root hub[0] - hub[0] - device

instead of

host - root hub[0] - device

I think perhaps what's trying to be accomplished is to count the depth
of the portstr, where the depth is 1, 2, 3, or 4. If the depth is 1,
then I think we'd return to the caller which would hopefully allocate an
AddressHub w/ nports=0 and plug the device directly into the root hub.
If the depth was 2, 3, or 4, then we'd have to allocate 'depth' nested
hubs each at the location of the port[i] value and then return to the
caller which would plug our device into that last port.

The following is just 

Re: [libvirt] [PATCH] network type ethernet not needs to be reconnected

2015-08-28 Thread Vasiliy Tolstov
2015-08-28 17:03 GMT+03:00 Laine Stump la...@laine.org:
 It was pushed on on Monday, commit id
 bbc705d1309b8ec2eb4cdae011dc702802c96d11. It will be in 1.2.19. I took the
 liberty of expanding the commit log message, so you may not have recognized
 it:


Thanks! =)

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

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


Re: [libvirt] [PATCH 9/9] Assign addresses on USB device hotplug

2015-08-28 Thread John Ferlan


On 08/12/2015 10:52 AM, Ján Tomko wrote:
 USB disks, redirected devices, host devices and serial devices
 are supported.
 ---
  src/conf/domain_addr.c | 34 +++
  src/conf/domain_addr.h |  4 +++
  src/libvirt_private.syms   |  1 +
  src/qemu/qemu_command.c|  5 +++
  src/qemu/qemu_hotplug.c| 39 
 ++
  .../qemuhotplug-hotplug-base+disk-usb.xml  |  1 +
  6 files changed, 84 insertions(+)
 

Like patch 8 - less in depth analysis here.

 diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
 index 15f4753..42c0837 100644
 --- a/src/conf/domain_addr.c
 +++ b/src/conf/domain_addr.c
 @@ -1522,3 +1522,37 @@ virDomainUSBAddressReserve(virDomainDefPtr def 
 ATTRIBUTE_UNUSED,
  VIR_FREE(portstr);
  return ret;
  }
 +
 +
 +int
 +virDomainUSBAddressRelease(virDomainUSBAddressSetPtr addrs,
 +   virDomainDeviceInfoPtr info)
 +{
 +virDomainUSBAddressHubPtr *port = NULL;
 +char *portstr = NULL;
 +int ret = -1;
 +
 +if (info-type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB)
 +return 0;
 +
 +portstr = virDomainUSBAddressGetPortString(info-addr.usb.port);

What if portstr == NULL

 +VIR_DEBUG(Releasing USB addr bus=%u port=%s, info-addr.usb.bus, 
 portstr);
 +
 +if (virDomainUSBAddressFindPort(port, addrs, info)  0)
 +goto cleanup;
 +
 +if (!*port) {
 +if ((*port)-nports) {
 +virReportError(VIR_ERR_INTERNAL_ERROR, %s,
 +   _(usb-hub hotunplug is not yet implemented));
 +goto cleanup;
 +}
 +VIR_FREE(*port);
 +}
 +
 +ret = 0;
 +
 + cleanup:
 +VIR_FREE(portstr);
 +return ret;
 +}
 diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
 index 8ecf588..fbd9557 100644
 --- a/src/conf/domain_addr.h
 +++ b/src/conf/domain_addr.h
 @@ -281,4 +281,8 @@ virDomainUSBAddressReserve(virDomainDefPtr def,
 virDomainDeviceInfoPtr info,
 void *data)
  ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
 +int
 +virDomainUSBAddressRelease(virDomainUSBAddressSetPtr addrs,
 +   virDomainDeviceInfoPtr info)
 +ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
  #endif /* __DOMAIN_ADDR_H__ */
 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
 index 048ec68..9c53b13 100644
 --- a/src/libvirt_private.syms
 +++ b/src/libvirt_private.syms
 @@ -109,6 +109,7 @@ virDomainPCIAddressValidate;
  virDomainUSBAddressAssign;
  virDomainUSBAddressGetPortBuf;
  virDomainUSBAddressGetPortString;
 +virDomainUSBAddressRelease;
  virDomainUSBAddressReserve;
  virDomainUSBAddressSetAddControllers;
  virDomainUSBAddressSetCreate;
 diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
 index 9df542e..277e431 100644
 --- a/src/qemu/qemu_command.c
 +++ b/src/qemu/qemu_command.c
 @@ -2106,6 +2106,11 @@ qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
  virDomainVirtioSerialAddrRelease(priv-vioserialaddrs, info)  0)
  VIR_WARN(Unable to release virtio-serial address on %s,
   NULLSTR(devstr));
 +if (info-type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB 
 +priv-usbaddrs 
 +virDomainUSBAddressRelease(priv-usbaddrs, info)  0)
 +VIR_WARN(Unable to release usb address on %s,
 + NULLSTR(devstr));
  }
  
  
 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
 index 8e38153..e72237a 100644
 --- a/src/qemu/qemu_hotplug.c
 +++ b/src/qemu/qemu_hotplug.c
 @@ -669,6 +669,7 @@ qemuDomainAttachUSBMassStorageDevice(virConnectPtr conn,
  char *devstr = NULL;
  virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
  const char *src = virDomainDiskGetSource(disk);
 +bool releaseaddr;
  
  for (i = 0; i  vm-def-ndisks; i++) {
  if (STREQ(vm-def-disks[i]-dst, disk-dst)) {
 @@ -678,6 +679,16 @@ qemuDomainAttachUSBMassStorageDevice(virConnectPtr conn,
  }
  }
  
 +if (priv-usbaddrs) {
 +if (disk-info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
 +if (virDomainUSBAddressReserve(NULL, NULL, disk-info, 
 priv-usbaddrs)  0)
 +goto cleanup;
 +} else if (virDomainUSBAddressAssign(priv-usbaddrs, disk-info, 
 false)  0) {
 +goto cleanup;
 +}
 +releaseaddr = true;
 +}
 +
  if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false)  0)
  goto cleanup;
  
 @@ -728,6 +739,8 @@ qemuDomainAttachUSBMassStorageDevice(virConnectPtr conn,
  virDomainDiskInsertPreAlloced(vm-def, disk);
  
   cleanup:
 +if (ret  0  releaseaddr)
 +virDomainUSBAddressRelease(priv-usbaddrs, disk-info);
  VIR_FREE(devstr);
  VIR_FREE(drivestr);
  virObjectUnref(cfg);
 @@ -1536,6 +1549,16 @@ 
 

Re: [libvirt] [PATCH 5/9] Introduce virDomainUSBAddressSet

2015-08-28 Thread John Ferlan

Picking up where I left off (more or less) before KVM Forum...  I think
I need a virtual whiteboard... I tried reviewing patches 5 - 7 together
- going back and forth. Hopefully I haven't left (m)any disjoint
thoughts... I have left some thoughts on the way through - some just to
make sure I'm following what's being done...  others because I found
something not quite right.

On 08/12/2015 10:52 AM, Ján Tomko wrote:
 A new type to track USB addresses.
 
 The buses in virDomainUSBAddressSet correspond to USB controllers.
 They are represented by the virDomainUSBAddressHub type, having nports
 USB ports. These can contain nested hubs (nports != 0), or they can be
 occupied by other USB devices (with nports = 0).

Recalling earlier reviews - nested ports are the n.n, n.n.n, and
n.n.n.n dotted octet port numbers... What's still not clear in my mind
is whether it's possible to have port='1' and port='1.1' in
hardware. Based on the algorithm - I assume not, but without digging in
it wasn't obvious. Maybe this is something we can document to make it
clearer.

Based on your description and the recursive virDomainUSBAddressHubFree,
pictorally this is what I envision:

AddressSet
+-+   AddressHub
| buses[] | ++
| nbuses  |  | ports[]| +-+  AddressHub
+-+  | nports |  | ports[0]| ++
 ++  | ports[1]|  | ports  + ...
  nports != 0+-+  | nports |
  ++
  nports != 0

After reading further, I think AddressSet may need to define which
controller index is being used rather than allocate an array of buses
based on the controller index found.

It also took me a while to find where nports == 0 (the code wasn't self
commenting ;-))

It seems that AddressSet is an array of buses (numbered 0...0xfff
according to formatdomain.html.in - something that could be checked) and
that AddressHub is either another hub (eg, an array of 'nports') or a
device. An array entry can contain either another array or a device.
There can be up to 4 nested octets.

 ---
  src/conf/domain_addr.c   | 41 +
  src/conf/domain_addr.h   | 17 +
  src/libvirt_private.syms |  2 ++
  3 files changed, 60 insertions(+)
 
 diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
 index a5d142d..3962357 100644
 --- a/src/conf/domain_addr.c
 +++ b/src/conf/domain_addr.c
 @@ -1198,3 +1198,44 @@ virDomainUSBAddressGetPortString(unsigned int *port)
  return NULL;
  return virBufferContentAndReset(buf);
  }
 +
 +
 +virDomainUSBAddressSetPtr
 +virDomainUSBAddressSetCreate(void)
 +{
 +virDomainUSBAddressSetPtr addrs;
 +
 +if (VIR_ALLOC(addrs)  0)
 +return NULL;
 +

I think we may need an 'addrs-ctlr_idx = -1;'

 +return addrs;
 +}
 +
 +
 +static void
 +virDomainUSBAddressHubFree(virDomainUSBAddressHubPtr hub)
 +{
 +size_t i;
 +
 +for (i = 0; i  hub-nports; i++) {
 +if (hub-ports[i])
 +virDomainUSBAddressHubFree(hub-ports[i]);
 +}
 +VIR_FREE(hub-ports);
 +VIR_FREE(hub);
 +}
 +

Need extra LF (others had 2 this one had 1)

 +void virDomainUSBAddressSetFree(virDomainUSBAddressSetPtr addrs)

void
virDomain*

 +{
 +size_t i;
 +
 +if (!addrs)
 +return;
 +
 +for (i = 0; i  addrs-nbuses; i++) {
 +if (addrs-buses[i])
 +virDomainUSBAddressHubFree(addrs-buses[i]);
 +}
 +VIR_FREE(addrs-buses);
 +VIR_FREE(addrs);
 +}
 diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
 index c6d8da7..dcf86d4 100644
 --- a/src/conf/domain_addr.h
 +++ b/src/conf/domain_addr.h
 @@ -248,4 +248,21 @@ char *
  virDomainUSBAddressGetPortString(unsigned int *port)
  ATTRIBUTE_NONNULL(1);
  
 +typedef struct _virDomainUSBAddressHub virDomainUSBAddressHub;
 +typedef virDomainUSBAddressHub *virDomainUSBAddressHubPtr;
 +struct _virDomainUSBAddressHub {
 +virDomainUSBAddressHubPtr *ports;
 +size_t nports;
 +};
 +
 +struct _virDomainUSBAddressSet {
 +virDomainUSBAddressHubPtr *buses;
 +size_t nbuses;

This may need an:

int ctlr_idx;


John
 +};
 +typedef struct _virDomainUSBAddressSet virDomainUSBAddressSet;
 +typedef virDomainUSBAddressSet *virDomainUSBAddressSetPtr;
 +
 +virDomainUSBAddressSetPtr virDomainUSBAddressSetCreate(void);
 +void virDomainUSBAddressSetFree(virDomainUSBAddressSetPtr addrs);
 +
  #endif /* __DOMAIN_ADDR_H__ */
 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
 index 5168230..a628d00 100644
 --- a/src/libvirt_private.syms
 +++ b/src/libvirt_private.syms
 @@ -108,6 +108,8 @@ virDomainPCIAddressSlotInUse;
  virDomainPCIAddressValidate;
  virDomainUSBAddressGetPortBuf;
  virDomainUSBAddressGetPortString;
 +virDomainUSBAddressSetCreate;
 +virDomainUSBAddressSetFree;
  virDomainVirtioSerialAddrAssign;
  

Re: [libvirt] [PATCH V2 1/3] libxl: fix ref counting of libxlMigrationDstArgs

2015-08-28 Thread Jim Fehlig
Michal Privoznik wrote:
 On 27.08.2015 23:38, Jim Fehlig wrote:
   
 How does it look with the following squashed in?

 diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
 index 8db3aea..9609e06 100644
 --- a/src/libxl/libxl_migration.c
 +++ b/src/libxl/libxl_migration.c
 @@ -112,9 +112,9 @@ libxlDoMigrateReceive(void *opaque)
  
  /* Remove all listen socks from event handler, and close them. */
  for (i = 0; i  nsocks; i++) {
 -virNetSocketUpdateIOCallback(socks[i], 0);
  virNetSocketRemoveIOCallback(socks[i]);
  virNetSocketClose(socks[i]);
 +virObjectUnref(socks[i]);
  socks[i] = NULL;
  }
  args-nsocks = 0;

 


 Yup, with this piece it looks good. ACK
 Er, we are currently in a freeze, but after all: a) this is a bugfix, b)
 this has been sitting on the list quite a while. So I'd say push it.
   

Thanks. Series pushed.

Regards,
Jim

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


Re: [libvirt] [PATCH v3 2/5] vz: add migration backbone code

2015-08-28 Thread Daniel P. Berrange
On Fri, Aug 28, 2015 at 12:18:30PM +0300, Nikolay Shirokovskiy wrote:
 
 
 On 27.08.2015 13:34, Daniel P. Berrange wrote:
  On Tue, Aug 25, 2015 at 12:04:14PM +0300, nshirokovs...@virtuozzo.com wrote:
  From: Nikolay Shirokovskiy nshirokovs...@virtuozzo.com
 
  This patch makes basic vz migration possible. For example by virsh:
virsh -c vz:///system migrate --direct $NAME $STUB vz+ssh://$DST/system
 
  $STUB could be anything as it is required virsh argument but it is not
  used in direct migration.
 
  Vz migration is implemented as direct migration. The reason is that vz sdk 
  do
  all the job. Prepare phase function is used to pass session uuid from
  destination to source so we don't introduce new rpc call.
  
  Looking more closely at migration again, the scenario you have is pretty
  much identical to the Xen scenario, in that the hypervisor actually
  manages the migration, but you still need a connection to dest libvirtd
  to fetch some initialization data.
  
  You have claimed you are implementing, what we describe as direct, 
  unmanaged
  migration on this page:
  
http://libvirt.org/migration.html
  
  But based on the fact that you need to talk to dest libvirtd, you should
  in fact implement 'direct, managed' migration - this name is slightly
  misleading as the VZ SDK is still actually managing it.
  
  Since you don't need to have the begin/confirm phases, you also don't
  need to implement the V3 migration protocol - it is sufficient to just
  use V1.
  
  This doesn't need many changes in your patch fortunately.
  
  
 
 I've been looking at common migration code for rather long time and think that
 using direct managed scheme for vz migration could lead to problems. Let me
 share my concerns.
 
 1. Migration protocol of version1 differs from version3 not only by number of
 stages. Version3 supports extended parameters like
 VIR_MIGRATE_PARAM_GRAPHICS_URI which have meaning for vz migration too. Thus 
 in
 future we could move to implementing version3 as well.

Ah, that is indeed true. From that POV it certainly makes sense to want
to start with V3 straight away.

 2. Direct managed stages doesn't have a meaning do anything on source, then on
 destination and so on. They interconnected and this interconnection is given 
 in
 migration algorithm. For version3 (virDomainMigrateVersion3Full) it is more
 noticeable. If finish3 phase fail then we cancel migration on confirm3 phase.
 See, we treat this phases specifically - on perform3 we think we move data, on
 finish we think we start domain on destination, on comfirm we think we stop
 domain on source. That is how qemu migration works and that is how we think of
 phases when we implement direct managed algorithm. So phases have some
 contracts. If we implement vz migration thru this scheme we could not keep
 these contracts as perform3 phase not only move data, but also kill source
 domain and start destination. The worst things the user could get are an
 erroneous warnings in logs and overall migration failure reports on actual
 migration success in case of side effect failures like rpc or OOM. The worser
 is that you should keep in mind that phases imlementation contracts are vague.

It isn't the end of the world if the Perform3 stage kills the source domain.
That is the same behaviour as with Xen. Particularly since the VZ SDK itself
does the switchover, there's no functional downside to letting Perform3
kill the source.

 So as as version1 scheme is quite simple and phase contracts are looser that
 for version3 we could go this way but i see potential problems (at least for
 developer). Thus suggest keep contracts of phases of all versions of direct
 managed migration clear and hide all differences by implementing p2p or direct
 scheme.
 
 The questing arises how these two differ. Documentation states that p2p is 
 when
 libvirt daemon manages migrations and direct is when all managing is done by
 hypervisor. As vz migration needs some help from destination daemon it looks
 like a candidate for p2p. But as this help is as just little as help
 authenticate i suggest to think of it as of direct. From implementation point
 of view there is no difference, from user point of view the difference is only
 in flags. Another argument is that if we take qemu we see that p2p is just go
 thru same steps as direct managed, the most of difference is that managing 
 move
 from client to daemon. That is p2p and direct managed are some kind of 
 coupled.
 If there is p2p then direct managed should be possible too and this is not the
 case of vz migration.

The p2p migration mode is only different from the default mode,
in that instead of the client app talking to the dest libvirtd,
it is the source libvirtd talking.

With the VZ driver though, the driver runs directly in the client
app, not libvirtd. As such, there is no benefit to implementing
p2p mode in VZ - it will just end up working in the exact same
way as the default mode in terms of 

Re: [libvirt] libvirt 1.2.19-rc1 can't configure

2015-08-28 Thread Daniel P. Berrange
On Fri, Aug 28, 2015 at 07:35:17PM +0300, Vasiliy Tolstov wrote:
 I'm try to configure libvirt 1.2.19-rc1 but get strange error.
 configure ended with:
 checking whether pthread.h pollutes the namespace... no
 checking for pthread_t... yes
 checking for pthread_spinlock_t... yes
 checking for library containing pthread_create and pthread_join... -pthread
 checking for pthread_sigmask in -pthread... yes
 checking whether pthread_sigmask is only a macro... no
 
 complete log:
 https://gist.github.com/raw/f8dc44de0ed7b0675755

You seem to be memory limited in your build host - the last
message is:

  sh: error while loading shared libraries: cannot create cache for search 
path: Cannot allocate memory


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

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


Re: [libvirt] [PATCH] Revert LXC: show used memory as 0 when domain is not active

2015-08-28 Thread Jim Fehlig
Eric Blake wrote:
 On 08/27/2015 04:38 PM, Jim Fehlig wrote:

   
 This reverts commit 1ce7c1d20cfd5afb26d2dbc88201085d52415d0e,
 which introduced a significant semantic change to the
 virDomainGetInfo() API. Additionally, the change was only
 made to 2 of the 15 virt drivers.

 

   
 I guess we should probably do this in the stable branch too, since I
 think it made it into the most recent release.
   
   
 Erm, the change is out for a while now:

 git desc 1ce7c1d20cfd5afb26d2dbc88201085d52415d0e
 v1.2.6-225-g1ce7c1d
 
 
 Oh yes, so it is. I'm still inclined to say we should be reverting it as
 I think it is wrong. The change was based on the misleading field name
 shown by virsh. The info-memory field shows the current balloon target,
 and conceptually this should be equal to the max memory if the ballooon
 driver is not active. As such I think it should be equal to max memory
 if shutoff too.
   
   
 Yikes, I forgot to commit this before leaving for travel/vacation. Is it
 still ok to commit to master? And just to be clear, then cherry pick to
 1.2.7-1.2.18 maint branches?
 

 Yes, that sounds like the best way to handle it.
   

Ok, pushed to master and v1.2.7-maint through v1.2.18-maint.

Regards,
Jim

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


[libvirt] libvirt 1.2.19-rc1 can't configure

2015-08-28 Thread Vasiliy Tolstov
I'm try to configure libvirt 1.2.19-rc1 but get strange error.
configure ended with:
checking whether pthread.h pollutes the namespace... no
checking for pthread_t... yes
checking for pthread_spinlock_t... yes
checking for library containing pthread_create and pthread_join... -pthread
checking for pthread_sigmask in -pthread... yes
checking whether pthread_sigmask is only a macro... no

complete log:
https://gist.github.com/raw/f8dc44de0ed7b0675755

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

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


Re: [libvirt] [PATCH] migration: remove direct migration dependency on version1 of driver

2015-08-28 Thread Michal Privoznik
On 28.08.2015 11:29, Nikolay Shirokovskiy wrote:
 
 
 On 28.08.2015 08:54, Michal Privoznik wrote:
 On 27.08.2015 12:23, Nikolay Shirokovskiy wrote:
 From: Nikolay Shirokovskiy Nikolay Shirokovskiy 
 nshirokovs...@virtuozzo.com

 Direct migration should work if *perform3 is present but *perform
 is not. This is situation when driver migration is implemented
 after new version of driver function is introduced. We should not
 be forced to support old version too as its parameter space is
 subspace of newer one.

 Signed-off-by: Nikolay Shirokovskiy nshirokovs...@virtuozzo.com
 ---
  src/libvirt-domain.c |3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)

 diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
 index 6ab50ba..c89775b 100644
 --- a/src/libvirt-domain.c
 +++ b/src/libvirt-domain.c
 @@ -3427,7 +3427,8 @@ virDomainMigrateDirect(virDomainPtr domain,
   NULLSTR(xmlin), flags, NULLSTR(dname), 
 NULLSTR(dconnuri),
   NULLSTR(miguri), bandwidth);
  
 -if (!domain-conn-driver-domainMigratePerform) {
 +if (!domain-conn-driver-domainMigratePerform 
 +!domain-conn-driver-domainMigratePerform3) {
  virReportUnsupportedError();
  return -1;
  }



 Hm.. domainMigratePerform3 will be used iff connection driver has
 VIR_DRV_FEATURE_MIGRATION_V3 feature. But this check will require that
 regardless. What if we check the presence of implementation with respect
 to that?
 I see you mean actual driver could be behind remote one and checking
 for perform3 always gives true so we need to check for feature instead?

Sort of. domainMigratePerform3 is used only if the feature is present.
But after your patch, the function implementation would be needed
always, even if the feature is not present.

Michal

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