[libvirt] How to execute an initial script in a container to start the network interface automatically
by WANG Cheng D
Dear All,
Happy new year to you.
I have a similar question which had been replied by Daniel in the following post:
http://www.redhat.com/archives/libvir-list/2010-March/msg00296.html
I also want to assign a static IP to the container.
As Daniel said, I can successfully assign a static IP to the container manually using " # ifconfig eth0 192.168.122.3 netmask 255.255.255.0 up".
Daniel also said that we can use "the regular distro initscripts" to automatically start the network interface, but this doesn't work on my system.
My host is fedora16. I used the command "yum --installroot=/root/fedora16lxc --releasever=16 install -y openssh, bridge-utils" to setup the rootfs for my container, but I am not sure if it is a right way.
After rootfs installation, there is no sub-directory named "network-scripts" in "/etc/sysconfig" . So, I created this directory manually and added a file named "ifcfg-eth0".
In my container's XML script, I use "<init>/bin/sh</init>". If I use "<init>/bin/init</init>", it seems that the container doesn't boot correctly because there are strings keeping rolling in the console.
My libvirtd and virsh version is 1.0.3.
I tried to add files ".bash_profile" and ".bashrc" in which I revised the shell environment variable such as PATH, I also added the "ifconfig" in the script to try to configure eth0 automatically, but it doesn't work.
I wonder if there is a ".bashrc" for the root of a container? If there is, where should this file be located?
In summary, I have two questions
1) How to setup rootfs for a container?
2) If a container can automatically execute an initial script when booting?
Your reply is highly appreciated.
With my warmest regards,
Cheng
10 years, 11 months
Re: [libvirt] libvirt live modify
by Michal Novotny
Hi Umar,
please contact libvirt guys for python bindings. Python bindings for libvirt are not handled by me, I handle just the PHP bindings and I'm not aware of the function support in the Python bindings.
Happy New Year!
Thanks,
Michal
----- Original Message -----
From: "Umar Draz" <unix.co(a)gmail.com>
To: "Michal Novotny" <minovotn(a)redhat.com>
Sent: Monday, December 23, 2013 7:03:17 PM
Subject: Re: [libvirt] libvirt live modify
Hi Michal
Thanks, its work, Ok one question
http://libvirt.org/php/api-reference.html#libvirt_domain_set_metadata
the above link is php api reference link
is there same kind of thing is available for python?
Br.
Umar
On Mon, Dec 23, 2013 at 3:27 PM, Michal Novotny <minovotn(a)redhat.com> wrote:
> Hi Umar,
> I'm on PTO, fortunately I was checking my e-mail because of the goods to
> declare so I can reply to you.
>
> For updating this please use the libvirt_domain_set_metadata() API
> function, please see [1] for documentation.
>
> Hope it helps,
> Michal
>
> [1] http://libvirt.org/php/api-reference.html#libvirt_domain_set_metadata
>
> ----- Original Message -----
> From: "Umar Draz" <unix.co(a)gmail.com>
> To: "Michal Novotny" <minovotn(a)redhat.com>
> Sent: Monday, December 23, 2013 11:05:11 AM
> Subject: Re: [libvirt] libvirt live modify
>
> Hi Michal,
>
> Sorry to disturb you again, this works great
>
> $info = @libvirt_domain_get_metadata($res,
> VIR_DOMAIN_METADATA_DESCRIPTION, '', VIR_DOMAIN_AFFECT_CURRENT);
>
> Now what I need to do for setting/updating for the domain description or
> title
>
> Br.
>
> Umar
>
>
> On Wed, Dec 18, 2013 at 8:25 PM, Michal Novotny <minovotn(a)redhat.com>
> wrote:
>
> > Hi Umar,
> > then you don't have working automake setup. Please google how to solve
> > it, I apologize but I don't really have much time to solve it right now.
> >
> > Thanks for understanding,
> > Michal
> >
> > On 12/18/2013 04:21 PM, Umar Draz wrote:
> > > Hi Michal
> > >
> > > I tried
> > >
> > > but on autogen.sh is failed
> > >
> > > automake: error: global options already processed
> > > automake: Please contact <bug-automake(a)gnu.org
> > > <mailto:bug-automake@gnu.org>>.
> > > at /usr/share/automake-1.14/Automake/Channels.pm line 662, <GEN0>
> > > line 77.
> > > Automake::Channels::msg('automake', '', 'global options
> > > already processed') called at
> > > /usr/share/automake-1.14/Automake/ChannelDefs.pm line 212
> > > Automake::ChannelDefs::prog_error('global options already
> > > processed') called at /usr/share/automake-1.14/Automake/Options.pm
> > > line 421
> > >
> > > Automake::Options::process_global_option_list('HASH(0x246df60)')
> > > called at /usr/bin/automake line 5331
> > > Automake::scan_autoconf_traces('configure.ac
> > > <http://configure.ac>') called at /usr/bin/automake line 5431
> > > Automake::scan_autoconf_files() called at /usr/bin/automake
> > > line 8259
> > > autoreconf: automake failed with exit status: 29
> > >
> > >
> > > Br.
> > >
> > > Umar
> > >
> > >
> > > On Wed, Dec 18, 2013 at 7:50 PM, Michal Novotny <minovotn(a)redhat.com
> > > <mailto:minovotn@redhat.com>> wrote:
> > >
> > > Hi Umar,
> > > you have to clone it from git repository and compile it and
> > > install. You
> > > can simply do it by:
> > >
> > > git clone git://libvirt.org/libvirt-php.git
> > > <http://libvirt.org/libvirt-php.git>
> > > ./autogen.sh
> > > make
> > > sudo make install
> > >
> > > And then you have to restart your Apache webserver.
> > >
> > > For example how to use it, see the test in
> > > test-domain-create-get-metadata.phpt file (it's normal PHP script,
> > > however I use phpt extension as PHP test but it's standard PHP
> code).
> > >
> > > Michal
> > >
> > > On 12/18/2013 03:45 PM, Umar Draz wrote:
> > > > Hi Michal,
> > > >
> > > > Thanks, Now what I need here? I already have
> > > > installed libvirt-php-0.4.8, do I need to copy
> > > >
> > > > libvirt-php.c
> > > >
> > > <
> >
> http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=src/libvirt-php.c;h=7a...
> > >
> > > > libvirt-php.
> > > >
> > > <
> >
> http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=src/libvirt-php.c;h=7a...
> > >h
> > > > in the src directory and reconfigure the php-libvirt?
> > > >
> > > > Br.
> > > >
> > > > Umar
> > > >
> > > >
> > > > On Wed, Dec 18, 2013 at 7:31 PM, Michal Novotny
> > > <minovotn(a)redhat.com <mailto:minovotn@redhat.com>
> > > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>>
> wrote:
> > > >
> > > > Hi Umar,
> > > > please see commit
> > > >
> > >
> >
> http://libvirt.org/git/?p=libvirt-php.git;a=commit;h=e3e783413d8f001ee0a2...
> > > > .
> > > >
> > > > The functions mentioned below have been implemented.
> > > >
> > > > Michal
> > > >
> > > > On 12/18/2013 01:29 PM, Umar Draz wrote:
> > > > > Hi Michal,
> > > > >
> > > > > Thanks for your efforts and help. If I need any other API
> > > I will
> > > > > definitely ask you.
> > > > >
> > > > > Br.
> > > > >
> > > > > Umar
> > > > >
> > > > >
> > > > > On Wed, Dec 18, 2013 at 5:19 PM, Michal Novotny
> > > > <minovotn(a)redhat.com <mailto:minovotn@redhat.com>
> > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>
> > > > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>
> > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>>> wrote:
> > > > >
> > > > > Hi Umar,
> > > > > that's fine. Give one or two days for this please.
> > > Maybe I'll
> > > > > implement
> > > > > earlier but I'm a bit overloaded after my PTO so I
> > > can't promise
> > > > > it will
> > > > > be earlier.
> > > > >
> > > > > Also, what APIs would you like to implement?
> > > > >
> > > > > I'm thinking of implementing these two:
> > > > >
> > > > >
> > > >
> > > http://libvirt.org/html/libvirt-libvirt.html#virDomainGetMetadata
> > > > >
> > > >
> > > http://libvirt.org/html/libvirt-libvirt.html#virDomainSetMetadata
> > > > >
> > > > > Would you like any other APIs?
> > > > >
> > > > > Thanks,
> > > > > Michal
> > > > >
> > > > > On 12/18/2013 01:15 PM, Umar Draz wrote:
> > > > > > HI Michal,
> > > > > >
> > > > > > Ok , I will wait. I hope you will get sometime to do
> > > this.
> > > > > >
> > > > > > Br.
> > > > > >
> > > > > > Umar
> > > > > >
> > > > > >
> > > > > > On Wed, Dec 18, 2013 at 5:06 PM, Michal Novotny
> > > > > <minovotn(a)redhat.com <mailto:minovotn@redhat.com>
> > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>
> > > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>
> > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>>
> > > > > > <mailto:minovotn@redhat.com
> > > <mailto:minovotn@redhat.com> <mailto:minovotn@redhat.com
> > > <mailto:minovotn@redhat.com>>
> > > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>
> > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>>>>
> wrote:
> > > > > >
> > > > > > Hi Michal and Umar,
> > > > > > it's correct I can't invoke this APIs via PHP
> > > yet. Please
> > > > > note that
> > > > > > libvirt-php is not automatically generated when
> > > doing
> > > > libvirt
> > > > > > build and
> > > > > > it's a separate project. It's rather easy to
> > > implement
> > > > it to the
> > > > > > libvirt-php so if you want to implement it, feel
> > > free to
> > > > > implement
> > > > > > or if
> > > > > > you can wait a day or two until I have some time
> > > I can
> > > > implement
> > > > > > it (the
> > > > > > project is not officially supported and it's done
> > in
> > > > the spare
> > > > > > time mainly).
> > > > > >
> > > > > > I'd just like to ask you whether there are some
> > more
> > > > APIs you'd
> > > > > > like me
> > > > > > to implement when I'll be implementing it. Are
> > > there any
> > > > > other APIs
> > > > > > you'd like?
> > > > > >
> > > > > > Thanks,
> > > > > > Michal
> > > > > >
> > > > > > On 12/18/2013 12:59 PM, Michal Privoznik wrote:
> > > > > > > On 18.12.2013 12:27, Umar Draz wrote:
> > > > > > >> Hi Peter,
> > > > > > >>
> > > > > > >> Thanks for the response, Would you please
> > > help how
> > > > I can
> > > > > > >> use *virDomainSetMetadata* with PHP or any
> > > url for
> > > > help?
> > > > > > >>
> > > > > > >> Br.
> > > > > > >>
> > > > > > >> Umar
> > > > > > > [CC'ing Michal Novotny - the libvirt-php
> > > maintainer]
> > > > > > >
> > > > > > > I don't think you can invoke those APIs via
> > > PHP. But
> > > > I expect
> > > > > > them to be
> > > > > > > able to add easily. Michal?
> > > > > > >
> > > > > > > Michal
> > > > > >
> > > > > > --
> > > > > > Michal Novotny <minovotn(a)redhat.com
> > > <mailto:minovotn@redhat.com>
> > > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>
> > > > > <mailto:minovotn@redhat.com
> > > <mailto:minovotn@redhat.com> <mailto:minovotn@redhat.com
> > > <mailto:minovotn@redhat.com>>>
> > > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>
> > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>
> > > > > <mailto:minovotn@redhat.com
> > > <mailto:minovotn@redhat.com> <mailto:minovotn@redhat.com
> > > <mailto:minovotn@redhat.com>>>>>,
> > > > > > RHCE, Red Hat
> > > > > > Virtualization | libvirt-php bindings |
> > > > php-virt-control.org <http://php-virt-control.org>
> > > <http://php-virt-control.org>
> > > > > <http://php-virt-control.org>
> > > > > > <http://php-virt-control.org>
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Umar Draz
> > > > > > Network Architect
> > > > >
> > > > > --
> > > > > Michal Novotny <minovotn(a)redhat.com
> > > <mailto:minovotn@redhat.com>
> > > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>
> > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>
> > > > <mailto:minovotn@redhat.com <mailto:minovotn@redhat.com>>>>,
> > > > > RHCE, Red Hat
> > > > > Virtualization | libvirt-php bindings |
> > > php-virt-control.org <http://php-virt-control.org>
> > > > <http://php-virt-control.org>
> > > > > <http://php-virt-control.org>
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Umar Draz
> > > > > Network Architect
> > > >
> > > > --
> > > > Michal Novotny <minovotn(a)redhat.com
> > > <mailto:minovotn@redhat.com> <mailto:minovotn@redhat.com
> > > <mailto:minovotn@redhat.com>>>,
> > > > RHCE, Red Hat
> > > > Virtualization | libvirt-php bindings | php-virt-control.org
> > > <http://php-virt-control.org>
> > > > <http://php-virt-control.org>
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Umar Draz
> > > > Network Architect
> > >
> > > --
> > > Michal Novotny <minovotn(a)redhat.com <mailto:minovotn@redhat.com>>,
> > > RHCE, Red Hat
> > > Virtualization | libvirt-php bindings | php-virt-control.org
> > > <http://php-virt-control.org>
> > >
> > >
> > >
> > >
> > > --
> > > Umar Draz
> > > Network Architect
> >
> > --
> > Michal Novotny <minovotn(a)redhat.com>, RHCE, Red Hat
> > Virtualization | libvirt-php bindings | php-virt-control.org
> >
> >
>
>
> --
> Umar Draz
> Network Architect
>
--
Umar Draz
Network Architect
10 years, 11 months
[libvirt] [PATCH] test: share state driver between test:///default connections
by Eric Blake
Prior to this patch, every test:/// URI has its own event manager,
which means that registering for an event can only ever receive
events from the connection where it issued the API that triggered
the event. But the whole idea of events is to be able to learn
about something where an API call did NOT trigger the action.
In order to actually test asynchronous events, I wanted to be able
to tie multiple test connections to the same state. Use of a file
in a test URI is still per-connection state, but now parallel
connections to test:///default (from the same binary, of course)
now share common state and can affect one another.
Here's the test program I used to expose the difference (maybe not
the most polished, but does the trick):
#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
static int counter;
static int counter2;
static virConnectPtr conn1;
static virConnectPtr conn2;
static virDomainPtr dom1;
static virDomainPtr dom2;
static int
common(virConnectPtr conn, virDomainPtr dom, int event, int detail,
void *opaque, int caller)
{
printf("%d: in callback %d, from domain %s (%d), event/detail %d/%d\n",
counter2++, caller, virDomainGetName(dom),
virDomainGetID(dom), event, detail);
return 0;
}
static int
callback1(virConnectPtr conn, virDomainPtr dom, int event, int detail,
void *opaque)
{
return common(conn, dom, event, detail, opaque, 1);
}
static int
callback2(virConnectPtr conn, virDomainPtr dom, int event, int detail,
void *opaque)
{
return common(conn, dom, event, detail, opaque, 2);
}
static bool quit;
static void
handler(int sig)
{
quit = true;
}
static void
timer(int id, void *opaque)
{
printf("%d: timer %d firing\n", counter++, id);
unsigned long l;
switch (counter) {
case 1:
if (virDomainSuspend(dom2) < 0)
exit(10);
printf("suspended\n");
break;
case 2:
if (virDomainResume(dom2) < 0)
exit(11);
printf("resumed\n");
break;
case 4:
quit = true;
/* fallthrough */
default:
virConnectGetLibVersion(conn1, &l);
break;
}
}
int main(int argc, char **argv)
{
signal(SIGINT, handler);
conn1 = virConnectOpen("test:///default");
conn2 = virConnectOpen("test:///default");
if (!conn1 || !conn2)
return 1;
dom1 = virDomainLookupByName(conn1, "test");
dom2 = virDomainLookupByName(conn2, "test");
if (!dom1 || !dom2)
return 2;
if (virEventRegisterDefaultImpl() < 0)
return 3;
int id0 = virEventAddTimeout(1000, timer, NULL, NULL);
if (id0 < 0)
return 4;
int id1 = virConnectDomainEventRegisterAny(conn1, dom1,
VIR_DOMAIN_EVENT_ID_LIFECYCLE,
VIR_DOMAIN_EVENT_CALLBACK(callback1),
NULL, NULL);
if (id1 < 0)
return 5;
int id2 = -1;
if (argc > 1) {
id2 = virConnectDomainEventRegisterAny(conn2, dom2,
VIR_DOMAIN_EVENT_ID_LIFECYCLE,
VIR_DOMAIN_EVENT_CALLBACK(callback2),
NULL, NULL);
if (id2 < 0)
return 6;
if (argc > 2) {
if (virConnectDomainEventDeregisterAny(conn2, id2) < 0)
return 7;
}
}
while (!quit)
if (virEventRunDefaultImpl() < 0)
return 20;
if (virConnectDomainEventDeregisterAny(conn1, id1) < 0)
return 21;
if (id2 >= 0 && virConnectDomainEventDeregisterAny(conn2, id2) < 0)
return 22;
if (virEventRemoveTimeout(id0) < 0)
return 23;
if (virDomainFree(dom1) < 0 || virDomainFree(dom2) < 0 ||
virConnectClose(conn1) < 0 || virConnectClose(conn2) < 0)
return 24;
return 0;
}
Pre-patch results:
$ ./run ./bar
0: timer 1 firing
suspended
1: timer 1 firing
resumed
2: timer 1 firing
3: timer 1 firing
Post-patch results:
$ ./run ./bar
0: timer 1 firing
suspended
0: in callback 1, from domain test (1), event/detail 3/0
1: timer 1 firing
resumed
1: in callback 1, from domain test (1), event/detail 4/0
2: timer 1 firing
3: timer 1 firing
$ ./run ./bar 1
0: timer 1 firing
suspended
0: in callback 1, from domain test (1), event/detail 3/0
1: in callback 2, from domain test (1), event/detail 3/0
1: timer 1 firing
resumed
2: in callback 1, from domain test (1), event/detail 4/0
3: in callback 2, from domain test (1), event/detail 4/0
2: timer 1 firing
3: timer 1 firing
Valgrind didn't report any leaks.
* src/test/test_driver.c (testConnectOpen): Move per-connection
state initialization...
(testOpenFromFile): ...here.
(defaultConn, defaultConnections, defaultLock, testOnceInit): New
shared state.
(testOpenDefault): Only initialize on first connection.
(testConnectClose): Don't clobber state if still shared.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
I'm actually playing with moving my test out of the commit message
and into tests/objecteventtest.c; if I get that working, I'll
post a v2.
src/test/test_driver.c | 88 ++++++++++++++++++++++++++++++++++++--------------
1 file changed, 64 insertions(+), 24 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index a48404a..9696044 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1,7 +1,7 @@
/*
* test.c: A "mock" hypervisor for use by application unit tests
*
- * Copyright (C) 2006-2013 Red Hat, Inc.
+ * Copyright (C) 2006-2014 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -105,6 +105,10 @@ struct _testConn {
typedef struct _testConn testConn;
typedef struct _testConn *testConnPtr;
+static testConn defaultConn;
+static int defaultConnections;
+static virMutex defaultLock;
+
#define TEST_MODEL "i686"
#define TEST_MODEL_WORDSIZE 32
#define TEST_EMULATOR "/usr/bin/test-hv"
@@ -125,6 +129,14 @@ static int testConnectClose(virConnectPtr conn);
static void testObjectEventQueue(testConnPtr driver,
virObjectEventPtr event);
+static int
+testOnceInit(void)
+{
+ return virMutexInit(&defaultLock);
+}
+
+VIR_ONCE_GLOBAL_INIT(test)
+
static void testDriverLock(testConnPtr driver)
{
@@ -665,9 +677,15 @@ cleanup:
return ret;
}
-static int testOpenDefault(virConnectPtr conn) {
+
+/* Simultaneous test:///default connections should share the same
+ * common state (among other things, this allows testing event
+ * detection in one connection for an action caused in another). */
+static int
+testOpenDefault(virConnectPtr conn)
+{
int u;
- testConnPtr privconn;
+ testConnPtr privconn = &defaultConn;
virDomainDefPtr domdef = NULL;
virDomainObjPtr domobj = NULL;
virNetworkDefPtr netdef = NULL;
@@ -679,18 +697,26 @@ static int testOpenDefault(virConnectPtr conn) {
virNodeDeviceDefPtr nodedef = NULL;
virNodeDeviceObjPtr nodeobj = NULL;
- if (VIR_ALLOC(privconn) < 0)
- return VIR_DRV_OPEN_ERROR;
+ virMutexLock(&defaultLock);
+ if (defaultConnections++) {
+ conn->privateData = &defaultConn;
+ virMutexUnlock(&defaultLock);
+ return VIR_DRV_OPEN_SUCCESS;
+ }
+
if (virMutexInit(&privconn->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot initialize mutex"));
- VIR_FREE(privconn);
+ defaultConnections--;
+ virMutexUnlock(&defaultLock);
return VIR_DRV_OPEN_ERROR;
}
- testDriverLock(privconn);
conn->privateData = privconn;
+ if (!(privconn->domainEventState = virObjectEventStateNew()))
+ goto error;
+
if (!(privconn->domains = virDomainObjListNew()))
goto error;
@@ -791,7 +817,7 @@ static int testOpenDefault(virConnectPtr conn) {
}
virNodeDeviceObjUnlock(nodeobj);
- testDriverUnlock(privconn);
+ virMutexUnlock(&defaultLock);
return VIR_DRV_OPEN_SUCCESS;
@@ -802,10 +828,12 @@ error:
virStoragePoolObjListFree(&privconn->pools);
virNodeDeviceObjListFree(&privconn->devs);
virObjectUnref(privconn->caps);
- testDriverUnlock(privconn);
+ virObjectEventStateFree(privconn->domainEventState);
+ virMutexDestroy(&privconn->lock);
conn->privateData = NULL;
- VIR_FREE(privconn);
virDomainDefFree(domdef);
+ defaultConnections--;
+ virMutexUnlock(&defaultLock);
return VIR_DRV_OPEN_ERROR;
}
@@ -1327,6 +1355,9 @@ error:
return ret;
}
+
+/* No shared state between simultaneous test connections initialized
+ * from a file. */
static int
testOpenFromFile(virConnectPtr conn, const char *file)
{
@@ -1355,6 +1386,9 @@ testOpenFromFile(virConnectPtr conn, const char *file)
if (!(privconn->xmlopt = testBuildXMLConfig()))
goto error;
+ if (!(privconn->domainEventState = virObjectEventStateNew()))
+ goto error;
+
if (!(doc = virXMLParseFileCtxt(file, &ctxt))) {
goto error;
}
@@ -1398,6 +1432,7 @@ testOpenFromFile(virConnectPtr conn, const char *file)
virInterfaceObjListFree(&privconn->ifaces);
virStoragePoolObjListFree(&privconn->pools);
VIR_FREE(privconn->path);
+ virObjectEventStateFree(privconn->domainEventState);
testDriverUnlock(privconn);
VIR_FREE(privconn);
conn->privateData = NULL;
@@ -1410,10 +1445,12 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
unsigned int flags)
{
int ret;
- testConnPtr privconn;
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+ if (testInitialize() < 0)
+ return VIR_DRV_OPEN_ERROR;
+
if (!conn->uri)
return VIR_DRV_OPEN_DECLINED;
@@ -1442,24 +1479,24 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
if (ret != VIR_DRV_OPEN_SUCCESS)
return ret;
- privconn = conn->privateData;
- testDriverLock(privconn);
-
- privconn->domainEventState = virObjectEventStateNew();
- if (!privconn->domainEventState) {
- testDriverUnlock(privconn);
- testConnectClose(conn);
- return VIR_DRV_OPEN_ERROR;
- }
-
- testDriverUnlock(privconn);
-
return VIR_DRV_OPEN_SUCCESS;
}
static int testConnectClose(virConnectPtr conn)
{
testConnPtr privconn = conn->privateData;
+
+ if (testInitialize() < 0)
+ return -1;
+
+ if (privconn == &defaultConn) {
+ virMutexLock(&defaultLock);
+ if (--defaultConnections) {
+ virMutexUnlock(&defaultLock);
+ return 0;
+ }
+ }
+
testDriverLock(privconn);
virObjectUnref(privconn->caps);
virObjectUnref(privconn->xmlopt);
@@ -1474,7 +1511,10 @@ static int testConnectClose(virConnectPtr conn)
testDriverUnlock(privconn);
virMutexDestroy(&privconn->lock);
- VIR_FREE(privconn);
+ if (privconn == &defaultConn)
+ virMutexUnlock(&defaultLock);
+ else
+ VIR_FREE(privconn);
conn->privateData = NULL;
return 0;
}
--
1.8.4.2
10 years, 11 months
[libvirt] [PATCHv2] test: share state driver between test:///default connections
by Eric Blake
Prior to this patch, every test:/// URI has its own event manager,
which means that registering for an event can only ever receive
events from the connection where it issued the API that triggered
the event. But the whole idea of events is to be able to learn
about something where an API call did NOT trigger the action.
In order to actually test asynchronous events, I wanted to be able
to tie multiple test connections to the same state. Use of a file
in a test URI is still per-connection state, but now parallel
connections to test:///default (from the same binary, of course)
now share common state and can affect one another.
The updated testsuite fails without the rest of this patch.
Valgrind didn't report any leaks.
* src/test/test_driver.c (testConnectOpen): Move per-connection
state initialization...
(testOpenFromFile): ...here.
(defaultConn, defaultConnections, defaultLock, testOnceInit): New
shared state.
(testOpenDefault): Only initialize on first connection.
(testConnectClose): Don't clobber state if still shared.
* tests/objecteventtest.c (testDomainStartStopEvent): Enhance to
cover this.
(timeout, mymain): Ensure test fails rather than blocks.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/test/test_driver.c | 88 +++++++++++++++++++++++++++++++++++--------------
tests/objecteventtest.c | 50 ++++++++++++++++++++++++----
2 files changed, 107 insertions(+), 31 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index a48404a..9696044 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1,7 +1,7 @@
/*
* test.c: A "mock" hypervisor for use by application unit tests
*
- * Copyright (C) 2006-2013 Red Hat, Inc.
+ * Copyright (C) 2006-2014 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -105,6 +105,10 @@ struct _testConn {
typedef struct _testConn testConn;
typedef struct _testConn *testConnPtr;
+static testConn defaultConn;
+static int defaultConnections;
+static virMutex defaultLock;
+
#define TEST_MODEL "i686"
#define TEST_MODEL_WORDSIZE 32
#define TEST_EMULATOR "/usr/bin/test-hv"
@@ -125,6 +129,14 @@ static int testConnectClose(virConnectPtr conn);
static void testObjectEventQueue(testConnPtr driver,
virObjectEventPtr event);
+static int
+testOnceInit(void)
+{
+ return virMutexInit(&defaultLock);
+}
+
+VIR_ONCE_GLOBAL_INIT(test)
+
static void testDriverLock(testConnPtr driver)
{
@@ -665,9 +677,15 @@ cleanup:
return ret;
}
-static int testOpenDefault(virConnectPtr conn) {
+
+/* Simultaneous test:///default connections should share the same
+ * common state (among other things, this allows testing event
+ * detection in one connection for an action caused in another). */
+static int
+testOpenDefault(virConnectPtr conn)
+{
int u;
- testConnPtr privconn;
+ testConnPtr privconn = &defaultConn;
virDomainDefPtr domdef = NULL;
virDomainObjPtr domobj = NULL;
virNetworkDefPtr netdef = NULL;
@@ -679,18 +697,26 @@ static int testOpenDefault(virConnectPtr conn) {
virNodeDeviceDefPtr nodedef = NULL;
virNodeDeviceObjPtr nodeobj = NULL;
- if (VIR_ALLOC(privconn) < 0)
- return VIR_DRV_OPEN_ERROR;
+ virMutexLock(&defaultLock);
+ if (defaultConnections++) {
+ conn->privateData = &defaultConn;
+ virMutexUnlock(&defaultLock);
+ return VIR_DRV_OPEN_SUCCESS;
+ }
+
if (virMutexInit(&privconn->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot initialize mutex"));
- VIR_FREE(privconn);
+ defaultConnections--;
+ virMutexUnlock(&defaultLock);
return VIR_DRV_OPEN_ERROR;
}
- testDriverLock(privconn);
conn->privateData = privconn;
+ if (!(privconn->domainEventState = virObjectEventStateNew()))
+ goto error;
+
if (!(privconn->domains = virDomainObjListNew()))
goto error;
@@ -791,7 +817,7 @@ static int testOpenDefault(virConnectPtr conn) {
}
virNodeDeviceObjUnlock(nodeobj);
- testDriverUnlock(privconn);
+ virMutexUnlock(&defaultLock);
return VIR_DRV_OPEN_SUCCESS;
@@ -802,10 +828,12 @@ error:
virStoragePoolObjListFree(&privconn->pools);
virNodeDeviceObjListFree(&privconn->devs);
virObjectUnref(privconn->caps);
- testDriverUnlock(privconn);
+ virObjectEventStateFree(privconn->domainEventState);
+ virMutexDestroy(&privconn->lock);
conn->privateData = NULL;
- VIR_FREE(privconn);
virDomainDefFree(domdef);
+ defaultConnections--;
+ virMutexUnlock(&defaultLock);
return VIR_DRV_OPEN_ERROR;
}
@@ -1327,6 +1355,9 @@ error:
return ret;
}
+
+/* No shared state between simultaneous test connections initialized
+ * from a file. */
static int
testOpenFromFile(virConnectPtr conn, const char *file)
{
@@ -1355,6 +1386,9 @@ testOpenFromFile(virConnectPtr conn, const char *file)
if (!(privconn->xmlopt = testBuildXMLConfig()))
goto error;
+ if (!(privconn->domainEventState = virObjectEventStateNew()))
+ goto error;
+
if (!(doc = virXMLParseFileCtxt(file, &ctxt))) {
goto error;
}
@@ -1398,6 +1432,7 @@ testOpenFromFile(virConnectPtr conn, const char *file)
virInterfaceObjListFree(&privconn->ifaces);
virStoragePoolObjListFree(&privconn->pools);
VIR_FREE(privconn->path);
+ virObjectEventStateFree(privconn->domainEventState);
testDriverUnlock(privconn);
VIR_FREE(privconn);
conn->privateData = NULL;
@@ -1410,10 +1445,12 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
unsigned int flags)
{
int ret;
- testConnPtr privconn;
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+ if (testInitialize() < 0)
+ return VIR_DRV_OPEN_ERROR;
+
if (!conn->uri)
return VIR_DRV_OPEN_DECLINED;
@@ -1442,24 +1479,24 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
if (ret != VIR_DRV_OPEN_SUCCESS)
return ret;
- privconn = conn->privateData;
- testDriverLock(privconn);
-
- privconn->domainEventState = virObjectEventStateNew();
- if (!privconn->domainEventState) {
- testDriverUnlock(privconn);
- testConnectClose(conn);
- return VIR_DRV_OPEN_ERROR;
- }
-
- testDriverUnlock(privconn);
-
return VIR_DRV_OPEN_SUCCESS;
}
static int testConnectClose(virConnectPtr conn)
{
testConnPtr privconn = conn->privateData;
+
+ if (testInitialize() < 0)
+ return -1;
+
+ if (privconn == &defaultConn) {
+ virMutexLock(&defaultLock);
+ if (--defaultConnections) {
+ virMutexUnlock(&defaultLock);
+ return 0;
+ }
+ }
+
testDriverLock(privconn);
virObjectUnref(privconn->caps);
virObjectUnref(privconn->xmlopt);
@@ -1474,7 +1511,10 @@ static int testConnectClose(virConnectPtr conn)
testDriverUnlock(privconn);
virMutexDestroy(&privconn->lock);
- VIR_FREE(privconn);
+ if (privconn == &defaultConn)
+ virMutexUnlock(&defaultLock);
+ else
+ VIR_FREE(privconn);
conn->privateData = NULL;
return 0;
}
diff --git a/tests/objecteventtest.c b/tests/objecteventtest.c
index ae29792..1f43070 100644
--- a/tests/objecteventtest.c
+++ b/tests/objecteventtest.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2014 Red Hat, Inc.
* Copyright (C) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* This library is free software; you can redistribute it and/or
@@ -220,8 +221,10 @@ testDomainStartStopEvent(const void *data)
lifecycleEventCounter counter;
int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
int id;
- int ret = 0;
+ int ret = -1;
virDomainPtr dom;
+ virConnectPtr conn2 = NULL;
+ virDomainPtr dom2 = NULL;
lifecycleEventCounter_reset(&counter);
@@ -237,20 +240,40 @@ testDomainStartStopEvent(const void *data)
virDomainDestroy(dom);
virDomainCreate(dom);
- if (virEventRunDefaultImpl() < 0) {
- ret = -1;
+ if (virEventRunDefaultImpl() < 0)
goto cleanup;
- }
if (counter.startEvents != 1 || counter.stopEvents != 1 ||
- counter.unexpectedEvents > 0) {
- ret = -1;
+ counter.unexpectedEvents > 0)
+ goto cleanup;
+
+ /* Repeat the test, but this time, trigger the events via an
+ * alternate connection. */
+ if (!(conn2 = virConnectOpen("test:///default")))
+ goto cleanup;
+ if (!(dom2 = virDomainLookupByName(conn2, "test")))
goto cleanup;
- }
+ if (virDomainDestroy(dom2) < 0)
+ goto cleanup;
+ if (virDomainCreate(dom2) < 0)
+ goto cleanup;
+
+ if (virEventRunDefaultImpl() < 0)
+ goto cleanup;
+
+ if (counter.startEvents != 2 || counter.stopEvents != 2 ||
+ counter.unexpectedEvents > 0)
+ goto cleanup;
+
+ ret = 0;
cleanup:
virConnectDomainEventDeregisterAny(test->conn, id);
virDomainFree(dom);
+ if (dom2)
+ virDomainFree(dom2);
+ if (conn2)
+ virConnectClose(conn2);
return ret;
}
@@ -374,14 +397,26 @@ cleanup:
return ret;
}
+static void
+timeout(int id ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
+{
+ fputs("test taking too long; giving up", stderr);
+ exit(EXIT_FAILURE);
+}
+
static int
mymain(void)
{
objecteventTest test;
int ret = EXIT_SUCCESS;
+ int timer;
virEventRegisterDefaultImpl();
+ /* Set up a timer to abort this test if it takes 10 seconds. */
+ if ((timer = virEventAddTimeout(10 * 1000, timeout, NULL, NULL)) < 0)
+ return EXIT_FAILURE;
+
if (!(test.conn = virConnectOpen("test:///default")))
return EXIT_FAILURE;
@@ -411,6 +446,7 @@ mymain(void)
virNetworkUndefine(test.net);
virNetworkFree(test.net);
virConnectClose(test.conn);
+ virEventRemoveTimeout(timer);
return ret;
}
--
1.8.4.2
10 years, 11 months
[libvirt] [PATCH 1/3] tests: virnetsockettest: Print the error if getifaddrs fails.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
---
tests/virnetsockettest.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c
index eda95bc..82c202e 100644
--- a/tests/virnetsockettest.c
+++ b/tests/virnetsockettest.c
@@ -60,8 +60,10 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6,
*hasIPv4 = *hasIPv6 = false;
*freePort = 0;
- if (getifaddrs(&ifaddr) < 0)
+ if (getifaddrs(&ifaddr) < 0) {
+ perror ("getifaddrs");
goto cleanup;
+ }
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (!ifa->ifa_addr)
--
1.8.3.1
10 years, 11 months
[libvirt] FYI: aarch64 test suite failures
by Richard W.M. Jones
Libvirt compiles fine on aarch64. You will need to configure with
--without-dtrace as systemtap tracepoints are pretty broken, giving
lots of strange compile-time errors/link failures in both libvirt and qemu.
The test suite fails, see attachment.
Note this is all running under qemu-arm64 userspace emulation[1], so
certain things are expected to be a bit different.
In particular, any aarch64 binary which the test suite runs is
actually run under the qemu-arm64 interpreter (using binfmt). I'm
guessing this explains the extra file descriptor in some tests.
Also qemu intercepts system calls and thunks them into host system
calls (an x86-64 host in this case), and its support for IPv6 seems
shaky at best.
Rich.
[1] http://rwmj.wordpress.com/2013/12/22/how-to-run-aarch64-binaries-on-an-x8...
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
10 years, 11 months
[libvirt] [PATCH] aarch64: Disable -fstack-protector.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
I'm using gcc-4.8.2-7.fc21.aarch64 which does not appear to support
this option.
---
m4/virt-compile-warnings.m4 | 3 +++
1 file changed, 3 insertions(+)
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 1547e03..574fbc4 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -163,6 +163,9 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
dnl -fstack-protector stuff passes gl_WARN_ADD with gcc
dnl on Mingw32, but fails when actually used
case $host in
+ aarch64-*-*)
+ dnl "error: -fstack-protector not supported for this target [-Werror]"
+ ;;
*-*-linux*)
dnl Fedora only uses -fstack-protector, but doesn't seem to
dnl be great overhead in adding -fstack-protector-all instead
--
1.8.3.1
10 years, 11 months
[libvirt] Build failed in Jenkins: libvirt-syntax-check #1804
by Jenkins CI
See <http://honk.sigxcpu.org:8001/job/libvirt-syntax-check/1804/>
------------------------------------------
Started by upstream project "libvirt-build" build number 2013
Building on master in workspace <http://honk.sigxcpu.org:8001/job/libvirt-syntax-check/ws/>
[workspace] $ /bin/sh -xe /tmp/hudson1250971132809350241.sh
+ make syntax-check
GEN bracket-spacing-check
GFDL_version
0.53 GFDL_version
TAB_in_indentation
0.41 TAB_in_indentation
Wundef_boolean
0.21 Wundef_boolean
avoid_attribute_unused_in_header
0.25 avoid_attribute_unused_in_header
avoid_ctype_macros
0.64 avoid_ctype_macros
avoid_if_before_free
8.01 avoid_if_before_free
avoid_strcase
0.81 avoid_strcase
avoid_write
0.55 avoid_write
bindtextdomain
0.50 bindtextdomain
cast_of_argument_to_free
1.37 cast_of_argument_to_free
cast_of_x_alloc_return_value
1.22 cast_of_x_alloc_return_value
changelog
0.22 changelog
const_long_option
0.67 const_long_option
copyright_check
./.gnulib/lib/version-etc.c
maint.mk: out of date copyright in ./.gnulib/lib/version-etc.c; update it
make: *** [sc_copyright_check] Error 1
Build step 'Execute shell' marked build as failure
10 years, 11 months
[libvirt] [PATCH] maint: update to latest gnulib
by Eric Blake
'make syntax-check' wants a newer gnulib for 2014 copyright.
Also, a couple of fixes for bootstrap issues reported on IRC:
- on some older glibc systems, ./configure could deadlock due to
a glibc malloc bug
- on FreeBSD systems, a broken autom4te coupled with gettext
0.18.3 prevents bootstrap; we can't work around it, but can at
least inform the user why they have a problem
And as always, portability fixes in other modules, some of which
are used by libvirt.
* .gnulib: Update to latest, in part for bootstrap improvements,
and for the new year.
* bootstrap: Resync to gnulib.
* gnulib/local/m4/ssize_t.m4.diff: Regenerate.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
Pushing under the build-breaker rule now that 'make syntax-check'
is impacted.
* .gnulib 831b84c...c7802e2 (33):
> doc: update main copyright year
> maint: update copyright
> version-etc: new year
> autoupdate
> passfd: give nicer error for recvfd at eof
> autoupdate
> gettimeofday: port recent C++ fix to Emacs
> gettimeofday: fix C++ crosscompilation
> qacl: port to Windows better
> md5, sha1, sha256, sha512: fix compile error in c++ mode
> open-tests: fix build failure with -Werror=old-style-declaration
> md5, sha1, sha256, sha512: fix link error with partial libcrypto
> md5, sha1, sha256, sha512: add gl_SET_CRYPTO_CHECK_DEFAULT
> md5, sha1, sha256, sha512: add 'auto', and a way to specify default
> autoupdate
> bootstrap: warn about BSD toolchain snafu
> open-tests: port to glibc with _FORTIFY_SOURCE and -O1
> include_next: minimize code duplication
> getcwd: fix compile error in configure check
> regex: suppress core dumps from detection code
> md5, sha1, sha256, sha512: support mandating use of openssl
> test-xvasprintf: disable some -Wformat-security diagnostics
> regex: avoid glibc deadlock during configure
> md5, sha1, sha256, sha512: use openssl routines if available
> base64: fix recent compilation regression on some compilers
> autoupdate
> autoupdate
> ignore-value: revert previous code change
> selinux-h: improve stub types and add more stub functions
> ignore-value: prefer GCC version back through 2.0
> pty: Activate the signature wrapper of forkpty.
> maint: fix gendocs.sh permissions
> autoupdate
.gnulib | 2 +-
bootstrap | 12 ++++++++++--
gnulib/local/m4/ssize_t.m4.diff | 2 +-
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/.gnulib b/.gnulib
index 831b84c..1276a2c 160000
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit 831b84c59ef413c57a36b67344467d66a8a2ba70
+Subproject commit 1276a2c5f24c0c932426aca9c899fa524d2443f2
diff --git a/bootstrap b/bootstrap
index e31d17d..ce90bc4 100755
--- a/bootstrap
+++ b/bootstrap
@@ -1,10 +1,10 @@
#! /bin/sh
# Print a version string.
-scriptversion=2013-08-15.22; # UTC
+scriptversion=2013-12-05.23; # UTC
# Bootstrap this package from checked-out sources.
-# Copyright (C) 2003-2013 Free Software Foundation, Inc.
+# Copyright (C) 2003-2014 Free Software Foundation, 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
@@ -551,6 +551,14 @@ if ! printf "$buildreq" | check_versions; then
fi
fi
+# Warn the user if autom4te appears to be broken; this causes known
+# issues with at least gettext 0.18.3.
+probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
+if test "x$probe" != xhi; then
+ warn_ "WARNING: your autom4te wrapper eats stdin;"
+ warn_ "if bootstrap fails, consider upgrading your autotools"
+fi
+
echo "$0: Bootstrapping from checked-out $package sources..."
# See if we can use gnulib's git-merge-changelog merge driver.
diff --git a/gnulib/local/m4/ssize_t.m4.diff b/gnulib/local/m4/ssize_t.m4.diff
index 93f8ad7..08c2b9c 100644
--- a/gnulib/local/m4/ssize_t.m4.diff
+++ b/gnulib/local/m4/ssize_t.m4.diff
@@ -5,7 +5,7 @@ index 209d64c..5ea72a1 100644
@@ -1,4 +1,4 @@
-# ssize_t.m4 serial 5 (gettext-0.18.2)
+# ssize_t.m4 serial 6 (gettext-0.18.2)
- dnl Copyright (C) 2001-2003, 2006, 2010-2013 Free Software Foundation, Inc.
+ dnl Copyright (C) 2001-2003, 2006, 2010-2014 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -17,7 +17,21 @@ AC_DEFUN([gt_TYPE_SSIZE_T],
--
1.8.4.2
10 years, 11 months