Re: [libvirt] RE: Libvirt - Xen Enterprise - Koan

2009-01-09 Thread Ben Guthro
One thing to know about the open source xend XenAPI - it does not come
configured by default. you must enable it in the xend_config.sxp file

If I recall my brief foray into the open source XenAPI - it uses the
same transport mechanisms, but the open source one is not ver heavily
tested, and just plain broken in some versions of xen (especially for
HVM guests)

However, you might be able to share some code under these two paths

Daniel P. Berrange wrote on 01/09/2009 10:30 AM:
 On Fri, Jan 09, 2009 at 03:18:36PM +, Richard W.M. Jones wrote:
   
 On Thu, Jan 08, 2009 at 12:53:51PM -, 
 gerhardus.geldenh...@gta-travel.com wrote:
 
* libxenserver: The XenServer C SDK
   
 [..]
 
 All this can be downloaded from CDN at
 http://community.citrix.com/display/xs/Download+SDKs
   
 I took a look at the C library:

 * It's LGPLv2+, so there is no license issue that I can see with
 linking it to libvirt.

 * It presents each XenServer API call as a C function.  Each C
 function constructs an XML document (XMLRPC, I think), dispatches it
 to the server, gets the reply, and unpacks the resulting XML.

 * Uses libxml2 to do the XML construction and parsing.

 * You have to supply your own HTTP library to pass the data to the
 server.  The examples use libcurl for this.

 * Compiles with -Wall -Werror without warnings or errors.

 It seems reasonably sensible.  It still requires the proprietary
 XenEnterprise to be installed for testing of course.
 

 It is possible that it might work with the XenAPI impl in the open
 source XenD  too - worth a try if you want to develop something

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


Re: [libvirt] RE: Libvirt - Xen Enterprise - Koan

2009-01-07 Thread Ben Guthro
FYI - The XenAPI has some similarities with XenEnterprise's API - but
they forked away from the open source model a while ago.

I agree with you that the XenAPI list is mostly dead. I haven't seem
anyone contributing to it in a while...


Daniel Veillard wrote on 01/07/2009 07:20 AM:
 On Wed, Jan 07, 2009 at 09:55:18AM +0900, Atsushi SAKAI wrote:
   
 Hello,

   Just one question.
   How about using XenAPI for XenEnterprise?
 I am not familiar with XenEnterprise.
 But It should have some API for a developer.
 

  Well the public XenAPI list seems mostly dead but
 there are reports of incompatibilities between their
 proprietary and old open sounce versions. Check the
 archives, it doesn't look good.

 Daniel

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


Re: [libvirt] Deploying latest libvirt in rhel / centos 5.2

2008-12-09 Thread Ben Guthro
You shouldn't have any issues.

There is a 'make rpm' target at the top level that I use to build
updated packages in RHEL.
Take a look at the top of the .spec.in file for build dependencies

Marco Sinhoreli wrote on 12/09/2008 08:00 AM:
 Hello all,

 I'm wanting to know if I will have some difficulty to package libvirt
 0.5.x to rhel / centos 5.2. I'm needing of the latest libvirt release
 to tests with oVirt.

 Regards,

   

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


RE: [libvirt] F10 rpm problems

2008-12-08 Thread Ben Guthro

I do have older versions (for chroot purposes) mounted in non-standard paths...
I don't know why it would pick it up in /data:

$ locate libgnutls.so.13
/data/f9root/usr/lib64/libgnutls.so.13
/data/f9root/usr/lib64/libgnutls.so.13.9.1


The strange part is, that it looks like it is linking against both versions:

$ ldd .libs/virsh
linux-vdso.so.1 =  (0x7fff633ff000)
libvirt.so.0 = /usr/lib/libvirt.so.0 (0x00382da0)
libxml2.so.2 = /usr/lib64/libxml2.so.2 (0x003cf2a0)
libselinux.so.1 = /lib64/libselinux.so.1 (0x003ce920)
libgnutls.so.26 = /usr/lib64/libgnutls.so.26 (0x003cff60)
libsasl2.so.2 = /usr/lib64/libsasl2.so.2 (0x003cf960)
libxenstore.so.3.0 = /usr/lib64/libxenstore.so.3.0 (0x0011)
libreadline.so.5 = /lib64/libreadline.so.5 (0x003ce720)
libpthread.so.0 = /lib64/libpthread.so.0 (0x003ce8a0)
libc.so.6 = /lib64/libc.so.6 (0x003ce7e0)
libgnutls.so.13 = not found
libhal.so.1 = /usr/lib64/libhal.so.1 (0x003cf600)
libdbus-1.so.3 = /lib64/libdbus-1.so.3 (0x0061e000)
libdl.so.2 = /lib64/libdl.so.2 (0x003ce860)
libz.so.1 = /lib64/libz.so.1 (0x003ce8e0)
libm.so.6 = /lib64/libm.so.6 (0x003ce820)
/lib64/ld-linux-x86-64.so.2 (0x003ce6a0)
libtasn1.so.3 = /usr/lib64/libtasn1.so.3 (0x003cfee0)
libgcrypt.so.11 = /lib64/libgcrypt.so.11 (0x003cfb60)
libgpg-error.so.0 = /lib64/libgpg-error.so.0 (0x003cf8e0)
libresolv.so.2 = /lib64/libresolv.so.2 (0x003cefa0)
libcrypt.so.1 = /lib64/libcrypt.so.1 (0x003cf7c0)
libtinfo.so.5 = /lib64/libtinfo.so.5 (0x003cf6c0)
libcap.so.2 = /lib64/libcap.so.2 (0x003ce6e0)


I take it that this situation is unique to my setup, and not F10?


-Original Message-
From: Daniel Veillard [mailto:[EMAIL PROTECTED]
Sent: Mon 12/8/2008 5:39 AM
To: Ben Guthro
Cc: libvir-list
Subject: Re: [libvirt] F10 rpm problems
 
On Fri, Dec 05, 2008 at 03:24:31PM -0500, Ben Guthro wrote:
 So...I decided to make the leap, and upgraded to F10 (from F9)
 
 After my upgrade, I decided to build the libvirt rpm from source, and install 
 it.
 So far, so good...everything built, and installs nicely.
 
 However, when I run virsh, I get the following error:
 virsh: error while loading shared libraries: libgnutls.so.13: cannot open 
 shared object file: No such file or directory
 
 Fedora 10 has /usr/lib/libgnutls.so.26, so I'm not real sure why it is 
 looking for the old F9 versions.
 
 I have tried a make clean, make distclean, even re-cloning the repo...without 
 effect.
 
 Does anyone have any thoughts as to why it is choosing this version of gnutls?

  You don't have an one laying around in /usr/local which would be
picked up by the linker, but not caught by ldconfig ?

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
[EMAIL PROTECTED]  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

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


RE: [libvirt] how to install updated python bindings

2008-12-05 Thread Ben Guthro
Visco - 

FYI - You should be able to build a custom rpm via 

'make rpm'


-Original Message-
From: [EMAIL PROTECTED] on behalf of visco
Sent: Fri 12/5/2008 1:05 AM
To: Daniel P. Berrange; [EMAIL PROTECTED]
Cc: libvir-list@redhat.com
Subject: Re: [libvirt] how to install updated python bindings
 
hi

thanks Berrange ...
after installing python development packages and setting the variables i am
able to work out the trouble.

@Veillard
unfortunately i required some latest version,which is not provided yet as
rpm, api for my needs,  and hence started from source.

On Wed, Dec 3, 2008 at 5:31 PM, Daniel Veillard [EMAIL PROTECTED] wrote:

 On Wed, Dec 03, 2008 at 09:40:55AM +, Daniel P. Berrange wrote:
  On Wed, Dec 03, 2008 at 12:44:17AM -0500, ente linux wrote:
   hi
  
   i was trying to install libvirt 0.5 on my centos 5 machine which by
 default
   have libvirt 0.4. But after installing from the source of libvirt,
 still the
   output of i get from python remains that of 0.4
   import libvirt
libvirt.getVersion()
   4006
  
   how could i install the new version... Do i need to give  any option
 while
   configuring or making.
 
  If installing manually, configure will default to putting it in
 /usr/local
  unless you give a different --prefix option.
 
  Python only looks in /usr by default, so when installing custom builds
  you'll need to set
 
 export LD_LIBRARY_PATH=/usr/local/lib
 export PYTHONPATH=/usr/local/lib/python2.4/site-packages

   in general in an rpm based system it's best to upgrade at the rpm
  level in my opinion, that avoids a lot of troubles, and it's possible
  to go back without leftovers from previous attemps left and right...

 Daniel

 --
 Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
 [EMAIL PROTECTED]  | Rpmfind RPM search engine http://rpmfind.net/
 http://veillard.com/ | virtualization library  http://libvirt.org/




-- 
thanks and regards
visco

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


[libvirt] F10 rpm problems

2008-12-05 Thread Ben Guthro
So...I decided to make the leap, and upgraded to F10 (from F9)

After my upgrade, I decided to build the libvirt rpm from source, and install 
it.
So far, so good...everything built, and installs nicely.

However, when I run virsh, I get the following error:
virsh: error while loading shared libraries: libgnutls.so.13: cannot open 
shared object file: No such file or directory

Fedora 10 has /usr/lib/libgnutls.so.26, so I'm not real sure why it is looking 
for the old F9 versions.

I have tried a make clean, make distclean, even re-cloning the repo...without 
effect.

Does anyone have any thoughts as to why it is choosing this version of gnutls?



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


RE: [libvirt] [PATCH] post-release patch for symbols

2008-12-02 Thread Ben Guthro
If I understood the previous conversation correctly, these thread-safe changes 
are necessary for the Java bindings DomainEvent code.

Do we really want those bindings to fall that far behind?


-Original Message-
From: [EMAIL PROTECTED] on behalf of Daniel Veillard
Sent: Tue 12/2/2008 5:30 AM
To: libvir-list@redhat.com
Subject: [libvirt] [PATCH] post-release patch for symbols
 
  Assuming we release a 0.5.1 soon. Maybe the code with threading
should be on a 0.6.0 considering the amount of changes though.

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
[EMAIL PROTECTED]  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

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


Re: [libvirt] PATCH: 25/28: Thread safety for libvirtd event loop

2008-12-01 Thread Ben Guthro
please disregard this email...user error.

Ben Guthro wrote on 12/01/2008 10:06 AM:
 Is patch 24/25 missing?
 
 I tried
 git branch thread-safe b726fa0fa5a91eee0af2f996c784d13593cd7616
 git checkout thread-safe
 git am --interactive /home/bguthro/.thunderbird/tiloddj9.default/Mail/Local\ 
 Folders/thread-safe
 
 and got through most of these, but it seemed to fail on patch 25:
 
 ...
 Applying PATCH: 22/28: Refactor libvirtd RPC call dispatcher
 Applying PATCH: 23/28: Replace client linked list with array
 Applying PATCH: 25/28: Thread safety for libvirtd event loop
 .dotest/patch:372: trailing whitespace.
  *
 .dotest/patch:388: trailing whitespace.
  * return -1 if wakup failed
 error: patch failed: qemud/qemud.h:177
 error: qemud/qemud.h: patch does not apply
 Patch failed at 0024.
 When you have resolved this problem run git-am --resolved.
 

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


Re: [libvirt] PATCH: 0/28: Thread safety for libvirtd daemon and drivers

2008-12-01 Thread Ben Guthro
What git changeset does this queue apply against?

I'm having a heck of a time getting it to apply cleanly with git-am.

alternately:
I know you work on occasion with mercurial. Is this an mq tree somewhere?


Daniel P. Berrange wrote on 11/30/2008 06:14 PM:
 The following huge series of patches adds thread safety for the libvirtd
 daemon and drivers, and makes the daemon multi-threaded in processing
 RPC calls. This enables multiple clients to be processed in parallel, 
 without blocking each other. It does not change the thread rules for the
 virConnectPtr object though, so each individual client is still serialized.
 
 There are two core places where we have to have synchronization in the
 threading model this patch series introduces
 
  - The libvirt daemon code 
- A single global server lock (aka struct qemud_server)
- One lock per client connection  (aka struct qemud_client)
 
  - The driver implementations
- One lock per driver (aka QEMU, LXC, Test, UML, OpenVZ, Network,
  Storage, Node Devices)
- One lock per primary object in a driver (virDomainObjPtr,
  virNetworkObjPtr, virStoragePoolObjPtr, virNodeDeviceObjptr
  instances)
 
 For most cases, the big global server / driver locks are only held while
 obtaining one of the finer grained locks. This gives a fairly good level
 of concurrency for operations touching different objects. Once this core
 infrastructure is merged, it will be possible to iterate on impl of
 drivers to reduce the time locks are held - eg avoid holding a lock while
 talking to the QEMU monitor interface.
 
 To try and make it easier to spot thread locking problems this series
 refactors alot of methods so that there is only a single return point
 where the unlock call can be placed, rather than multiple return point
 which increases the chances of missing an unlock call.
 
 This touches a huge amount of code, so I'd like to get this all merged 
 ASAP as it'll be really hard to keep it synced with ongoing changes.
 
 Daniel

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


Re: [libvirt] [PATCH] fix --without-xen build

2008-11-24 Thread Ben Guthro
This fixed it in our environment

ACK

Daniel P. Berrange wrote on 11/24/2008 10:50 AM:
 On Fri, Nov 21, 2008 at 12:46:59PM -0500, David Lively wrote:
 Okay, *this* one seems to be a complete fix.
 
 Not quite. The ENABLE_XEN_TESTS conditional is only set when not
 running on a live Xen kernel, which is a different conditional
 from disabling Xen driver entirely. It also shouldn't skip out
 sub-directories because we need 'make dist' to include them even
 when Xen build is disabled.
 
 Try out this patch which should do what you were after. It also removes
 some pointless conditionals from the source files - we don't need WITH_XEN
 in the source, if we're disabling the build entirely in the Makefile.am
 
 
 Index: tests/Makefile.am
 ===
 RCS file: /data/cvs/libvirt/tests/Makefile.am,v
 retrieving revision 1.59
 diff -u -p -r1.59 Makefile.am
 --- tests/Makefile.am 24 Nov 2008 07:13:30 -  1.59
 +++ tests/Makefile.am 24 Nov 2008 15:47:46 -
 @@ -43,10 +43,13 @@ EXTRA_DIST =  \
   nodeinfodata \
   domainschematest
  
 -noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \
 - reconnect xmconfigtest xencapstest \
 +noinst_PROGRAMS = xmlrpctest virshtest conftest \
  nodeinfotest statstest qparamtest
  
 +if WITH_XEN
 +noinst_PROGRAMS += xml2sexprtest sexpr2xmltest \
 + reconnect xmconfigtest xencapstest
 +endif
  if WITH_QEMU
  noinst_PROGRAMS += qemuxml2argvtest qemuxml2xmltest
  endif
 @@ -68,12 +71,22 @@ endif
  
  EXTRA_DIST += $(test_scripts)
  
 -TESTS = xml2sexprtest sexpr2xmltest virshtest xmconfigtest \
 -xencapstest nodeinfotest \
 - statstest qparamtest $(test_scripts)
 +TESTS = virshtest \
 +nodeinfotest \
 + statstest \
 + qparamtest \
 + $(test_scripts)
 +
 +if WITH_XEN
 +TESTS += xml2sexprtest \
 + sexpr2xmltest \
 + xmconfigtest \
 + xencapstest
  if ENABLE_XEN_TESTS
 -  TESTS += reconnect
 +TESTS += reconnect
 +endif
  endif
 +
  if WITH_QEMU
  TESTS += qemuxml2argvtest qemuxml2xmltest
  endif
 @@ -105,6 +118,7 @@ xmlrpctest_SOURCES = \
  
  xmlrpctest_LDADD = $(LDADDS)
  
 +if WITH_XEN
  xml2sexprtest_SOURCES = \
   xml2sexprtest.c testutilsxen.c testutilsxen.h \
   testutils.c testutils.h
 @@ -120,6 +134,20 @@ xmconfigtest_SOURCES = \
   testutils.c testutils.h
  xmconfigtest_LDADD = ../src/libvirt_driver_xen.la $(LDADDS)
  
 +xencapstest_SOURCES = \
 + xencapstest.c testutils.h testutils.c
 +xencapstest_LDADD = ../src/libvirt_driver_xen.la $(LDADDS)
 +
 +reconnect_SOURCES = \
 + reconnect.c
 +reconnect_LDADD = $(LDADDS)
 +
 +else
 +EXTRA_DIST += xml2sexprtest.c sexpr2xmltest.c xmconfigtest.c \
 + xencapstest.c reconnect.c \
 + testutilsxen.c testutilsxen.h
 +endif
 +
  if WITH_QEMU
  qemuxml2argvtest_SOURCES = \
   qemuxml2argvtest.c testutilsqemu.c testutilsqemu.h \
 @@ -143,10 +171,6 @@ conftest_SOURCES = \
   conftest.c
  conftest_LDADD = $(LDADDS)
  
 -xencapstest_SOURCES = \
 - xencapstest.c testutils.h testutils.c
 -xencapstest_LDADD = ../src/libvirt_driver_xen.la $(LDADDS)
 -
  nodeinfotest_SOURCES = \
   nodeinfotest.c testutils.h testutils.c
  nodeinfotest_LDADD = $(LDADDS)
 @@ -159,8 +183,4 @@ qparamtest_SOURCES = \
   qparamtest.c testutils.h testutils.c
  qparamtest_LDADD = $(LDADDS)
  
 -reconnect_SOURCES = \
 - reconnect.c
 -reconnect_LDADD = $(LDADDS)
 -
  CLEANFILES = *.cov *.gcov .libs/*.gcda .libs/*.gcno *.gcno *.gcda
 Index: tests/sexpr2xmltest.c
 ===
 RCS file: /data/cvs/libvirt/tests/sexpr2xmltest.c,v
 retrieving revision 1.32
 diff -u -p -r1.32 sexpr2xmltest.c
 --- tests/sexpr2xmltest.c 9 Sep 2008 13:53:58 -   1.32
 +++ tests/sexpr2xmltest.c 24 Nov 2008 15:47:46 -
 @@ -4,8 +4,6 @@
  #include string.h
  #include unistd.h
  
 -#ifdef WITH_XEN
 -
  #include internal.h
  #include xml.h
  #include xend_internal.h
 @@ -146,11 +144,3 @@ mymain(int argc, char **argv)
  
  VIRT_TEST_MAIN(mymain)
  
 -#else /* WITHOUT_XEN */
 -int
 -main(void)
 -{
 -fprintf(stderr, libvirt compiled without Xen support\n);
 -return(0);
 -}
 -#endif /* WITH_XEN */
 Index: tests/testutilsxen.c
 ===
 RCS file: /data/cvs/libvirt/tests/testutilsxen.c,v
 retrieving revision 1.2
 diff -u -p -r1.2 testutilsxen.c
 --- tests/testutilsxen.c  12 Aug 2008 08:25:48 -  1.2
 +++ tests/testutilsxen.c  24 Nov 2008 15:47:46 -
 @@ -1,6 +1,5 @@
  #include config.h
  
 -#ifdef WITH_XEN
  #include sys/utsname.h
  #include stdlib.h
  
 @@ -52,4 +51,3 @@ cleanup:
  virCapabilitiesFree(caps);
  return NULL;
  }
 -#endif
 Index: tests/xencapstest.c
 ===
 RCS file: /data/cvs/libvirt/tests/xencapstest.c,v
 retrieving revision 1.15
 diff -u -p -r1.15 

RE: [libvirt] --with-xen=foo

2008-11-21 Thread Ben Guthro

Oh - sorry for not getting back to you about this.
Yes - it does solve it for me.

+1

-Original Message-
From: Daniel P. Berrange [mailto:[EMAIL PROTECTED]
Sent: Fri 11/21/2008 5:12 AM
To: Ben Guthro
Cc: libvir-list
Subject: Re: [libvirt] --with-xen=foo
 
On Thu, Nov 20, 2008 at 06:30:38PM +, Daniel P. Berrange wrote:
 On Thu, Nov 20, 2008 at 01:27:40PM -0500, Ben Guthro wrote:
  I tried this...didn't seem to help:
 
 Sorry, not paying close enough attention. In fact this file was
 built in an earlier module. Find the line which says
 
 libvirt_driver_la_SOURCES = \
 $(DRIVER_SOURCES)   \
 $(DOMAIN_CONF_SOURCES)  \
 $(NETWORK_CONF_SOURCES) \
 $(STORAGE_CONF_SOURCES) \
 $(NODE_DEVICE_CONF_SOURCES)
 
 And add in a line following that
 
 libvirt_driver_la_CFLAGS = $(XEN_CFLAGS)

On the assumption that this fixed it for you, I've committed this change

Regards,
Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] --with-xen=foo

2008-11-21 Thread Ben Guthro
hmm...It looks like this is not the only problem.

If I do a clean build with the following options:
./autogen.sh --enable-compile-warnings=error \
 --with-xen \ 
 --without-uml \  
 --with-storage-disk \
 --with-storage-iscsi \   
 --prefix=/usr

I get an error when building testutilsxen.c

gcc -DHAVE_CONFIG_H -I. -I.. -I../gnulib/lib -I../gnulib/lib -I../include 
-I../src -I../include -I../src -I/usr/include/libxml2  
-DGETTEXT_PACKAGE=\libvirt\  -Wall -Wformat -Wformat-security 
-Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wextra -Wshadow 
-Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Winline 
-Wredundant-decls -Wno-sign-compare -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fasynchronous-unwind-tables  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 
-fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic 
-MT testutilsxen.o -MD -MP -MF .deps/testutilsxen.Tpo -c -o testutilsxen.o 
testutilsxen.c
make[4]: *** No rule to make target `../src/libvirt_driver_xen.la', needed by 
`xml2sexprtest'.  Stop.


...it would appear that some dependency is incorrect...


Ben Guthro wrote on 11/21/2008 06:52 AM:
 
 Oh - sorry for not getting back to you about this.
 Yes - it does solve it for me.
 
 +1
 
 -Original Message-
 From: Daniel P. Berrange [mailto:[EMAIL PROTECTED]
 Sent: Fri 11/21/2008 5:12 AM
 To: Ben Guthro
 Cc: libvir-list
 Subject: Re: [libvirt] --with-xen=foo
 
 On Thu, Nov 20, 2008 at 06:30:38PM +, Daniel P. Berrange wrote:
 On Thu, Nov 20, 2008 at 01:27:40PM -0500, Ben Guthro wrote:
  I tried this...didn't seem to help:

 Sorry, not paying close enough attention. In fact this file was
 built in an earlier module. Find the line which says

 libvirt_driver_la_SOURCES = \
 $(DRIVER_SOURCES)   \
 $(DOMAIN_CONF_SOURCES)  \
 $(NETWORK_CONF_SOURCES) \
 $(STORAGE_CONF_SOURCES) \
 $(NODE_DEVICE_CONF_SOURCES)

 And add in a line following that

 libvirt_driver_la_CFLAGS = $(XEN_CFLAGS)
 
 On the assumption that this fixed it for you, I've committed this change
 
 Regards,
 Daniel
 --
 |: Red Hat, Engineering, London   -o-  
 http://people.redhat.com/berrange/ :|
 |: http://libvirt.org  -o-  http://virt-manager.org  -o- 
 http://ovirt.org :|
 |: http://autobuild.org   -o-
 http://search.cpan.org/~danberr/ :|
 |: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B
 9505 :|
 
 
 
 
 --
 Libvir-list mailing list
 Libvir-list@redhat.com
 https://www.redhat.com/mailman/listinfo/libvir-list

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


Re: [libvirt] [PATCH] Xen Events Updated

2008-11-21 Thread Ben Guthro
I tested these changes, and seem to be having some issues opening the xen 
driver in a post 3.0.3 codepath:

DEBUG: xen_unified.c: xenUnifiedOpen (Trying hypervisor sub-driver)
DEBUG: xen_unified.c: xenUnifiedOpen (Activated hypervisor sub-driver)
libvir: Xen Daemon error : internal error failed to create a socket   
libvir: Xen error : out of memory 
DEBUG: xen_unified.c: xenUnifiedOpen (Failed to make capabilities)
DEBUG: xen_unified.c: xenUnifiedOpen (Failed to activate a mandatory sub-driver)
DEBUG: libvirt.c: do_open (driver 1 Xen returned ERROR)


I haven't chased this down fully yet, but something is interfering...



Daniel P. Berrange wrote on 11/21/2008 11:13 AM:
 On Thu, Nov 20, 2008 at 03:49:07PM -0500, Ben Guthro wrote:
 New xen events patch attached. This removes a couple unnecessary 
 changes from my prior patch, but remains functionally the same as
 the last version.

 This will emit the following events for Xen:

 STARTED
 STOPPED
 ADDED
 REMOVED
 
 I hit a few problems with the old Xen 3.0.3 codepath for /etc/xen files
 in this patch. What follows is the patch I needed to make it work
 reliably on RHEL-5 Xen.
 
 The changes are
 
  - Remove hardcoded qemu:///system to let libvirt probe HV
  - Add a cast to workaround lack of const-ness in RHEL5 python
  - Add an explicit xenXMConfigRemoveFile() to deal with files
going away
  - Remove use of IN_MODIFY - it fired when the config was still
incompletely written resulting in wierd errors
  - Add use of IN_CLOSE_WRITE so we're notified when the file is
finished writing
  - Ignoring IN_CREATE if stat() shows zero size, because this fires
the moment the name is allocated in the FS, but before content
is created. We can't ignore it completely, because its needed
if someone creates the file via hard-linking, when the entire
content appears attomically  no IN_CLOSED_WRITE is fired.
  - Allocate capabilities info before initializing inotify driver
because loading XM config files /etc/xen requires this
  - Fix removal of file handles for inotify  xenstore, since we
need to remove based on watch number, not FD number
 
 Regards,
 Daniel
 
 diff -r fe87b41b48e3 examples/domain-events/events-c/event-test.c
 --- a/examples/domain-events/events-c/event-test.cFri Nov 21 08:02:15 
 2008 -0500
 +++ b/examples/domain-events/events-c/event-test.cFri Nov 21 08:40:58 
 2008 -0500
 @@ -308,7 +308,7 @@ int main(int argc, char **argv)
myEventRemoveTimeoutFunc);
  
  virConnectPtr dconn = NULL;
 -dconn = virConnectOpen (argv[1] ? argv[1] : qemu:///system);
 +dconn = virConnectOpen (argv[1] ? argv[1] : NULL);
  if (!dconn) {
  printf(error opening\n);
  return -1;
 diff -r fe87b41b48e3 include/libvirt/virterror.h
 --- a/include/libvirt/virterror.h Fri Nov 21 08:02:15 2008 -0500
 +++ b/include/libvirt/virterror.h Fri Nov 21 08:02:47 2008 -0500
 @@ -60,6 +60,7 @@ typedef enum {
  VIR_FROM_DOMAIN,/* Error from domain config */
  VIR_FROM_UML,   /* Error at the UML driver */
  VIR_FROM_NODEDEV, /* Error from node device monitor */
 +VIR_FROM_XEN_INOTIFY, /* Error from xen inotify layer */
  } virErrorDomain;
  
  
 diff -r fe87b41b48e3 python/libvir.c
 --- a/python/libvir.c Fri Nov 21 08:02:15 2008 -0500
 +++ b/python/libvir.c Fri Nov 21 08:36:40 2008 -0500
 @@ -1564,7 +1564,8 @@ getLibvirtModuleObject (void) {
  return libvirt_module;
  
  // PyImport_ImportModule returns a new reference
 -libvirt_module = PyImport_ImportModule(libvirt);
 +/* Bogus (char *) cast for RHEL-5 python API brokenness */
 +libvirt_module = PyImport_ImportModule((char *)libvirt);
  if(!libvirt_module) {
  #if DEBUG_ERROR
  printf(%s Error importing libvirt module\n, __FUNCTION__);
 diff -r fe87b41b48e3 src/util.c
 --- a/src/util.c  Fri Nov 21 08:02:15 2008 -0500
 +++ b/src/util.c  Fri Nov 21 11:07:03 2008 -0500
 @@ -613,6 +613,10 @@ virRun(virConnectPtr conn,
  VIR_FREE(outbuf);
  VIR_FREE(errbuf);
  VIR_FREE(argv_str);
 +if (outfd != -1)
 +close(outfd);
 +if (errfd != -1)
 +close(errfd);
  return ret;
  }
  
 diff -r fe87b41b48e3 src/xen_inotify.c
 --- a/src/xen_inotify.c   Fri Nov 21 08:02:15 2008 -0500
 +++ b/src/xen_inotify.c   Fri Nov 21 11:07:22 2008 -0500
 @@ -49,12 +49,6 @@ static const char *configDir= NU
  static const char *configDir= NULL;
  static int  useXenConfigCache = 0;
  static xenUnifiedDomainInfoListPtr configInfoList = NULL;
 -
 -/* declared in xm_internal.c */
 -virHashTablePtr xenXMGetConfigCache(void);
 -char *xenXMGetConfigDir(void);
 -int xenXMConfigCacheRefresh (virConnectPtr conn);
 -int xenXMConfigCacheAddRemoveFile(virConnectPtr conn, const char *filename);
  
  struct xenUnifiedDriver xenInotifyDriver = {
  xenInotifyOpen, /* open */
 @@ -121,7 +115,7

Re: [libvirt] [PATCH] Xen Events Updated

2008-11-21 Thread Ben Guthro
I think I found the culprit of this:

Daniel P. Berrange wrote on 11/21/2008 11:13 AM:
  - Allocate capabilities info before initializing inotify driver
because loading XM config files /etc/xen requires this
 
...
 -if (!(priv-caps = xenHypervisorMakeCapabilities(conn))) {
 -DEBUG0(Failed to make capabilities);
 -goto fail;
 -}

If I undo this part of your patch, everything else works as designed.

While I have no evidence yet to support this claim, I think this is failing 
trying to open the xend socket, perhaps before the xend driver is open...

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


Re: [libvirt] [PATCH] Xen Events Updated

2008-11-21 Thread Ben Guthro
I have integrated your changes, and moved this bit referenced below, so it 
works with my setup. Could you please test with yours, and make sure I didn't 
break anything?

 configure.in |   13
 examples/domain-events/events-c/event-test.c |2
 include/libvirt/virterror.h  |1
 po/POTFILES.in   |1
 python/libvir.c  |3
 src/Makefile.am  |5
 src/util.c   |4
 src/virterror.c  |3
 src/xen_inotify.c|  453 +++
 src/xen_inotify.h|   31 +
 src/xen_unified.c|  200 +++
 src/xen_unified.h|   61 +++
 src/xm_internal.c|  198 +++
 src/xm_internal.h|6
 src/xs_internal.c|  431 +
 src/xs_internal.h|   51 +++
 16 files changed, 1393 insertions(+), 70 deletions(-)


Daniel P. Berrange wrote on 11/21/2008 02:07 PM:
 On Fri, Nov 21, 2008 at 01:56:16PM -0500, Ben Guthro wrote:
 I think I found the culprit of this:

 Daniel P. Berrange wrote on 11/21/2008 11:13 AM:
  - Allocate capabilities info before initializing inotify driver
because loading XM config files /etc/xen requires this

 ...
 -if (!(priv-caps = xenHypervisorMakeCapabilities(conn))) {
 -DEBUG0(Failed to make capabilities);
 -goto fail;
 -}
 If I undo this part of your patch, everything else works as designed.

 While I have no evidence yet to support this claim, I think this is 
 failing trying to open the xend socket, perhaps before the xend driver
 is open...
 
 Doh. Merge error. Originally I had moved it to be immediately before
 the call to initialize xen inotify driver. For inexplicable reasons,
 in the new patch I have it before the XenD driver. 
 
 Daniel
 configure.in |   13 
 examples/domain-events/events-c/event-test.c |2 
 include/libvirt/virterror.h  |1 
 po/POTFILES.in   |1 
 python/libvir.c  |3 
 src/Makefile.am  |5 
 src/util.c   |4 
 src/virterror.c  |3 
 src/xen_inotify.c|  453 +++
 src/xen_inotify.h|   31 +
 src/xen_unified.c|  200 +++
 src/xen_unified.h|   61 +++
 src/xm_internal.c|  198 +++
 src/xm_internal.h|6 
 src/xs_internal.c|  431 +
 src/xs_internal.h|   51 +++
 16 files changed, 1393 insertions(+), 70 deletions(-)
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Xen Events Updated

2008-11-20 Thread Ben Guthro
I see a couple of issues with this patch that I am working out now

Apologies for premature submission.
(Thats what I get for submitting at the end of the day)

New patch to follow shortly

Ben Guthro wrote on 11/19/2008 05:47 PM:
 I finally was able to get back to this patch.
 
 Attached is a new version which detects which xend version it is running 
 under, and adjust appropriately.
 
  configure.in|   13 +
  include/libvirt/virterror.h |1
  po/POTFILES.in  |1
  src/Makefile.am |3
  src/virterror.c |3
  src/xen_inotify.c   |  456 
 
  src/xen_inotify.h   |   31 ++
  src/xen_unified.c   |  192 ++
  src/xen_unified.h   |   59 +
  src/xm_internal.c   |  196 +++---
  src/xs_internal.c   |  437 ++
  src/xs_internal.h   |   51 
  12 files changed, 1367 insertions(+), 76 deletions(-)
 

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


[libvirt] --with-xen=foo

2008-11-20 Thread Ben Guthro
So, when I merged my changes up yesterday to some of the developments going on, 
it would seem that one of the changesets I pulled in had a bit of a reduction 
in configure flexibility.

I'm not yet sure what changeset caused it...but I used to be able to specify an 
external xen tree with the following line in a Makefile...

./autogen.sh --prefix=/usr --with-xen=$(XEN_SRC)/dist/install/usr

This now seems to fail to find that xen tree, as I error out with:

 gcc -DHAVE_CONFIG_H -I. -I. -I.. -I../gnulib/lib -I../gnulib/lib -I../include 
-I../include -I../qemud -I/usr/include/libxml2 -DBINDIR=\/usr/libexec\ 
-DSBINDIR=\/usr/sbin\ -DSYSCONF_DIR=\/etc\ 
-DLOCALEBASEDIR=\/usr/share/locale\ -DLOCAL_STATE_DIR=\/var\ 
-DGETTEXT_PACKAGE=\libvirt\ -Wall -Wformat -Wformat-security 
-Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wextra -Wshadow 
-Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Winline 
-Wredundant-decls -Wno-sign-compare -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fasynchronous-unwind-tables -g -O2 -MT stats_linux.lo -MD -MP -MF 
.deps/stats_linux.Tpo -c stats_linux.c  -fPIC -DPIC -o .libs/stats_linux.o
stats_linux.c:24:16: error: xs.h: No such file or directory
stats_linux.c: In function 'check_bd_connected':
stats_linux.c:154: warning: implicit declaration of function 'xs_read'
stats_linux.c:154: warning: nested extern declaration of 'xs_read'
stats_linux.c:154: warning: assignment makes pointer from integer without a cast


I assume this has something to do with Daniel B's changes to configure scripts 
recently.

Could you give me a pointer as to where I should be looking?

Ben

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


Re: [libvirt] --with-xen=foo

2008-11-20 Thread Ben Guthro
I did a git bisect, and as predicted, the culprit seems to be

aac3e1ab15645f1ff491b140ddb249b01397bebd is first bad commit
commit aac3e1ab15645f1ff491b140ddb249b01397bebd 
Author: Daniel P. Berrange [EMAIL PROTECTED]
Date:   Mon Nov 17 10:43:30 2008 +  

Build drivers as libtool convenience libs


Once again, I am faced with my ignorance of how automake magic works.

It looks to me like XEN_CFLAGS is set properly...but clearly they are not being 
passed on while compiling stats_linux.c





Ben Guthro wrote on 11/20/2008 09:48 AM:
 So, when I merged my changes up yesterday to some of the developments going 
 on, it would seem that one of the changesets I pulled in had a bit of a 
 reduction in configure flexibility.
 
 I'm not yet sure what changeset caused it...but I used to be able to specify 
 an external xen tree with the following line in a Makefile...
 
 ./autogen.sh --prefix=/usr --with-xen=$(XEN_SRC)/dist/install/usr
 
 This now seems to fail to find that xen tree, as I error out with:
 
  gcc -DHAVE_CONFIG_H -I. -I. -I.. -I../gnulib/lib -I../gnulib/lib 
 -I../include -I../include -I../qemud -I/usr/include/libxml2 
 -DBINDIR=\/usr/libexec\ -DSBINDIR=\/usr/sbin\ -DSYSCONF_DIR=\/etc\ 
 -DLOCALEBASEDIR=\/usr/share/locale\ -DLOCAL_STATE_DIR=\/var\ 
 -DGETTEXT_PACKAGE=\libvirt\ -Wall -Wformat -Wformat-security 
 -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wextra -Wshadow 
 -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Winline 
 -Wredundant-decls -Wno-sign-compare -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
 -fasynchronous-unwind-tables -g -O2 -MT stats_linux.lo -MD -MP -MF 
 .deps/stats_linux.Tpo -c stats_linux.c  -fPIC -DPIC -o .libs/stats_linux.o
 stats_linux.c:24:16: error: xs.h: No such file or directory
 stats_linux.c: In function 'check_bd_connected':
 stats_linux.c:154: warning: implicit declaration of function 'xs_read'
 stats_linux.c:154: warning: nested extern declaration of 'xs_read'
 stats_linux.c:154: warning: assignment makes pointer from integer without a 
 cast
 
 
 I assume this has something to do with Daniel B's changes to configure 
 scripts recently.
 
 Could you give me a pointer as to where I should be looking?
 
 Ben
 
 --
 Libvir-list mailing list
 Libvir-list@redhat.com
 https://www.redhat.com/mailman/listinfo/libvir-list

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


[libvirt] [PATCH] Fix UML syntax

2008-11-20 Thread Ben Guthro
various changes to fix make syntax-check succeed with new UML driver
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3f8fdd2..d9f3abe 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -28,6 +28,8 @@ src/storage_backend_logical.c
 src/storage_conf.c
 src/storage_driver.c
 src/test.c
+src/uml_conf.c
+src/uml_driver.c
 src/util.c
 src/uuid.c
 src/virsh.c
diff --git a/src/uml_conf.h b/src/uml_conf.h
index 1213df1..69794bc 100644
--- a/src/uml_conf.h
+++ b/src/uml_conf.h
@@ -64,11 +64,11 @@ struct uml_driver {
 virCapsPtr  umlCapsInit   (void);
 
 int umlBuildCommandLine   (virConnectPtr conn,
-   struct uml_driver *driver,
-   virDomainObjPtr dom,
-   const char ***retargv,
-   const char ***retenv,
-   int **tapfds,
-   int *ntapfds);
+   struct uml_driver *driver,
+   virDomainObjPtr dom,
+   const char ***retargv,
+   const char ***retenv,
+   int **tapfds,
+   int *ntapfds);
 
 #endif /* __UML_CONF_H */
diff --git a/src/uml_driver.c b/src/uml_driver.c
index ac0c32c..d5530d9 100644
--- a/src/uml_driver.c
+++ b/src/uml_driver.c
@@ -51,7 +51,6 @@
 
 #include uml_driver.h
 #include uml_conf.h
-#include c-ctype.h
 #include event.h
 #include buf.h
 #include util.h
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Xen Events Updated

2008-11-20 Thread Ben Guthro
New xen events patch attached. This removes a couple unnecessary changes from 
my prior patch, but remains functionally the same as the last version.

This will emit the following events for Xen:

STARTED
STOPPED
ADDED
REMOVED
diff --git a/configure.in b/configure.in
index 21931a1..a38592a 100644
--- a/configure.in
+++ b/configure.in
@@ -147,6 +147,8 @@ fi
 dnl Allow to build without Xen, QEMU/KVM, test or remote driver
 AC_ARG_WITH([xen],
 [  --with-xen  add XEN support (on)],[],[with_xen=yes])
+AC_ARG_WITH([xen-inotify],
+[  --with-xen-inotify  add XEN inotify support (on)],[],[with_xen_inotify=yes])
 AC_ARG_WITH([qemu],
 [  --with-qemu add QEMU/KVM support (on)],[],[with_qemu=yes])
 AC_ARG_WITH([uml],
@@ -335,6 +337,17 @@ AC_SUBST([XEN_CFLAGS])
 AC_SUBST([XEN_LIBS])
 
 dnl
+dnl check for kernel headers required by xen_inotify
+dnl
+if test $with_xen_inotify != no; then
+AC_CHECK_HEADER([linux/inotify.h],[],[with_xen_inotify=no])
+fi
+if test $with_xen_inotify = yes; then
+AC_DEFINE_UNQUOTED([WITH_XEN_INOTIFY], 1,[whether Xen inotify sub-driver is enabled])
+fi
+AM_CONDITIONAL([WITH_XEN_INOTIFY], [test $with_xen_inotify = yes])
+
+dnl
 dnl check for kernel headers required by src/bridge.c
 dnl
 if test $with_qemu = yes -o $with_lxc = yes ; then
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index 868f1a3..1bce719 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -59,6 +59,7 @@ typedef enum {
 VIR_FROM_NETWORK,   /* Error from network config */
 VIR_FROM_DOMAIN,/* Error from domain config */
 VIR_FROM_UML,   /* Error at the UML driver */
+VIR_FROM_XEN_INOTIFY, /* Error from xen inotify layer */
 } virErrorDomain;
 
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3f8fdd2..5804be6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -32,6 +32,7 @@ src/util.c
 src/uuid.c
 src/virsh.c
 src/virterror.c
+src/xen_inotify.c
 src/xen_internal.c
 src/xend_internal.c
 src/xm_internal.c
diff --git a/src/Makefile.am b/src/Makefile.am
index b2c7e3f..3520130 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -94,6 +94,9 @@ XEN_DRIVER_SOURCES =		\
 		xend_internal.c xend_internal.h			\
 		xm_internal.c xm_internal.h			\
 		xs_internal.c xs_internal.h
+if WITH_XEN_INOTIFY
+XEN_DRIVER_SOURCES += xen_inotify.c xen_inotify.h
+endif
 
 LXC_DRIVER_SOURCES =		\
 		lxc_conf.c lxc_conf.h\
diff --git a/src/virterror.c b/src/virterror.c
index 46a7d15..40bbdf1 100644
--- a/src/virterror.c
+++ b/src/virterror.c
@@ -262,6 +262,9 @@ virDefaultErrorFunc(virErrorPtr err)
 case VIR_FROM_XENSTORE:
 dom = Xen Store ;
 break;
+case VIR_FROM_XEN_INOTIFY:
+dom = Xen Inotify ;
+break;
 case VIR_FROM_DOM:
 dom = Domain ;
 break;
diff --git a/src/xen_inotify.c b/src/xen_inotify.c
new file mode 100644
index 000..ff5898e
--- /dev/null
+++ b/src/xen_inotify.c
@@ -0,0 +1,456 @@
+/*
+ * xen_inofify.c: Xen notification of xml file activity in the
+ *following dirs:
+ */etc/xen
+ */var/lib/xend/domains
+ *
+ * Copyright (C) 2008 VirtualIron
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Ben Guthro
+ */
+#include config.h
+#include dirent.h
+#include sys/inotify.h
+
+#include virterror_internal.h
+#include datatypes.h
+#include driver.h
+#include memory.h
+#include event.h
+#include xen_unified.h
+#include conf.h
+#include domain_conf.h
+#include xen_inotify.h
+#include xend_internal.h
+#include logging.h
+#include uuid.h
+
+#include xm_internal.h /* for xenXMDomainConfigParse */
+
+#define virXenInotifyError(conn, code, fmt...) \
+virReportErrorHelper(NULL, VIR_FROM_XEN_INOTIFY, code, __FILE__,  \
+   __FUNCTION__, __LINE__, fmt)
+
+#define LIBVIRTD_DOMAINS_DIR /var/lib/xend/domains
+static const char *configDir= NULL;
+static int  useXenConfigCache = 0;
+static xenUnifiedDomainInfoListPtr configInfoList = NULL;
+
+/* declared in xm_internal.c */
+virHashTablePtr xenXMGetConfigCache(void);
+char *xenXMGetConfigDir(void);
+int xenXMConfigCacheRefresh (virConnectPtr conn);
+int

[libvirt] [PATCH] Allow rpm to build without uml

2008-11-20 Thread Ben Guthro
Allow to build minimal rpm without uml
diff --git a/libvirt.spec.in b/libvirt.spec.in
index cfd4a66..91af843 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -10,6 +10,7 @@
 %define with_polkit0%{!?_without_polkit:0}
 %define with_python0%{!?_without_python:1}
 %define with_libvirtd  0%{!?_without_libvirtd:1}
+%define with_uml   0%{!?_without_uml:1}
 
 # Xen is available only on i386 x86_64 ia64
 %ifnarch i386 i686 x86_64 ia64
@@ -197,6 +198,10 @@ of recent versions of Linux (and other OSes).
 %define _without_libvirtd --without-libvirtd
 %endif
 
+%if ! %{with_uml}
+%define _without_uml --without-uml
+%endif
+
 %configure %{?_without_xen} \
%{?_without_qemu} \
%{?_without_openvz} \
@@ -206,6 +211,7 @@ of recent versions of Linux (and other OSes).
%{?_without_polkit} \
%{?_without_python} \
%{?_without_libvirtd} \
+   %{?_without_uml} \
--with-init-script=redhat \
--with-qemud-pid-file=%{_localstatedir}/run/libvirt_qemud.pid \
--with-remote-file=%{_localstatedir}/run/libvirtd.pid
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] PATCH: Change signature of virEventAddHandle to allow multiple calls per FD

2008-11-17 Thread Ben Guthro
well, that was a lot of fallout.

All looks necessary though.

+1 from me

Daniel P. Berrange wrote on 11/17/2008 11:58 AM:
 As discussed previously, this patch changes the semantics of the public
 API for dealing with file handle watches. Previously we would track the
 watch based on  the file handle number directly. With this change, the
 virEventAddHandle method returns an integer 'watch' number. This watch
 number is required when unregistering or updating a watch. The watch is
 also passed into the callback when an event occurrs. This allows for
 multiple watches to be registered against the same file descriptor.
 
 There was quite alot of fallout from this patch requiring many callers
 to be updated to comply with the new semantics.
 
  examples/domain-events/events-c/event-test.c   |7 +-
  examples/domain-events/events-python/event-test.py |   12 ++--
  include/libvirt/libvirt.h  |   20 ---
  include/libvirt/libvirt.h.in   |   20 ---
  python/libvir.c|8 +-
  qemud/event.c  |   27 ++---
  qemud/event.h  |   10 +--
  qemud/mdns.c   |   16 +++--
  qemud/qemud.c  |   59 
 +++--
  qemud/qemud.h  |2 
  src/domain_conf.h  |3 +
  src/event.c|8 +-
  src/event.h|8 +-
  src/lxc_driver.c   |   25 +---
  src/qemu_driver.c  |   43 ---
  src/remote_internal.c  |   27 ++---
  16 files changed, 176 insertions(+), 119 deletions(-)
 
 
 Daniel
 
 diff --git a/examples/domain-events/events-c/event-test.c 
 b/examples/domain-events/events-c/event-test.c
 --- a/examples/domain-events/events-c/event-test.c
 +++ b/examples/domain-events/events-c/event-test.c
 @@ -40,8 +40,8 @@ int myDomainEventCallback2 (virConnectPt
  int event, int detail, void *opaque);
  int myEventAddHandleFunc  (int fd, int event,
 virEventHandleCallback cb, void *opaque);
 -void myEventUpdateHandleFunc(int fd, int event);
 -int  myEventRemoveHandleFunc(int fd);
 +void myEventUpdateHandleFunc(int watch, int event);
 +int  myEventRemoveHandleFunc(int watch);
  
  int myEventAddTimeoutFunc(int timeout, virEventTimeoutCallback cb,
void *opaque);
 @@ -308,7 +308,8 @@ int main(int argc, char **argv)
  }
  
  if(h_cb) {
 -h_cb(h_fd,
 +h_cb(0,
 + h_fd,
   myPollEventToEventHandleType(pfd.revents  h_event),
   h_opaque);
  }
 diff --git a/examples/domain-events/events-python/event-test.py 
 b/examples/domain-events/events-python/event-test.py
 --- a/examples/domain-events/events-python/event-test.py
 +++ b/examples/domain-events/events-python/event-test.py
 @@ -75,19 +75,19 @@ def myAddHandle(fd, events, cb, opaque):
  
  mypoll.register(fd, myEventHandleTypeToPollEvent(events))
  
 -def myUpdateHandle(fd, event):
 +def myUpdateHandle(watch, event):
  global h_fd, h_events
  #print Updating Handle %s %s % (str(fd), str(events))
  h_fd = fd
  h_events = event
 -mypoll.unregister(fd)
 -mypoll.register(fd, myEventHandleTypeToPollEvent(event))
 +mypoll.unregister(watch)
 +mypoll.register(watch, myEventHandleTypeToPollEvent(event))
  
 -def myRemoveHandle(fd):
 +def myRemoveHandle(watch):
  global h_fd
  #print Removing Handle %s % str(fd)
  h_fd = 0
 -mypoll.unregister(fd)
 +mypoll.unregister(watch)
  
  def myAddTimeout(timeout, cb, opaque):
  global t_active, t_timeout, t_cb, t_opaque
 @@ -175,7 +175,7 @@ def main():
  
  if h_cb != None:
  #print Invoking Handle CB
 -h_cb(h_fd, myPollEventToEventHandleType(revents  h_events),
 +h_cb(0, h_fd, myPollEventToEventHandleType(revents  h_events),
   h_opaque[0], h_opaque[1])
  
  #print DEBUG EXIT
 diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h
 --- a/include/libvirt/libvirt.h
 +++ b/include/libvirt/libvirt.h
 @@ -1121,13 +1121,15 @@ typedef enum {
  /**
   * virEventHandleCallback:
   *
 + * @watch: watch on which the event occurred
   * @fd: file handle on which the event occurred
   * @events: bitset of events from virEventHandleType constants
   * @opaque: user data registered with handle
   *
 - * callback for receiving file handle events
 + * Callback for receiving file handle events. The callback will
 + * be invoked once for each event which is pending.
   */
 -typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
 +typedef void 

RE: [libvirt] RFC: Add a 'reason' argument for domain events ?

2008-11-14 Thread Ben Guthro
To revisit the DEFINED, UNDEFINED topic - I have been giving this some thought, 
and it seems like it is redundant information to me.

Doesn't the existence of a config file define the difference between a 
transient and a persistent domain?
Therefore this could be tracked solely with the enum values we have? 
If a transient domain becomes persistent via adding a config file, the ADDED 
event would be emitted, denoting a config file came into being, and by 
definition changing this domain from transient, to persistent.
I'm not sure I understand the need for these events.


Moving on to the shutdown reason discussion - 
I can certainly see the need to know why a domain stopped.
That said - would it not be more consistent with the API to introduce an event 
sub-type enum to be passed alongside of the event-type, passed as a second 
integer?
This would reduce the size of the wire protocol, not needing to pass the full 
character string, as well.

This would trivially allow us finer grained notifications within a particular 
event.

A downside is that it may become a bit noisy for clients who may not be 
interested in all of the sub-events.
Perhaps we should add some sort of filtering mechanism?

 
-Original Message-
From: [EMAIL PROTECTED] on behalf of Daniel P. Berrange
Sent: Fri 11/14/2008 6:18 AM
To: libvir-list@redhat.com
Subject: [libvirt] RFC: Add a 'reason' argument for domain events ?
 
We currently have a set of domain lifecycle events

  VIR_DOMAIN_EVENT_ADDED = 0,
  VIR_DOMAIN_EVENT_REMOVED = 1,
  VIR_DOMAIN_EVENT_STARTED = 2,
  VIR_DOMAIN_EVENT_SUSPENDED = 3,
  VIR_DOMAIN_EVENT_RESUMED = 4,
  VIR_DOMAIN_EVENT_STOPPED = 5,
  VIR_DOMAIN_EVENT_SAVED = 6,
  VIR_DOMAIN_EVENT_RESTORED = 7,

And a couple more I proposed last week to allow distinguishing of new
domains which are transient vs persistent

  VIR_DOMAIN_EVENT_DEFINED = 8,
  VIR_DOMAIN_EVENT_UNDEFINED = 9,

Previously Stefan has suggested we should consider having an event for
migration, and though I rejected that at the time, I'm now inclined to
agree that this info would be useful here. I'm also thinking I'd like
to have more information about STOPPED  STARTED events in general.

eg, there are a number of reasons why an domain may have started

 - explicitly booted on the host
 - restored from a saved image
 - incoming migration operation

and there are a number of reasons why a domain might have stopped

 - forcably destroyed by host admin
 - shutdown by host admin
 - shutdown by guest admin
 - host emulator process crashed
 - killed by mgmt after host emulation hung
 - migrated to another host
 - saved to a memory image

We have explicit events for the SAVED/RESTORED reasons, but what should
we do about the other reasons ?

One option is to add alot more events

  VIR_DOMAIN_MIGRATED_IN   (migrated to another node)
  VIR_DOMAIN_MIGRATED_OUT  (migrated from another node)
  VIR_DOMAIN_SHUTDOWN  (graceful shutdown by host admin)
  VIR_DOMAIN_DESTROYED (force destroyed by host admin)
  VIR_DOMAIN_CRASHED   (guest kernel crashed)
  VIR_DOMAIN_HUNG  (host emulator hung)

leaving STOPPED to just be a generic stop event, with no particular
reason.

The downside with this, is if an application just wants to know about 
whether a domain shutdown, not why, then they have to track lots and
lots of events.

Also, not every driver  would be able to provide all of these events,
so would often have to fallback on a generic STOPPED event 

So one alternative is to provide a generic 'char * reason' with each 
event with provides scope on the cause of the lifecycle operation.
So you'd get

  VIR_DOMAIN_STOPPED  (crashed, shutdown, destroyed,
   quit, hung, migrated, saved)
  VIR_DOMAIN_STARTED  (booted, migrated, restored)

nb, we could remove the explicit SAVED and RESTORED events in this style.

With such a 'reason' arg, we could possibly avoid adding the DEFINED
and UNDEFINED events I suggested. Instead, adding a reason for ADDED
and REMOVED events,

   VIR_DOMAIN_ADDED(started, defined)
   VIR_DOMAIN_REMOVED  (shutdown, undefined)

which lets you distinguish transient from persistent domains. The downside
of this though, is that we can't explicitly track when a configuration
file is 're-defined', eg adding a config file for an existing running
guest.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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

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


RE: [libvirt] [RFC] making (newly public) EventImpl interface moreconsistent

2008-11-14 Thread Ben Guthro
I'll answer for Dave, while I'm looking at this.

As far as I know, Dave is of the opinion that we are just getting lucky using 
the APIs as we are, and remains convinced that his suggested change is 
necessary here.

He (and I) remain worried that release of the EventImpl API without this API 
change could get us into trouble in the future, as we would have to support the 
released API that has different semantics than DBus, which we were supposed to 
be modeled closely to.

You had sounded convinced it was not necessary the last we heard though...and 
ultimatley we don't have checkin permissions...so we'll go with whatever you 
guys decide.

I'll let Dave follow up with any additional examples of where this would get us 
in trouble...


-Original Message-
From: Daniel P. Berrange [mailto:[EMAIL PROTECTED]
Sent: Fri 11/14/2008 6:27 AM
To: Dave Lively
Cc: Ben Guthro; libvir-list
Subject: Re: [libvirt] [RFC] making (newly public) EventImpl interface 
moreconsistent
 
On Wed, Nov 05, 2008 at 05:32:36PM -0500, David Lively wrote:
 Ugh.  I see what you mean.  It seems more complicated than that, though.
 For one thing, the AvahiWatch/AvahiPoll stuff is sufficiently abstract
 that it doesn't mention DBusConnection (or any other DBus type, AFAIK),
 so there's no indication that *any* DBusConnection is being used (though
 I trust that there is).  Turning on AVAHI_DEBUG, I see both my
 (node_device_hal.c) callbacks and the avahi callbacks being called (but
 at different times, and with different fds and event sets).  Makes me
 wonder whether the avahi library is using dbus_bus_get_private() to get
 its own DBusConnection that it doesn't have to worry about sharing with
 others.
 
 I tried changing the node_device_hal code to use a private dbus
 connection, and see exactly the same behavior (i.e., dbus immediately
 registers the same fd twice, with different event sets and enable
 state).  Regardless, I like the idea of simply using this private
 connection (as you suggested but rejected), just for the sake of
 simplicity.  (Also, what if Avahi's been configured out?)
 
 But ... back to the original problem.  Immediately after calling
 dbus_set_watch_functions (and *before* initializing the Avahi stuff), I
 see two callbacks to watch_add with the same fd.  Looking at the glib
 watch functions, I see watches on GIOChannels are added with
 g_io_add_watch(), which indeed doesn't specify what happens if the same
 GIOChannel is added twice.  But GIOChannels aren't fds.  Presumably, one
 could create two different GIOChannels with the same fd (via
 g_io_channel_unix_new) and then register watches on each of them.  So I
 remain convinced that we need to support the registration of the same fd
 multiple times ...

Did you ever get to the bottom of this problem. If not, then I think
the only safe thing todo for this release is to change the signature
of AddHandle as you suggest, so we explicitly track FDs using an
integer ID that's independant of the FD number.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] PATCH: Add domain event detail information

2008-11-14 Thread Ben Guthro
Looks pretty much exactly how I pictured it

+1

Daniel P. Berrange wrote on 11/14/2008 12:44 PM:
 As per our earlier discussion today, this patch expands the callback for
 domain events so that it also gets a event type specific 'detail' field.
 This is also kept as an int, and we define enumerations for the possible
 values associated with each type. If a event type has no detail, 0 is
 passed.
 
 The RESTORED and SAVED event types disappear in this patch and just become
 another piece of 'detail' to the STOPPED and STARTED events. I have also
 renamed ADDED  REMOVED to DEFINED and UNDEFINED to match terminology we
 have elsewhere  because the names were confusing me
 
 Easiest to just look at the final set:
 
 typedef enum {
   VIR_DOMAIN_EVENT_DEFINED = 0,
   VIR_DOMAIN_EVENT_UNDEFINED = 1,
   VIR_DOMAIN_EVENT_STARTED = 2,
   VIR_DOMAIN_EVENT_SUSPENDED = 3,
   VIR_DOMAIN_EVENT_RESUMED = 4,
   VIR_DOMAIN_EVENT_STOPPED = 5,
 } virDomainEventType;
 
 typedef enum {
 VIR_DOMAIN_EVENT_STARTED_BOOTED = 0,   /* Normal startup from boot */
 VIR_DOMAIN_EVENT_STARTED_MIGRATED = 1, /* Incoming migration from another 
 host */
 VIR_DOMAIN_EVENT_STARTED_RESTORED = 2, /* Restored from a state file */
 } virDomainEventStartedDetailType;
 
 typedef enum {
 VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN = 0,  /* Normal shutdown */
 VIR_DOMAIN_EVENT_STOPPED_DESTROYED = 1, /* Forced poweroff from host */
 VIR_DOMAIN_EVENT_STOPPED_CRASHED = 2,   /* Guest crashed */
 VIR_DOMAIN_EVENT_STOPPED_MIGRATED = 3,  /* Migrated off to another host */
 VIR_DOMAIN_EVENT_STOPPED_SAVED = 4, /* Saved to a state file */
 VIR_DOMAIN_EVENT_STOPPED_FAILED = 5,/* Host emulator/mgmt failed */
 } virDomainEventStoppedDetailType;
 
 typedef enum {
 VIR_DOMAIN_EVENT_DEFINED_ADDED = 0, /* Newly created config file */
 VIR_DOMAIN_EVENT_DEFINED_UPDATED = 1,   /* Changed config file */
 } virDomainEventDefinedDetailType;
 
 I don't make use of 'CRASHED' in QEMU driver yet. It might be useful in
 Xen though - when a PV guest crashes, Xen stops the domain running, but
 leaves it there in a shutoff state, but marked as crashed.
 
 Now using the C event-test program you can see the effects:
 
   myDomainEventCallback1 EVENT: Domain F9x86_64(2) Started Booted
   myDomainEventCallback2 EVENT: Domain F9x86_64(2) Started Booted
   myDomainEventCallback1 EVENT: Domain F9x86_64(-1) Stopped Destroyed
   myDomainEventCallback2 EVENT: Domain F9x86_64(-1) Stopped Destroyed
   myDomainEventCallback1 EVENT: Domain F9x86_64(3) Started Booted
   myDomainEventCallback2 EVENT: Domain F9x86_64(3) Started Booted
   myDomainEventCallback1 EVENT: Domain F9x86_64(3) Suspended 
   myDomainEventCallback2 EVENT: Domain F9x86_64(3) Suspended 
   myDomainEventCallback1 EVENT: Domain F9x86_64(3) Resumed 
   myDomainEventCallback2 EVENT: Domain F9x86_64(3) Resumed 
   myDomainEventCallback1 EVENT: Domain F9x86_64(-1) Stopped Shutdown
   myDomainEventCallback2 EVENT: Domain F9x86_64(-1) Stopped Shutdown
 
 Of the following sequence of actions
 
   virsh start F9x86_64
   virsh destroy F9x86_64
   virsh start F9x86_64
   virsh suspend F9x86_64
   virsh resume F9x86_64
   virsh shutdown F9x86_64
 
 For the last 'shutdown' operation, you'll see the same if you just run
 a graceful shutdown inside the guest itself.
 
 NB, I've not tested saved/restored because my install of KVM is not new
 enough to support that correctly, but I expect it to work without trouble.
 Likewise for migration.
 
 A word about migration...
 
  - The destination host first gets a STARTED event, with detail MIGRATED
when it starts running
  - The source host then gets a STOPPED event with detail MIGRATED when
it completes
  - The destination host then gets a RESUMED event, on success, and
a STOPPED event with detail FAILED if migration aborts.
 
 Daniel
 
  examples/domain-events/events-c/event-test.c   |   78 +++
  examples/domain-events/events-python/event-test.py |8 +-
  include/libvirt/libvirt.h  |   29 ++-
  include/libvirt/libvirt.h.in   |   29 ++-
  python/libvir.c|6 +
  qemud/qemud.h  |1 
  qemud/remote.c |   22 +++--
  qemud/remote_protocol.c|2 
  qemud/remote_protocol.h|1 
  qemud/remote_protocol.x|1 
  src/domain_event.c |4 -
  src/domain_event.h |6 +
  src/qemu_driver.c  |   82 
 +++--
  src/remote_internal.c  |   29 ---
  18 files changed, 366 insertions(+), 118 deletions(-)
 
 
 
 diff --git a/examples/domain-events/events-c/event-test.c 
 b/examples/domain-events/events-c/event-test.c
 

[libvirt] [PATCH] Xen Events Updated

2008-11-11 Thread Ben Guthro
This version of the Xen-Events patch goes a step further than the last version, 
and now emits the following domain events:

STARTED
STOPPED
ADDED
REMOVED

This is accomplished by monitoring /etc/xen, and taking advantage of what 
seemed to be dormant code in the XM driver. By re-enabling the config cache, 
we can properly track domains when files come, and go into this directory.

 configure.in|   13 +
 include/libvirt/virterror.h |1
 po/POTFILES.in  |1
 src/Makefile.am |3
 src/virterror.c |3
 src/xen_inotify.c   |  270 +++
 src/xen_inotify.h   |   32 +++
 src/xen_unified.c   |  190 +++
 src/xen_unified.h   |   61 ++
 src/xm_internal.c   |   24 +-
 src/xs_internal.c   |  430 +++-
 src/xs_internal.h   |   51 +
 12 files changed, 1069 insertions(+), 10 deletions(-)

diff --git a/configure.in b/configure.in
index ef69730..6ac4c4e 100644
--- a/configure.in
+++ b/configure.in
@@ -147,6 +147,8 @@ fi
 dnl Allow to build without Xen, QEMU/KVM, test or remote driver
 AC_ARG_WITH([xen],
 [  --with-xen  add XEN support (on)],[],[with_xen=yes])
+AC_ARG_WITH([xen-inotify],
+[  --with-xen-inotify  add XEN inotify support (on)],[],[with_xen_inotify=yes])
 AC_ARG_WITH([qemu],
 [  --with-qemu add QEMU/KVM support (on)],[],[with_qemu=yes])
 AC_ARG_WITH([openvz],
@@ -328,6 +330,17 @@ AC_SUBST([XEN_CFLAGS])
 AC_SUBST([XEN_LIBS])
 
 dnl
+dnl check for kernel headers required by xen_inotify
+dnl
+if test $with_xen_inotify != no; then
+AC_CHECK_HEADER([linux/inotify.h],[],[with_xen_inotify=no])
+fi
+if test $with_xen_inotify = yes; then
+AC_DEFINE_UNQUOTED([WITH_XEN_INOTIFY], 1,[whether Xen inotify sub-driver is enabled])
+fi
+AM_CONDITIONAL([WITH_XEN_INOTIFY], [test $with_xen_inotify = yes])
+
+dnl
 dnl check for kernel headers required by src/bridge.c
 dnl
 if test $with_qemu = yes -o $with_lxc = yes ; then
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index 8e24708..ff07542 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -58,6 +58,7 @@ typedef enum {
 VIR_FROM_STORAGE,   /* Error from storage driver */
 VIR_FROM_NETWORK,   /* Error from network config */
 VIR_FROM_DOMAIN,/* Error from domain config */
+VIR_FROM_XEN_INOTIFY, /* Error from xen inotify layer */
 } virErrorDomain;
 
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3f8fdd2..5804be6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -32,6 +32,7 @@ src/util.c
 src/uuid.c
 src/virsh.c
 src/virterror.c
+src/xen_inotify.c
 src/xen_internal.c
 src/xend_internal.c
 src/xm_internal.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 9b9520e..880733b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -93,6 +93,9 @@ XEN_DRIVER_SOURCES =		\
 		xend_internal.c xend_internal.h			\
 		xm_internal.c xm_internal.h			\
 		xs_internal.c xs_internal.h
+if WITH_XEN_INOTIFY
+XEN_DRIVER_SOURCES += xen_inotify.c xen_inotify.h
+endif
 
 LXC_DRIVER_SOURCES =		\
 		lxc_conf.c lxc_conf.h\
diff --git a/src/virterror.c b/src/virterror.c
index 15eb0a1..1ca821d 100644
--- a/src/virterror.c
+++ b/src/virterror.c
@@ -262,6 +262,9 @@ virDefaultErrorFunc(virErrorPtr err)
 case VIR_FROM_XENSTORE:
 dom = Xen Store ;
 break;
+case VIR_FROM_XEN_INOTIFY:
+dom = Xen Inotify ;
+break;
 case VIR_FROM_DOM:
 dom = Domain ;
 break;
diff --git a/src/xen_inotify.c b/src/xen_inotify.c
new file mode 100644
index 000..b388ab1
--- /dev/null
+++ b/src/xen_inotify.c
@@ -0,0 +1,270 @@
+/*
+ * xen_inofify.c: Xen notification of xml file activity in the
+ *following dirs:
+ */etc/xen
+ */var/lib/xend/domains
+ *
+ * Copyright (C) 2008 VirtualIron
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Ben Guthro
+ */
+#include config.h
+#include sys/inotify.h
+
+#include virterror_internal.h
+#include datatypes.h
+#include driver.h
+#include memory.h
+#include event.h
+#include xen_unified.h
+#include conf.h
+#include domain_conf.h

Re: [libvirt] make not invoking rpcgen remote_protocol.x

2008-11-10 Thread Ben Guthro
from the top level, you could do a 
make -C src remote_protocol.c

This should re-generate both .c and .h files from the .x

Kenneth Nagin wrote on 11/10/2008 10:52 AM:
 I am attempting to add some new libvirt functions that I intend to submit
 for your approval.
 I have made changes to remote_protocol.x.  Initially it generated the
 expected files.
 However,  after making a few changes the make no causes it to generate
 files.
 Manually invoke rpcgen -c remote_protocol.x  remote_protocol.c seems
 to get around the compile problem.  But now I'm getting a Remote error :
 marshaling args
 I 'm think there is a problem in the make.
 
 Kenneth Nagin
 
 
 
 
 --
 Libvir-list mailing list
 Libvir-list@redhat.com
 https://www.redhat.com/mailman/listinfo/libvir-list

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


Re: [libvirt] PATCH: Misc fixes to events code

2008-11-07 Thread Ben Guthro

Daniel P. Berrange wrote on 11/04/2008 05:05 PM:
 Well lets just start with STARTED/STOPPED from xenstore, and possibly
 try ADDED/REMOVED using inotify on /etc/xen or /var/lib/xend/domains.
 These are what virt-manager cares about the most. The others are just
 a nice-to-have.

Perhaps I just can't see it, but is there already mechanism where I can look up 
a domain (virDomainPtr) given a config filename? I'd rather not re-invent the 
wheel if this is already written...

I think that there should be code to do this somewhere in the xm_internal file 
when listing defined (but not running) domains...but I'm just not seeing it

Ben

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


Re: [libvirt] RFC: Domain events add DEFINED and UNDEFINED events

2008-11-07 Thread Ben Guthro
I suppose I could make some sort of configure option to only compile it in 
optionally...

I don't have access to a solaris box though...so don't really know what the 
appropriate API would be in that situation

Daniel Veillard wrote on 11/07/2008 07:39 AM:
 On Fri, Nov 07, 2008 at 12:26:23PM +, Daniel P. Berrange wrote:
 Yesterday, I began looking into creating a xen driver patch for emitting 
 the DEFINED/UNDEFINED events via inotify.
 It looks like the easiest way to do this right now is to create yet another 
 Xen sub-driver.
 I don't expect this to take an extremely long time, as this tutorial from 
 IBM makes it fairly straightforward to understand:
 http://www-128.ibm.com/developerworks/linux/library/l-inotify.html
 The experimental user mode linux driver has some iNotify code in
 it too if you want another point of reference. See the
 umlInotifyEvent() method umlStartup() where I register for the
 events

 http://www.redhat.com/archives/libvir-list/2008-October/msg00355.html
 
   Hum, the only problem is that contrary to uml , the xen drivers should
 not be Linux specific, but inotify is linux specific.
 Making this subdriver Linux only should still be okay until someone
 using Solaris comes with an appropriate patch though,
 
 /me hopes to never get involved again into the mess of portable APIs
 for file changes notifications.
 
 Daniel
 

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


RE: [libvirt] RFC: Domain events add DEFINED and UNDEFINED events

2008-11-07 Thread Ben Guthro
I think this sounds reasonable.

Let me see if I understand the state machine for a newly created persistent 
domain:
DEFINED-ADDED-STARTED-STOPPED

Starting, then stopping a previously defined persistent domain would just emit 
STARTED-STOPPED

and a transient domain would be:
ADDED-STARTED-STOPPED-REMOVED

Will it be an issue for domains that only support a subset of these events 
(like xen)

Yesterday, I began looking into creating a xen driver patch for emitting the 
DEFINED/UNDEFINED events via inotify.
It looks like the easiest way to do this right now is to create yet another Xen 
sub-driver.
I don't expect this to take an extremely long time, as this tutorial from IBM 
makes it fairly straightforward to understand:
http://www-128.ibm.com/developerworks/linux/library/l-inotify.html



-Original Message-
From: [EMAIL PROTECTED] on behalf of Daniel P. Berrange
Sent: Fri 11/7/2008 5:34 AM
To: libvir-list@redhat.com
Subject: [libvirt] RFC: Domain events add DEFINED and UNDEFINED events
 
We currently have the following list of events for domains:

  VIR_DOMAIN_EVENT_ADDED,
  VIR_DOMAIN_EVENT_REMOVED,
  VIR_DOMAIN_EVENT_STARTED,
  VIR_DOMAIN_EVENT_SUSPENDED,
  VIR_DOMAIN_EVENT_RESUMED,
  VIR_DOMAIN_EVENT_STOPPED,
  VIR_DOMAIN_EVENT_SAVED,
  VIR_DOMAIN_EVENT_RESTORED,

The QEMU driver supports all of them, except for ADDED and REMOVED. I
was looking at adding these and wondering how exactly we should define
the semantics

Originally I was just going to emit 'ADDED' from virDomainDefine() driver
impl and 'REMOVED' from virDomainUndefine().

This does not, however, take into account that there are two sorts of
domains, so called 'persistent' and 'transient' domains.

With a transient domain, there is no config file, so the first time you
know about the domain is when it is booted via virDomainCreateXML(),
and all trace of it disappears when it shuts down, or migrates, or is
saved.  With a persistent domain though, it is visible before it is
booted, and remains visible after shutdown/migrate/save etc.

The current set of events does not allow applications to get this level
of visibility. eg when receiving a VIR_DOMAIN_EVENT_STOPPED event, there
is no way to know wether the domain was transient / persistent, and thus
whether to remove it from your list of VMs, or simply mark it shutoff.

So, I'd like to propose that we do the following:

 - Clarify the semantics for 

* VIR_DOMAIN_EVENT_ADDED

Emitted when a domain comes into existance, by which I mean a
previously known inactive domain is defined, or a transient
domain is booted. This is emited before any other events for
a domain with that UUID/name.

* VIR_DOMAIN_EVENT_REMOVED

Emitted when a domains goes out of existance, by which I mean
a transient domain shuts down / migrates / is saved, or a
persistent domain is undefined. This is the last event ever to
be emitted for a domain with that UUID/name.


 - Create two more events

 * VIR_DOMAIN_EVENT_DEFINED

 Emitted whenenever a domain's config file is created. This can
 be when a peristent domain is first defined, when it is later
 re-defined, or when an transient domain gains a confi file,
 becoming persistent.

 * VIR_DOMAIN_EVENT_UNDEFINED

 Emitted when a domain's config file is removed.

With this complete set of events, virt-manager is able to track domains
without ever having to poll for the domain listing.

I think we also need to provide some way for an application to determine
what set of events a hypervisor backend supports. eg, if it only supports
the STARTED/STOPPED events, virt-manager would still need to do polling to
find out about defined/undefined domains.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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

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


[libvirt] [PATCH] Xen events

2008-11-06 Thread Ben Guthro
The following patch implements a framework for emitting events from the Xen 
driver, via monitoring xenstore.

Currently, this only emits the STARTED, and STOPPED events, as this is all that 
seems to be available via monitoring xenstore. 

 xen_unified.c |  162 +++
 xen_unified.h |   38 +
 xs_internal.c |  408 +-
 xs_internal.h |   51 +++
 4 files changed, 657 insertions(+), 2 deletions(-)
diff --git a/src/xen_unified.c b/src/xen_unified.c
index 1ab204d..9314725 100644
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -222,6 +222,7 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f
 {
 int i, ret = VIR_DRV_OPEN_DECLINED;
 xenUnifiedPrivatePtr priv;
+virDomainEventCallbackListPtr cbList;
 
 /* Refuse any scheme which isn't xen:// or http://;. */
 if (uri-scheme 
@@ -248,6 +249,13 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f
 }
 conn-privateData = priv;
 
+/* Allocate callback list */
+if (VIR_ALLOC(cbList)  0) {
+xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, allocating callback list);
+return VIR_DRV_OPEN_ERROR;
+}
+priv-domainEventCallbacks = cbList;
+
 priv-handle = -1;
 priv-xendConfigVersion = -1;
 priv-type = -1;
@@ -345,6 +353,8 @@ xenUnifiedClose (virConnectPtr conn)
 int i;
 
 virCapabilitiesFree(priv-caps);
+virDomainEventCallbackListFree(priv-domainEventCallbacks);
+
 for (i = 0; i  XEN_UNIFIED_NR_DRIVERS; ++i)
 if (priv-opened[i]  drivers[i]-close)
 (void) drivers[i]-close (conn);
@@ -1280,6 +1290,29 @@ xenUnifiedNodeGetFreeMemory (virConnectPtr conn)
 return(0);
 }
 
+static int
+xenUnifiedDomainEventRegister (virConnectPtr conn,
+   void *callback,
+   void *opaque)
+{
+GET_PRIVATE (conn);
+conn-refs++;
+return virDomainEventCallbackListAdd(conn, priv-domainEventCallbacks,
+ callback, opaque);
+}
+
+static int
+xenUnifiedDomainEventDeregister (virConnectPtr conn,
+ void *callback)
+{
+int ret;
+GET_PRIVATE (conn);
+ret = virDomainEventCallbackListRemove(conn, priv-domainEventCallbacks,
+callback);
+virUnrefConnect(conn);
+return ret;
+}
+
 /*- Register with libvirt.c, and initialise Xen drivers. -*/
 
 #define HV_VERSION ((DOM0_INTERFACE_VERSION  24) * 100 + \
@@ -1345,6 +1378,8 @@ static virDriver xenUnifiedDriver = {
 .domainBlockPeek	= xenUnifiedDomainBlockPeek,
 .nodeGetCellsFreeMemory = xenUnifiedNodeGetCellsFreeMemory,
 .getFreeMemory = xenUnifiedNodeGetFreeMemory,
+.domainEventRegister = xenUnifiedDomainEventRegister,
+.domainEventDeregister = xenUnifiedDomainEventDeregister,
 };
 
 /**
@@ -1364,3 +1399,130 @@ xenUnifiedRegister (void)
 return virRegisterDriver (xenUnifiedDriver);
 }
 
+/**
+ * xenUnifiedDomainInfoListFree:
+ *
+ * Free the Domain Info List
+ */
+void
+xenUnifiedDomainInfoListFree(xenUnifiedDomainInfoListPtr list)
+{
+int i;
+for (i=0; ilist-count; i++) {
+VIR_FREE(list-doms[i]-name);
+VIR_FREE(list-doms[i]-uuid);
+}
+VIR_FREE(list);
+}
+
+/**
+ * xenUnifiedAddDomainInfo:
+ *
+ * Add name and uuid to the domain info list
+ *
+ * Returns: 0 on success, -1 on failure
+ */
+int
+xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list,
+ char *name, char *uuid)
+{
+xenUnifiedDomainInfoPtr info;
+int n;
+
+/* check if we already have this callback on our list */
+for (n=0; n  list-count; n++) {
+if( STREQ(list-doms[n]-name, name) 
+STREQ(list-doms[n]-uuid, uuid)) {
+DEBUG0(WARNING: dom already tracked);
+return -1;
+}
+}
+
+if (VIR_ALLOC(info)  0) {
+xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, allocating info);
+return -1;
+}
+info-name   = strdup(name);
+info-uuid  = strdup(uuid);
+
+/* Make space on list */
+n = list-count;
+if (VIR_REALLOC_N(list-doms, n + 1)  0) {
+xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, reallocating list);
+VIR_FREE(info);
+return -1;
+}
+
+list-doms[n] = info;
+list-count++;
+return 0;
+}
+
+/**
+ * xenUnifiedRemoveDomainInfo:
+ *
+ * Removes name and uuid to the domain info list
+ *
+ * Returns: 0 on success, -1 on failure
+ */
+int
+xenUnifiedRemoveDomainInfo(xenUnifiedDomainInfoListPtr list,
+ char *name, char *uuid)
+{
+int i;
+for (i = 0 ; i  list-count ; i++) {
+if( STREQ(list-doms[i]-name, name) 
+STREQ(list-doms[i]-uuid, uuid)) {
+VIR_FREE(list-doms[i]-name);
+VIR_FREE(list-doms[i]-uuid);
+VIR_FREE(list-doms[i]);
+
+if (i  

Re: [libvirt] [PATCH] Xen events

2008-11-06 Thread Ben Guthro
New patch attached with changes recommended in prior email from Daniel V.

Ben
diff --git a/src/xen_unified.c b/src/xen_unified.c
index 1ab204d..c5f84c8 100644
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -222,6 +222,7 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f
 {
 int i, ret = VIR_DRV_OPEN_DECLINED;
 xenUnifiedPrivatePtr priv;
+virDomainEventCallbackListPtr cbList;
 
 /* Refuse any scheme which isn't xen:// or http://;. */
 if (uri-scheme 
@@ -248,6 +249,13 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f
 }
 conn-privateData = priv;
 
+/* Allocate callback list */
+if (VIR_ALLOC(cbList)  0) {
+xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, allocating callback list);
+return VIR_DRV_OPEN_ERROR;
+}
+priv-domainEventCallbacks = cbList;
+
 priv-handle = -1;
 priv-xendConfigVersion = -1;
 priv-type = -1;
@@ -345,6 +353,8 @@ xenUnifiedClose (virConnectPtr conn)
 int i;
 
 virCapabilitiesFree(priv-caps);
+virDomainEventCallbackListFree(priv-domainEventCallbacks);
+
 for (i = 0; i  XEN_UNIFIED_NR_DRIVERS; ++i)
 if (priv-opened[i]  drivers[i]-close)
 (void) drivers[i]-close (conn);
@@ -1280,6 +1290,29 @@ xenUnifiedNodeGetFreeMemory (virConnectPtr conn)
 return(0);
 }
 
+static int
+xenUnifiedDomainEventRegister (virConnectPtr conn,
+   void *callback,
+   void *opaque)
+{
+GET_PRIVATE (conn);
+conn-refs++;
+return virDomainEventCallbackListAdd(conn, priv-domainEventCallbacks,
+ callback, opaque);
+}
+
+static int
+xenUnifiedDomainEventDeregister (virConnectPtr conn,
+ void *callback)
+{
+int ret;
+GET_PRIVATE (conn);
+ret = virDomainEventCallbackListRemove(conn, priv-domainEventCallbacks,
+callback);
+virUnrefConnect(conn);
+return ret;
+}
+
 /*- Register with libvirt.c, and initialise Xen drivers. -*/
 
 #define HV_VERSION ((DOM0_INTERFACE_VERSION  24) * 100 + \
@@ -1345,6 +1378,8 @@ static virDriver xenUnifiedDriver = {
 .domainBlockPeek	= xenUnifiedDomainBlockPeek,
 .nodeGetCellsFreeMemory = xenUnifiedNodeGetCellsFreeMemory,
 .getFreeMemory = xenUnifiedNodeGetFreeMemory,
+.domainEventRegister = xenUnifiedDomainEventRegister,
+.domainEventDeregister = xenUnifiedDomainEventDeregister,
 };
 
 /**
@@ -1364,3 +1399,141 @@ xenUnifiedRegister (void)
 return virRegisterDriver (xenUnifiedDriver);
 }
 
+/**
+ * xenUnifiedDomainInfoListFree:
+ *
+ * Free the Domain Info List
+ */
+void
+xenUnifiedDomainInfoListFree(xenUnifiedDomainInfoListPtr list)
+{
+int i;
+for (i=0; ilist-count; i++) {
+VIR_FREE(list-doms[i]-name);
+VIR_FREE(list-doms[i]-uuid);
+VIR_FREE(list-doms[i]);
+}
+VIR_FREE(list);
+}
+
+/**
+ * xenUnifiedAddDomainInfo:
+ *
+ * Add name and uuid to the domain info list
+ *
+ * Returns: 0 on success, -1 on failure
+ */
+int
+xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list,
+int id, char *name, char *uuid)
+{
+xenUnifiedDomainInfoPtr info;
+int n;
+
+/* check if we already have this callback on our list */
+for (n=0; n  list-count; n++) {
+if( STREQ(list-doms[n]-name, name) 
+STREQ(list-doms[n]-uuid, uuid)) {
+DEBUG0(WARNING: dom already tracked);
+return -1;
+}
+}
+
+if (VIR_ALLOC(info)  0)
+goto memory_error;
+if (!(info-name = strdup(name)))
+goto memory_error;
+if (!(info-uuid = strdup(uuid)))
+goto memory_error;
+info-id = id;
+
+/* Make space on list */
+n = list-count;
+if (VIR_REALLOC_N(list-doms, n + 1)  0) {
+goto memory_error;
+}
+
+list-doms[n] = info;
+list-count++;
+return 0;
+memory_error:
+xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, allocating domain info);
+if (info  info-name)
+VIR_FREE(info-name);
+if (info  info-uuid)
+VIR_FREE(info-uuid);
+if (info)
+VIR_FREE(info);
+return -1;
+}
+
+/**
+ * xenUnifiedRemoveDomainInfo:
+ *
+ * Removes name and uuid to the domain info list
+ *
+ * Returns: 0 on success, -1 on failure
+ */
+int
+xenUnifiedRemoveDomainInfo(xenUnifiedDomainInfoListPtr list,
+   int id, char *name, char *uuid)
+{
+int i;
+for (i = 0 ; i  list-count ; i++) {
+if( list-doms[i]-id == id 
+STREQ(list-doms[i]-name, name) 
+STREQ(list-doms[i]-uuid, uuid)) {
+
+VIR_FREE(list-doms[i]-name);
+VIR_FREE(list-doms[i]-uuid);
+VIR_FREE(list-doms[i]);
+
+if (i  (list-count - 1))
+memmove(list-doms + i,
+list-doms + i + 1,
+

Re: [libvirt] New Libvirt Implementation - OpenNebula

2008-11-04 Thread Ben Guthro
As part of the internal API (and not explicitly exported from 
src/libvirt_sym.version) The  xml parsing would not be available to external 
apps.

Stefan de Konink wrote on 11/04/2008 11:21 AM:
 Daniel P. Berrange wrote:
 On Tue, Nov 04, 2008 at 05:04:50PM +0100, Stefan de Konink wrote:
 Last time *your* argument was that the API would get too big. Now why
 isn't that argument valid anymore? I'm honestly asking for an
 explanation on this point, and I do expect you have it.

 You are confusing internal API with external API. The external API has
 scalability issues because it is a long term supported ABI. The internal
 API size is irrelevant because we can  will change that at will. The
 domain XML handling API is internal only for in-tree drivers. So there
 has been no change in policy wrt to the external API
 
 Is an external tool able to use the internal XML handling (from a C
 perspective?) or isn't this code exported to the shared library?
 
 
 Stefan
 
 ps. Sorry if you thought I was trying to virtualize a troll.
 
 -- 
 Libvir-list mailing list
 Libvir-list@redhat.com
 https://www.redhat.com/mailman/listinfo/libvir-list

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


Re: [libvirt] [RFC] making (newly public) EventImpl interface more consistent

2008-11-04 Thread Ben Guthro
   I have no strong feeling w.r.t. the reregistration of an fd, I would
 rather error and not state it's undefined though.
   For the java bindings, yes please :-) that way I would be able to
 push a new release too end of next week.

I'd like to get the Xen driver domain events in that release as well.
I'm working through some bugs with these, but I think it should be ready for 
review sometime this week, or beginning of next.

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


Re: [libvirt] PATCH: Misc fixes to events code

2008-11-04 Thread Ben Guthro


Daniel P. Berrange wrote on 11/04/2008 02:56 PM:
 A couple more things I've not fixed but are on the todo list
 
  - THe QEMU driver doesn't emit the ADDED or REMOVED events for VMs
which virt-manager requires in order to fully avoid polling.

Not to derail this topic from your patch...but this comment somewhat relates to 
the xen driver changes I've been looking at.

Currently, I can detect domains being externally created, and destroyed via a 
xenstore watch.

That said - there is no mechanism like @introduceDomain/@releaseDomain for the 
rest of domain lifecycle events. As far as I can tell, these control events 
such as pause/resume, etc are controlled via the xen control(xc) library. I saw 
nothing in this library, or the xend python code that would indicate that 
anything is written in xenstore.

So - I can look into plumbing up the rest of the events in the driver without 
this. This would mean that it could emit events when issued by libvirt, but 
would only issue STARTED, and STOPPED events from external influences like 'xm'

Thoughts?

Ben

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


Re: [libvirt] PATCH: Misc fixes to events code

2008-11-04 Thread Ben Guthro


Daniel P. Berrange wrote on 11/04/2008 04:42 PM:

 Then there is XenAPI in Xen = 3.1.0. We don't currently use XenAPI
 at all, and I'm not up2date on its level of functionality, but in
 the original scope it was intended to provide full event notification
 capabilities for VMs. If the XenAPI event stuff was ever implemented,
 then perhaps we should make use of that, and say older non-XenAPI
 versions only get a limited sub-set of our events ?

ugh.

I tried using xenapi about 8 months ago...

Back then - it was messy, and underdocumented, IMO - and a large reason why  
started to look at libvirt in the first place. 
It seemed...shoe-horned into an existing scheme, with a new API.

There was some effort a little while back to shore this up...but I don't know 
where, or if that really went anywhere.

I think it would be a mistake to integrate that project into this one.

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


Re: [libvirt] PATCH: Misc fixes to events code

2008-11-04 Thread Ben Guthro
These look good to me
+1

Daniel P. Berrange wrote on 11/04/2008 02:56 PM:
 I'm trying out the new events code with virt-manager and stumbled on some
 minor bugs
 
  - The python binding forgot to call LIBVIRT_BEGIN_ALLOW_THREADS,
LIBVIRT_END_ALLOW_THREADS, LIBVIRT_ENSURE_THREAD_STATE or
LIBVIRT_RELEASE_THREAD_STATE which meant virt-manager crashed
and burned in a heap of python interpretor state corruption [1]
 
  - The API docs extracted assumes that enums without explicit value
assignements started from 1 instead of 0.  This caused an off-by-1
error for all the VIR_DOMAIN_EVENT_* constants in the generated python
code.
 
 I briefly toyed with fixing docs/apibuild.py enum handling but then instead
 decided to just change libvirt.h to give explicit values.
 
 With these two fixes and some hacks to virt-manager, I've got the
 events triggering display state refreshes.
 
 A couple more things I've not fixed but are on the todo list
 
  - THe QEMU driver doesn't emit the ADDED or REMOVED events for VMs
which virt-manager requires in order to fully avoid polling.
  - The VIR_EVENT_* constants aren't included in python, because the
API docs can't cope with enum value asignments looking like
(1  0) (ie fails to parse the left-shifts)
 
 Regards,
 Daniel
 
 [1] FYI, i'm using the libvirt-glib python binding in virt-manager
 http://libvirt.org/hg/libvirt-glib/ which is slightly bad too
 by not doing glib thread locking calls, but we're lucky because
 libvirt.so doesn't invoke any glib calls itself from the event
 callback context.
 
 
 Index: python/libvir.c
 ===
 RCS file: /data/cvs/libvirt/python/libvir.c,v
 retrieving revision 1.43
 diff -u -p -r1.43 libvir.c
 --- python/libvir.c   31 Oct 2008 10:13:45 -  1.43
 +++ python/libvir.c   4 Nov 2008 19:45:42 -
 @@ -1537,29 +1537,33 @@ libvirt_virConnectDomainEventCallback(vi
  PyObject *pyobj_ret;
  
  PyObject *pyobj_conn_inst = (PyObject*)opaque;
 -PyObject *pyobj_dom = libvirt_virDomainPtrWrap(dom);
 +PyObject *pyobj_dom;
  
  PyObject *pyobj_dom_args;
  PyObject *pyobj_dom_inst;
  
  PyObject *dom_class;
 +int ret = -1;
 +
 +LIBVIRT_ENSURE_THREAD_STATE;
  
  /* Create a python instance of this virDomainPtr */
 +pyobj_dom = libvirt_virDomainPtrWrap(dom);
  pyobj_dom_args = PyTuple_New(2);
  if(PyTuple_SetItem(pyobj_dom_args, 0, pyobj_conn_inst)!=0) {
  printf(%s error creating tuple,__FUNCTION__);
 -return -1;
 +goto cleanup;
  }
  if(PyTuple_SetItem(pyobj_dom_args, 1, pyobj_dom)!=0) {
  printf(%s error creating tuple,__FUNCTION__);
 -return -1;
 +goto cleanup;
  }
  Py_INCREF(pyobj_conn_inst);
  
  dom_class = getLibvirtDomainClassObject();
  if(!PyClass_Check(dom_class)) {
  printf(%s dom_class is not a class!\n, __FUNCTION__);
 -return -1;
 +goto cleanup;
  }
  
  pyobj_dom_inst = PyInstance_New(dom_class,
 @@ -1571,7 +1575,7 @@ libvirt_virConnectDomainEventCallback(vi
  if(!pyobj_dom_inst) {
  printf(%s Error creating a python instance of virDomain\n, 
 __FUNCTION__);
  PyErr_Print();
 -return -1;
 +goto cleanup;
  }
  
  /* Call the Callback Dispatcher */
 @@ -1586,12 +1590,15 @@ libvirt_virConnectDomainEventCallback(vi
  if(!pyobj_ret) {
  printf(%s - ret:%p\n, __FUNCTION__, pyobj_ret);
  PyErr_Print();
 -return -1;
  } else {
  Py_DECREF(pyobj_ret);
 -return 0;
 +ret = 0;
  }
  
 +
 +cleanup:
 +LIBVIRT_RELEASE_THREAD_STATE;
 +return -1;
  }
  
  static PyObject *
 @@ -1620,10 +1627,14 @@ libvirt_virConnectDomainEventRegister(AT
  
  Py_INCREF(pyobj_conn_inst);
  
 +LIBVIRT_BEGIN_ALLOW_THREADS;
 +
  ret = virConnectDomainEventRegister(conn,
  
 libvirt_virConnectDomainEventCallback,
  (void *)pyobj_conn_inst);
  
 +LIBVIRT_END_ALLOW_THREADS;
 +
  py_retval = libvirt_intWrap(ret);
  return (py_retval);
  }
 @@ -1650,8 +1661,12 @@ libvirt_virConnectDomainEventDeregister(
  
  conn   = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
  
 +LIBVIRT_BEGIN_ALLOW_THREADS;
 +
  ret = virConnectDomainEventDeregister(conn, 
 libvirt_virConnectDomainEventCallback);
  
 +LIBVIRT_END_ALLOW_THREADS;
 +
  Py_DECREF(pyobj_conn_inst);
  py_retval = libvirt_intWrap(ret);
  return (py_retval);
 @@ -1679,13 +1694,15 @@ libvirt_virEventAddHandleFunc  (int fd A
  PyObject *cb_args;
  PyObject *pyobj_args;
  
 +LIBVIRT_ENSURE_THREAD_STATE;
 +
  /* Lookup the python callback */
  python_cb = PyDict_GetItemString(getLibvirtDictObject(),
   eventInvokeHandleCallback);
  if(!python_cb) {
  printf(%s 

RE: [libvirt] [RFC] making (newly public) EventImpl interface moreconsistent

2008-11-04 Thread Ben Guthro
I'll respond now while I'm looking at this, as Dave may not be able to get to 
this until later today

I was talking with Dave about this yesterday, and if I'm not mistaken, this 
idea comes from some of the implementations for either DevKit, DBus, or libHAL 
(I can't remember which one he was looking at at that particular moment) 

Essentially, if I understand the model correctly, they have 2 fd sets - one for 
reading, one for writing.

I could see an additional use where you have multiple callbacks - one for data, 
and one for error handling. These 2 calls to AddHandle would take the sale fd, 
but would have different event mask sets, for the different callbacks.

It does make the model with the timeouts more symmetric.

-Original Message-
From: [EMAIL PROTECTED] on behalf of Daniel P. Berrange
Sent: Tue 11/4/2008 5:10 AM
To: Dave Lively
Cc: libvir-list
Subject: Re: [libvirt] [RFC] making (newly public) EventImpl interface 
moreconsistent
 
On Mon, Nov 03, 2008 at 10:51:36AM -0500, David Lively wrote:
 Hi Folks -
   Since virEvent???RegisterImpl is now public (in libvirt.h), a nagging
 concern of mine has become more urgent.  Essentially this callback gives
 clients a way of registering their own handle (fd) watcher and timer
 functionality for use by libvirt.
   What bugs me is the inconsistency between the handle-watcher and timer
 interfaces: the timer add function returns a timer id, which is then
 used to identify the timer to the update and remove functions.  But
 the handle-watcher add / update / remove functions identify the watcher
 by the handle (fd).  The semantics of registering the same handle twice
 aren't specified (what happens when we pass that same fd in a subsequent
 update or remove?).  Even worse, this doesn't allow one to manage
 multiple watches on the same handle reasonably.

IMHO it doesn't make sense to register 1 file descriptor multiple
times - once the I/O has been processed by one handler, there's 
nothing more another handler can do.

I think there are a few options if the FD is already registered when 
calling 'add'

 - Return an error code
 - Ignore the new request
 - Remove the existing callback
 - Say behaviour is undefined

Trying to define any more complex semantics than this will limit our
ability to integrate with existing event loop implementations. We 
currently defacto do option 3, which is fine provided no libvirt code
ever registered the same FD more than once - which we don't.

I think I'm inclined to stick with saying behaviour is undefined, and
if a libvirt driver needs to somehow process the FD events in multiple
places it can deal with that at a higher level - eg it can register one
callback to get the notifications  perform the I/O, and then fire off
some notifications to the bits of the driver than ned to know when the
I/O is complete.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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

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


RE: [libvirt] Domain Events Python Bindings (Round 2)

2008-10-31 Thread Ben Guthro

Hmmm... I also realized that I never added the example to the top level 
Makefile.am EXTRA_DIST.
I imagine that would need to be resolved to address adding it to the RPM

Would you like me to take a look at this, or will this be something you'll 
resolve as part of the RPM multlib cleanup?

Ben

-Original Message-
From: Daniel Veillard [mailto:[EMAIL PROTECTED]
Sent: Fri 10/31/2008 6:16 AM
To: Ben Guthro
Cc: libvir-list@redhat.com
Subject: Re: [libvirt] Domain Events Python Bindings (Round 2)
 
On Thu, Oct 30, 2008 at 05:03:28PM -0400, Ben Guthro wrote:
 Attached are the python bindings for domain events as previously submitted:
 https://www.redhat.com/archives/libvir-list/2008-October/msg00707.html
 https://www.redhat.com/archives/libvir-list/2008-October/msg00668.html
 
 I have resolved most of the issues Daniel V. commented on
 I also addressed a number of ref counting problems.

  Okidoc, I think that's good to go, so applied and commited :-)
One of the things I need to check/fix is that the examples from
examples/domain-events are also added to the RPMs in the docs
section, i will check this, there is a bit of nastyness to avoid
problem with multilib if not careful.

  thanks a lot !

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
[EMAIL PROTECTED]  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

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


RE: [libvirt] Domain Events Python Bindings (Round 2)

2008-10-31 Thread Ben Guthro

I just took a look over the commit here:
http://git.et.redhat.com/?p=libvirt.git;a=commit;h=471b765ae0fc3efd721d6dbd3c82539880933c0b

It appears that you may have missed adding the new file python/virConnect.py
This file is critical to this patch, as it controls proper callback 
registration, and cleanup coordination with the C code

Ben

-Original Message-
From: Daniel Veillard [mailto:[EMAIL PROTECTED]
Sent: Fri 10/31/2008 7:22 AM
To: Ben Guthro
Cc: libvir-list@redhat.com
Subject: Re: [libvirt] Domain Events Python Bindings (Round 2)
 
On Fri, Oct 31, 2008 at 07:04:09AM -0400, Ben Guthro wrote:
 
 Hmmm... I also realized that I never added the example to the top level 
 Makefile.am EXTRA_DIST.
 I imagine that would need to be resolved to address adding it to the RPM
 
 Would you like me to take a look at this, or will this be something you'll 
 resolve as part of the RPM multlib cleanup?

  I will handle this :-) don't worry !

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
[EMAIL PROTECTED]  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

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


[libvirt] Domain Events Python Bindings (Round 2)

2008-10-30 Thread Ben Guthro
Attached are the python bindings for domain events as previously submitted:
https://www.redhat.com/archives/libvir-list/2008-October/msg00707.html
https://www.redhat.com/archives/libvir-list/2008-October/msg00668.html

I have resolved most of the issues Daniel V. commented on
I also addressed a number of ref counting problems.

 examples/domain-events/events-python/event-test.py |  186 
 python/Makefile.am |5
 python/generator.py|   19
 python/libvir.c|  441 +
 python/libvir.py   |   20
 python/libvirt_wrap.h  |   27 +
 python/types.c |   47 ++
 python/virConnect.py   |   43 ++
 8 files changed, 782 insertions(+), 6 deletions(-)
diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py
new file mode 100755
index 000..7082db0
--- /dev/null
+++ b/examples/domain-events/events-python/event-test.py
@@ -0,0 +1,186 @@
+#!/usr/bin/python -u
+import sys,getopt,os
+import libvirt
+import select
+
+mypoll = select.poll()
+TIMEOUT_MS = 1000
+
+# handle globals
+h_fd   = 0
+h_events   = 0
+h_cb   = None
+h_opaque   = None
+
+# timeout globals
+t_active   = 0
+t_timeout  = -1
+t_cb   = None
+t_opaque   = None
+
+#
+# Callback Functions
+#
+def eventToString(event):
+eventStrings = ( Added,
+ Removed,
+ Started,
+ Suspended,
+ Resumed,
+ Stopped,
+ Saved,
+ Restored );
+return eventStrings[event];
+
+def myDomainEventCallback1 (conn, dom, event, opaque):
+print myDomainEventCallback1 EVENT: Domain %s(%s) %s % (dom.name(), dom.ID(), eventToString(event))
+
+def myDomainEventCallback2 (conn, dom, event, opaque):
+print myDomainEventCallback2 EVENT: Domain %s(%s) %s % (dom.name(), dom.ID(), eventToString(event))
+
+#
+# EventImpl Functions
+#
+def myEventHandleTypeToPollEvent(events):
+ret = 0
+if events  libvirt.VIR_EVENT_HANDLE_READABLE:
+ret |= select.POLLIN
+if events  libvirt.VIR_EVENT_HANDLE_WRITABLE:
+ret |= select.POLLOUT
+if events  libvirt.VIR_EVENT_HANDLE_ERROR:
+ret |= select.POLLERR;
+if events  libvirt.VIR_EVENT_HANDLE_HANGUP:
+ret |= select.POLLHUP;
+return ret
+
+def myPollEventToEventHandleType(events):
+ret = 0;
+if events  select.POLLIN:
+ret |= libvirt.VIR_EVENT_HANDLE_READABLE;
+if events  select.POLLOUT:
+ret |= libvirt.VIR_EVENT_HANDLE_WRITABLE;
+if events  select.POLLERR:
+ret |= libvirt.VIR_EVENT_HANDLE_ERROR;
+if events  select.POLLHUP:
+ret |= libvirt.VIR_EVENT_HANDLE_HANGUP;
+return ret;
+
+def myAddHandle(fd, events, cb, opaque):
+global h_fd, h_events, h_cb, h_opaque
+#print Adding Handle %s %s %s %s % (str(fd), str(events), str(cb), str(opaque))
+h_fd = fd
+h_events = events
+h_cb = cb
+h_opaque = opaque
+
+mypoll.register(fd, myEventHandleTypeToPollEvent(events))
+
+def myUpdateHandle(fd, event):
+global h_fd, h_events
+#print Updating Handle %s %s % (str(fd), str(events))
+h_fd = fd
+h_events = event
+mypoll.unregister(fd)
+mypoll.register(fd, myEventHandleTypeToPollEvent(event))
+
+def myRemoveHandle(fd):
+global h_fd
+#print Removing Handle %s % str(fd)
+h_fd = 0
+mypoll.unregister(fd)
+
+def myAddTimeout(timeout, cb, opaque):
+global t_active, t_timeout, t_cb, t_opaque
+#print Adding Timeout %s %s %s % (str(timeout), str(cb), str(opaque))
+t_active = 1;
+t_timeout = timeout;
+t_cb = cb;
+t_opaque = opaque;
+
+def myUpdateTimeout(timer, timeout):
+global t_timeout
+#print Updating Timeout %s % (str(timer), str(timeout))
+t_timeout = timeout;
+
+def myRemoveTimeout(timer):
+global t_active
+#print Removing Timeout %s % str(timer)
+t_active = 0;
+
+##
+# Main
+##
+
+def usage():
+print usage: +os.path.basename(sys.argv[0])+ [uri]
+printuri will default to qemu:///system
+
+def main():
+try:
+opts, args = getopt.getopt(sys.argv[1:], h, [help] )
+except getopt.GetoptError, err:
+# print help information and exit:
+print str(err) # will print something like option -a not recognized
+usage()
+sys.exit(2)
+for o, a in opts:
+if o in (-h, --help):
+usage()
+sys.exit()
+
+if len(sys.argv)  1:
+uri = 

RE: [libvirt] [RFC] domain-events-python

2008-10-29 Thread Ben Guthro

One issue that I seem to be running into for both dom, and conn objects is the 
creation of a python object from the C vir{Connect,Domain}Ptr

The issue is that when creating a python object, and passing _obj into the 
constructor - it will give a different python object each time, instead of 
searching for an existing object, and bumping the ref count.

For example - each time the C callback would be called, we would create a new 
python object with the came ._o, rather than getting a new reference to a 
common one

This is not an issue unless we want to store data in the python object 
independent from C object (like the python callback list)

So...we could create a hash/dict object of virConnect objects...but when would 
you know to delete the last reference?




-Original Message-
From: Daniel Veillard [mailto:[EMAIL PROTECTED]
Sent: Wed 10/29/2008 2:50 AM
To: Daniel P. Berrange
Cc: Ben Guthro; libvir-list@redhat.com
Subject: Re: [libvirt] [RFC] domain-events-python
 
On Tue, Oct 28, 2008 at 06:23:20PM +, Daniel P. Berrange wrote:
 On Tue, Oct 28, 2008 at 09:09:53AM -0400, Ben Guthro wrote:
  Attached is a preliminary patch implementing the python bindings for 
  domain events, and the EventImpl code.
  
  This implements a python test app equivalent to the code in the C 
  event-test app. Contrary to what Daniel B originally suggested, I thought 
  that the EventImpl would be useful to expose for apps that are strictly 
  using python, and not integrating with glib, or another event loop. It 
  also makes the test case easier to debug.
 
 That's a good idea - does make it easier to debug.

  yes +1 definitely

  I have not marked this with [PATCH] in the subject, as I don't believe 
  it is quite complete. 
  
  I am still having a few issues with the Refcounting in the C code, and 
  I think there is still some cleanup code I haven't quite handled quite 
  right.
  
  That said - I would welcome some comments/suggestions on this thus far,
  to make sure I'm not going off in a direction contrary to where you 
  think I should be.
 
 I think my main thought would be to try and domore of the event
 dispatch work in the python layer, rather than C layer. So rather
 than doing the de-multiplexing to all registered callbacks in
 libvirt_virConnectDomainEventCallback, have that C method call
 into a python  virConnectDomainEventCallback function, and have
 that de-multiplex the events out to all application callbacks.
 I think it'd probably make the code a little easier to follow,
 and might simplify the ref counting problems.
 
 Likewise I think I'd also keep more of the 'DomainEventRegister' and
 'Unregister' impl in the python layer. Perhaps keeping the list of
 callbacks as an attribute in the 'class virConnect', rather than the
 static global variable pyobj_domain_event_cbs.

  Agreed too, since we don't care too much about performances in that
code it is really easier to implement and debug if most of the logic is
done in Python rather than C.
  The reference counting problem in callback based interfaces can be
nasty as I found out in libxml2, that too can be simplified greatly by
doing most of the work on the python side.

  thanks !

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
[EMAIL PROTECTED]  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

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


Re: [libvirt] PATCH: Move domain event helpers out of internal.h/libvirt.c

2008-10-29 Thread Ben Guthro
I like this much better than where I had put everything.
Makes much more sense to encapsulate it in its own file/header

+1


Daniel P. Berrange wrote on 10/29/2008 08:06 AM:
 There are a bunch of helper functions relating to domain events, which
 are only used internally by hypervisor drivers. Following the principle
 that libvirt.c should only contain functions exported in the API, and
 internal.h should not define any function signatures, these helpers
 need to move.
 
 So I'm inventing a domain_events.c, and domain_events.h file to contain
 the domain events helper code, in much same way as domain_conf.c and
 domain_conf.h contain the domain XML helper code.
 
 Again no functional change here. With this patch applied, the cleanup
 of internal.h is basically complete - at least more than good enough
 for now. It'd be nice to move the struct definitions of virDomainPtr,
 etc elsewhere, perhaps to src/libvirt.h because they're public API,
 but not exported publically.
 
  b/src/domain_event.c  |  229 
 ++
  b/src/domain_event.h  |   83 ++
  qemud/event.c |8 -
  qemud/event.h |7 +
  src/Makefile.am   |1 
  src/internal.h|   73 ---
  src/libvirt.c |  201 ---
  src/qemu_conf.h   |1 
  src/remote_internal.c |1 
  9 files changed, 326 insertions(+), 278 deletions(-)
 
 Daniel
 
 diff -r 0325a25d1762 qemud/event.c
 --- a/qemud/event.c   Wed Oct 29 11:48:08 2008 +
 +++ b/qemud/event.c   Wed Oct 29 12:03:29 2008 +
 @@ -489,7 +489,7 @@
  }
  
  int
 -__virEventHandleTypeToPollEvent(virEventHandleType events)
 +virEventHandleTypeToPollEvent(int events)
  {
  int ret = 0;
  if(events  VIR_EVENT_HANDLE_READABLE)
 @@ -503,10 +503,10 @@
  return ret;
  }
  
 -virEventHandleType
 -__virPollEventToEventHandleType(int events)
 +int
 +virPollEventToEventHandleType(int events)
  {
 -virEventHandleType ret = 0;
 +int ret = 0;
  if(events  POLLIN)
  ret |= VIR_EVENT_HANDLE_READABLE;
  if(events  POLLOUT)
 diff -r 0325a25d1762 qemud/event.h
 --- a/qemud/event.h   Wed Oct 29 11:48:08 2008 +
 +++ b/qemud/event.h   Wed Oct 29 12:03:29 2008 +
 @@ -105,4 +105,11 @@
   */
  int virEventRunOnce(void);
  
 +int
 +virEventHandleTypeToPollEvent(int events);
 +int
 +virPollEventToEventHandleType(int events);
 +
 +
 +
  #endif /* __VIRTD_EVENT_H__ */
 diff -r 0325a25d1762 src/Makefile.am
 --- a/src/Makefile.am Wed Oct 29 11:48:08 2008 +
 +++ b/src/Makefile.am Wed Oct 29 12:03:29 2008 +
 @@ -150,6 +150,7 @@
   hash.c hash.h   \
   internal.h  \
   libvirt.c   \
 + domain_event.c domain_event.h   \
   $(GENERIC_LIB_SOURCES)  \
   $(DOMAIN_CONF_SOURCES)  \
   $(NETWORK_CONF_SOURCES) \
 diff -r 0325a25d1762 src/domain_event.c
 --- /dev/null Thu Jan 01 00:00:00 1970 +
 +++ b/src/domain_event.c  Wed Oct 29 12:03:29 2008 +
 @@ -0,0 +1,229 @@
 +/*
 + * domain_event.c: domain event queue processing helpers
 + *
 + * Copyright (C) 2008 VirtualIron
 + *
 + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 + *
 + * Author: Ben Guthro
 + */
 +
 +#include config.h
 +
 +#include domain_event.h
 +#include libvirt.h
 +#include memory.h
 +
 +
 +/**
 + * virDomainEventCallbackListFree:
 + * @list: event callback list head
 + *
 + * Free the memory in the domain event callback list
 + */
 +void
 +virDomainEventCallbackListFree(virDomainEventCallbackListPtr list)
 +{
 +int i;
 +for (i=0; ilist-count; i++) {
 +VIR_FREE(list-callbacks[i]);
 +}
 +VIR_FREE(list);
 +}
 +/**
 + * virDomainEventCallbackListRemove:
 + * @conn: pointer to the connection
 + * @cbList: the list
 + * @callback: the callback to remove
 + *
 + * Internal function to remove a callback from a 
 virDomainEventCallbackListPtr
 + */
 +int
 +virDomainEventCallbackListRemove(virConnectPtr conn,
 + virDomainEventCallbackListPtr

[libvirt] [PATCH] Domain Events Python Bindings

2008-10-29 Thread Ben Guthro
Attached are the python bindings for domain events

I have moved much of the complicated code from my prior submission out of C and 
into python.

This required a slight change to the generator.
The new convention that we came up with is to append classname.py to the 
class as it is being generated, iff that file exists.

 examples/domain-events/events-python/event-test.py |  186 +
 python/generator.py|   16
 python/libvir.c|  410 +
 python/libvir.py   |   20 +
 python/libvirt_wrap.h  |   27 +
 python/types.c |   47 ++
 python/virConnect.py   |   46 ++
 7 files changed, 747 insertions(+), 5 deletions(-)
diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py
new file mode 100755
index 000..ac53196
--- /dev/null
+++ b/examples/domain-events/events-python/event-test.py
@@ -0,0 +1,186 @@
+#!/usr/bin/python -u
+import sys,getopt,os
+import libvirt
+import select
+
+mypoll = select.poll()
+TIMEOUT_MS = 1000
+
+# handle globals
+h_fd   = 0
+h_events   = 0
+h_cb   = None
+h_opaque   = None
+
+# timeout globals
+t_active   = 0
+t_timeout  = -1
+t_cb   = None
+t_opaque   = None
+
+#
+# Callback Functions
+#
+def eventToString(event):
+eventStrings = ( Added,
+ Removed,
+ Started,
+ Suspended,
+ Resumed,
+ Stopped,
+ Saved,
+ Restored );
+return eventStrings[event];
+
+def myDomainEventCallback1 (conn, dom, event, opaque):
+print myDomainEventCallback1 EVENT: Domain %s(%s) %s % (dom.name(), dom.ID(), eventToString(event))
+
+def myDomainEventCallback2 (conn, dom, event, opaque):
+print myDomainEventCallback2 EVENT: Domain %s(%s) %s % (dom.name(), dom.ID(), eventToString(event))
+
+#
+# EventImpl Functions
+#
+def myEventHandleTypeToPollEvent(events):
+ret = 0
+if events  libvirt.VIR_EVENT_HANDLE_READABLE:
+ret |= select.POLLIN
+if events  libvirt.VIR_EVENT_HANDLE_WRITABLE:
+ret |= select.POLLOUT
+if events  libvirt.VIR_EVENT_HANDLE_ERROR:
+ret |= select.POLLERR;
+if events  libvirt.VIR_EVENT_HANDLE_HANGUP:
+ret |= select.POLLHUP;
+return ret
+
+def myPollEventToEventHandleType(events):
+ret = 0;
+if events  select.POLLIN:
+ret |= libvirt.VIR_EVENT_HANDLE_READABLE;
+if events  select.POLLOUT:
+ret |= libvirt.VIR_EVENT_HANDLE_WRITABLE;
+if events  select.POLLERR:
+ret |= libvirt.VIR_EVENT_HANDLE_ERROR;
+if events  select.POLLHUP:
+ret |= libvirt.VIR_EVENT_HANDLE_HANGUP;
+return ret;
+
+def myAddHandle(fd, events, cb, opaque):
+global h_fd, h_events, h_cb, h_opaque
+#print Adding Handle %s %s %s %s % (str(fd), str(events), str(cb), str(opaque))
+h_fd = fd
+h_events = events
+h_cb = cb
+h_opaque = opaque
+
+mypoll.register(fd, myEventHandleTypeToPollEvent(events))
+
+def myUpdateHandle(fd, event):
+global h_fd, h_events
+#print Updating Handle %s %s % (str(fd), str(events))
+h_fd = fd
+h_events = event
+mypoll.unregister(fd)
+mypoll.register(fd, myEventHandleTypeToPollEvent(event))
+
+def myRemoveHandle(fd):
+global h_fd
+#print Removing Handle %s % str(fd)
+h_fd = 0
+mypoll.unregister(fd)
+
+def myAddTimeout(timeout, cb, opaque):
+global t_active, t_timeout, t_cb, t_opaque
+#print Adding Timeout %s %s %s % (str(timeout), str(cb), str(opaque))
+t_active = 1;
+t_timeout = cb;
+t_cb = cb;
+t_opaque = opaque;
+
+def myUpdateTimeout(timer, timeout):
+global t_timeout
+#print Updating Timeout %s % (str(timer), str(timeout))
+t_timeout = timeout;
+
+def myRemoveTimeout(timer):
+global t_active
+#print Removing Timeout %s % str(timer)
+t_active = 0;
+
+##
+# Main
+##
+
+def usage():
+print usage: +os.path.basename(sys.argv[0])+ [uri]
+printuri will default to qemu:///system
+
+def main():
+try:
+opts, args = getopt.getopt(sys.argv[1:], h, [help] )
+except getopt.GetoptError, err:
+# print help information and exit:
+print str(err) # will print something like option -a not recognized
+usage()
+sys.exit(2)
+for o, a in opts:
+if o in (-h, --help):
+usage()
+sys.exit()
+
+if len(sys.argv)  1:
+uri = sys.argv[1]
+else:
+uri = qemu:///system
+
+print 

Re: [libvirt] [PATCH] Domain Events Python Bindings

2008-10-29 Thread Ben Guthro
Comments inline below

Daniel Veillard wrote on 10/29/2008 01:09 PM:
...
 +def myDomainEventCallback1 (conn, dom, event, opaque):
 +print myDomainEventCallback1 EVENT: Domain %s(%s) %s % (dom.name(), 
 dom.ID(), eventToString(event))
 +
 +def myDomainEventCallback2 (conn, dom, event, opaque):
 +print myDomainEventCallback2 EVENT: Domain %s(%s) %s % (dom.name(), 
 dom.ID(), eventToString(event))
 
 Thinking out loud, maybe we should allow dom to be NULL/None in
 examples, if we extend the API later to add node related events dom
 would be NULL, isn't it 

I was under the impression that re-use of this API was undesired, and that the 
events API would be extended to call out each event class explicitly (IIRC, 
Daniel B suggested this)

If we were to extend the API, there would be a 
virConnectNodeEventRegister/Deregister
and associated callbacks, with their own signatures.
So - we would not be mxing NodeEventCallbacks, and DomainEventCallbacks with 
the same python code.




 [...]
 +##
 +# Main
 +##
 +
 +def usage():
 +print usage: +os.path.basename(sys.argv[0])+ [uri]
 +printuri will default to qemu:///system
 
   ideally for regression testing it would be nice to be able to provide
 a test driver definition, but augmented with an emulated scenario,
 things like:
   scenario
 event type=start
 domain type='test2'
   nametest2/name
   memory512000/memory
   currentMemory512000/currentMemory
   vcpu2/vcpu
   os
 type arch='i686'hvm/type
 boot dev='hd'/
   /os
 /domain
 /event
 event type=pause
   domain name=test/
 /event
 event type=resume
   domain name=test/
 /event
 event type=destroy
   domain name=test2/
 /event
   /scenario

I really have no knowledge of how the test driver works, or how to design a 
test of this code. Ad discussed in an earlier thread - since this event code 
depends on OS state, I made no effort to design tests to exercise the code, 
beyond the example app. While I agree that a regression test would be 
desirable, I really don't know how that would be accomplished.

...


 +static PyObject *
 +libvirt_virEventRegisterImpl(ATTRIBUTE_UNUSED PyObject * self,
 + PyObject * args)
 +{
 +Py_XDECREF(addHandleObj);
 +Py_XDECREF(updateHandleObj);
 +Py_XDECREF(removeHandleObj);
 +Py_XDECREF(addTimeoutObj);
 +Py_XDECREF(updateTimeoutObj);
 +Py_XDECREF(removeTimeoutObj);
  
   hum, maybe the ParseTuple should be done before onto temporary
 variables and then only DECREF, right now if the parse fails, then
 the next event may lead to a crash due to garbage collected code :-)


hmmm...maybe I'm misunderstanding how XDECREF works...I thought it would not 
dec the ref if the object was NULL

Other than the above comments, I think the other suggestions are good ones. 
I'll take a look.

Ben

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


Re: [libvirt] [PATCH] Domain Events Python Bindings

2008-10-29 Thread Ben Guthro


Daniel Veillard wrote on 10/29/2008 01:09 PM:
 +/* Call the Callback Dispatcher */
 +pyobj_ret = PyObject_CallMethod(pyobj_conn_inst,
 +(char*)dispatchDomainEventCallbacks,
 +(char*)Oi,
 +pyobj_dom_inst,
 +event);
 +
 +Py_DECREF(pyobj_dom_inst);
 +Py_DECREF(pyobj_conn_inst);
 
   We should make clear that the python callback can't keep any reference
 to the domain.
   Maybe the solution is to pass a name or UUID string and let the python
 user do the lookup, might also avoid the object duplication (but then
 the user will do the dictionary of domains and get into the same
 problems of object lifetime) I hate asynch interfaces :-)
 

If the callback keeps a reference, then python will reference count it, and 
this will not get garbage collected until it gives up the last reference... am 
I misunderstanding something?

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


Re: [libvirt] FYI: fixes to events code for mingw

2008-10-24 Thread Ben Guthro


Daniel Veillard wrote on 10/24/2008 09:26 AM:
   since we don't use poll anywhere there i assume it's a leftover from
 the early event work.

Yes, this was mistakenly left in from prior versions of the patch
 

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


Re: [libvirt] [PATCH 00/12] Domain Events : DONE !

2008-10-23 Thread Ben Guthro
 Again congratulations ! I think this also means the next release
 will be a 0.5.0 since this is a major API addition. I still looking
 at the other pending patches though, it would be better to have them
 in the next release ... oh and I want your java bindings and we need
 Python too  (and QPid !) :-)

Great news!
I'm just starting to look at the Python bindings...tryng to wrap my head around 
this whole process. Java will come after this, though I haven't even begun to 
look at it. As for Qpid... I suppose that will come after all the others. I've 
been mostly ignoring this, hoping I wouldn't have to know the gory 
details...but I guess that's unavoidable.

Dave Lively's patches for HAL, and DevKit have some java bindings that are 
mostly done...I think submitting them are still on his TODO list. Are these the 
ones you are referring to?

Thanks for accepting the patches!

Ben

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


Re: [libvirt] [PATCH 00/12] Domain Events : DONE !

2008-10-23 Thread Ben Guthro
Also - 

Additional work is needed in the hypervisor drivers other than qemu to properly 
emit domain events.

My initial patch submission included some code designed to add, and monitor 
xenstore watches. It would be nice to get this integrated, as well.



Ben Guthro wrote on 10/23/2008 09:40 AM:
 Again congratulations ! I think this also means the next release
 will be a 0.5.0 since this is a major API addition. I still looking
 at the other pending patches though, it would be better to have them
 in the next release ... oh and I want your java bindings and we need
 Python too  (and QPid !) :-)
 
 Great news!
 I'm just starting to look at the Python bindings...tryng to wrap my head 
 around this whole process. Java will come after this, though I haven't even 
 begun to look at it. As for Qpid... I suppose that will come after all the 
 others. I've been mostly ignoring this, hoping I wouldn't have to know the 
 gory details...but I guess that's unavoidable.
 
 Dave Lively's patches for HAL, and DevKit have some java bindings that are 
 mostly done...I think submitting them are still on his TODO list. Are these 
 the ones you are referring to?
 
 Thanks for accepting the patches!
 
 Ben
 
 --
 Libvir-list mailing list
 Libvir-list@redhat.com
 https://www.redhat.com/mailman/listinfo/libvir-list

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


Re: [libvirt] Re: [PATCH 01/12] Domain Events - Public API

2008-10-22 Thread Ben Guthro


Daniel Veillard wrote on 10/22/2008 05:14 AM:
 thanks for the changes! I think the prototypes are good to go, maybe a couple
 tiny changes but I can make them myself based on the 'make rebuild'
 output in the doc directory
 functions in src/libvirt.c still need arguments checkings however, but
 I can add that later.

Are these changes worth a 4th round of submissions - or is this something that 
can be taken care of in a follow-up patch?


 +/**
 + * virEventHandleCallback: callback for receiving file handle events
 
   description just need to be moved after the parameters, can be
   trivially done later.
 
 + * @fd: file handle on which the event occurred
 + * @events: bitset of events from virEventHandleType constants
 + * @opaque: user data registered with handle
 + */
 +typedef void (*virEventHandleCallback)(int fd, virEventHandleType events,
 +   void *opaque);
 +/**
 + * virConnectDomainEventRegister:
 + * @conn: pointer to the connection
 + * @cb: callback to the function handling domain events
 + * @opaque: opaque data to pass on to the callback
 + *
 + * Adds a Domain Event Callback
 + *
 + * Returns 0 on success, -1 on failure
 + */
 +int
 +virConnectDomainEventRegister(virConnectPtr conn,
 +  virConnectDomainEventCallback cb,
 +  void *opaque)
 +{
 
conn still need to be checked  with the standard block
 
 if (!VIR_IS_CONNECT(conn)) {
 virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
 return (-1);
 }
 
 like every other public functions with a conn parameter in src/libvirt.c
 What if cb is NULL, that probably need to be rejected
 
 +/* Registering for a domain callback will enable delivery by default */
 +if (conn-driver  conn-driver-domainEventRegister)
 +return conn-driver-domainEventRegister (conn, cb, opaque);
 +return -1;
 +}
 +
 +/**
 + * virConnectDomainEventDeregister:
 + * @conn: pointer to the connection
 + * @cb: callback to the function handling domain events
 + *
 + * Removes a Domain Event Callback
 + *
 + * Returns 0 on success, -1 on failure
 + */
 +int
 +virConnectDomainEventDeregister(virConnectPtr conn,
 +virConnectDomainEventCallback cb)
 +{
 
   same thing for VIR_IS_CONNECT and cb being NULL tests
 
 otherwise looks fine to me.
 
 Daniel
 
 

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


Re: [libvirt] errors building rpm

2008-10-22 Thread Ben Guthro
This looks like it fixed the problem for me, as well

Thanks!

+1


Cole Robinson wrote on 10/22/2008 09:31 AM:
 Daniel P. Berrange wrote:
 On Tue, Oct 21, 2008 at 04:39:36PM -0400, Ben Guthro wrote:
 I keep getting the following error when trying to build via a
 'sudo make rpm' on the tip of the tree

 + /usr/lib/rpm/find-lang.sh /var/tmp/libvirt-0.4.6-1.fc9-root libvirt
 No translations found for libvirt in /var/tmp/libvirt-0.4.6-1.fc9-root
 error: Bad exit status from /var/tmp/rpm-tmp.82848 (%install)


 RPM build errors:
 Bad exit status from /var/tmp/rpm-tmp.82848 (%install)
 make: *** [rpm] Error 1


 This looks like it came in with one of Jim Meyering's latest checkins.
 Looks like it probably failed to include any of the .po files. I see
 Jim's change was essentially

 ALL_LINGUAS=`{cd po  /dev/null  ls *.po} | sed 's+\.po$++'`

 to

 ALL_LINGUAS=`{cd $srcdir/po  /dev/null  ls *.po} | sed 's+\.po$++'`


 So my expectation is that '$srcdir' is not defined, and thus its trying
 to use '/po' to find po files.

 Daniel
 
 I hit this last night. Attached patch fixed it for me, not
 sure if it breaks anything in subtle ways though. The actual
 error it's throwing is something like '{cd' command not found
 
 Thanks,
 Cole
 

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


Re: [libvirt] Re: [PATCH 04/12] Domain Events - rpc changes

2008-10-21 Thread Ben Guthro
This is very similar to what I had in the original patch,
where on the server side, we just increment/decrement a callback_registered 
counter,
then keep the list of callbacks/opaque data on the client.

The server would then send one rpc to each connected client, whose job it would 
be
to multiplex this out to all registered callbacks.

There would still be a one-for-one for register/deregister, but this scheme 
has the following advantages for efficency:
a.) Fewer RPC calls (less data on the wire - one-to-many for events firing)
b.) Less RPC data passed on register/deregister (no need for cb/user_data)
c.) Code is simpler - no need to invent yet another data structure, and list 
for tracking tokens

Daniel - what are your thoughts on this? 
This is similar to what I had originally implemented, but I'm not sure if you 
objected to this part of it, or not...

Ben


David Lively wrote on 10/20/2008 04:05 PM:
 On Sun, 2008-10-19 at 20:22 +0100, Daniel P. Berrange wrote:
 On Fri, Oct 17, 2008 at 11:58:15AM -0400, Ben Guthro wrote:
 Changes to the RPC protocol

 +struct remote_domain_event_ret {
 +remote_nonnull_domain dom;
 +int event;
 +unsigned long int callback;
 +unsigned long int user_data;
 +};
 Using a 'unsigned long int' field to transmit the raw pointer feels a little
 wrong to me. Could we have the client side pass a simple integer 'token' when
 registering / unregistering, and have that 'token' passed back by the server
 in the actual event. The client could use this token to lookup the callback
 and user_data. 
 
 Hold on.  We can (and IMO should) quite easily avoid both this lookup
 and the passing of the callback pointer to the server:
 
 Suppose we have the same client registered for two different domain
 event callbacks.  In the current patch, the server will send two RPCs
 per event, one for each callback (which the client then unmarshals,
 casts, and calls).
 
 But what if we sent just one RPC per event ( per client) and had the
 client walk its list of callbacks (which we'll need to track on the
 client side anyway, if we're not sending the data over the wire)?  We
 *always* make *all* the callbacks on the list, so there's no point in
 making individual RPCs to fire off each callback individually.  This
 gets rid of the need to send callback/user_data over the wire, and also
 doesn't require tokenization (which is all just extra overhead in this
 case).
 
 remote_domain_events_register/deregister_args structs will go away.
 remoteDispatchhDomainEventsRegister/Deregister will simply inc/dec a
 value, sending events only when the value is 0.
 
 While I'm not sure I've described this very well, I feel pretty strongly
 that it's the right way to go.  If my explanation isn't clear, please
 get back to me ...
 
 Dave
 

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


[libvirt] Re: [PATCH 03/12] Domain Events - daemon changes

2008-10-21 Thread Ben Guthro
[PATCH 03/12] Domain Events - daemon changes
This code changes the daemaon to:
  use the pulic def of virEventRegisterImpl
  Add functionality to dispatch events to connected remote drivers

 event.c  |   21 +
 event.h  |5 +-
 mdns.c   |   15 --
 qemud.c  |   72 ---
 qemud.h  |   11 
 remote.c |  143 +++
 6 files changed, 227 insertions(+), 40 deletions(-)
diff --git a/qemud/event.c b/qemud/event.c
index bb1f381..f391cd1 100644
--- a/qemud/event.c
+++ b/qemud/event.c
@@ -38,7 +38,7 @@
 /* State for a single file handle being monitored */
 struct virEventHandle {
 int fd;
-int events;
+virEventHandleType events;
 virEventHandleCallback cb;
 void *opaque;
 int deleted;
@@ -74,13 +74,13 @@ static struct virEventLoop eventLoop;
 /* Unique ID for the next timer to be registered */
 static int nextTimer = 0;
 
-
 /*
  * Register a callback for monitoring file handle events.
  * NB, it *must* be safe to call this from within a callback
  * For this reason we only ever append to existing list.
  */
-int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *opaque) {
+int virEventAddHandleImpl(int fd, virEventHandleType events,
+  virEventHandleCallback cb, void *opaque) {
 EVENT_DEBUG(Add handle %d %d %p %p, fd, events, cb, opaque);
 if (eventLoop.handlesCount == eventLoop.handlesAlloc) {
 EVENT_DEBUG(Used %d handle slots, adding %d more,
@@ -92,7 +92,8 @@ int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *o
 }
 
 eventLoop.handles[eventLoop.handlesCount].fd = fd;
-eventLoop.handles[eventLoop.handlesCount].events = events;
+eventLoop.handles[eventLoop.handlesCount].events =
+ virEventHandleTypeToPollEvent(events);
 eventLoop.handles[eventLoop.handlesCount].cb = cb;
 eventLoop.handles[eventLoop.handlesCount].opaque = opaque;
 eventLoop.handles[eventLoop.handlesCount].deleted = 0;
@@ -102,11 +103,12 @@ int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *o
 return 0;
 }
 
-void virEventUpdateHandleImpl(int fd, int events) {
+void virEventUpdateHandleImpl(int fd, virEventHandleType events) {
 int i;
 for (i = 0 ; i  eventLoop.handlesCount ; i++) {
 if (eventLoop.handles[i].fd == fd) {
-eventLoop.handles[i].events = events;
+eventLoop.handles[i].events =
+virEventHandleTypeToPollEvent(events);
 break;
 }
 }
@@ -342,6 +344,7 @@ static int virEventDispatchTimeouts(void) {
  */
 static int virEventDispatchHandles(struct pollfd *fds) {
 int i;
+virEventHandleType hEvents;
 /* Save this now - it may be changed during dispatch */
 int nhandles = eventLoop.handlesCount;
 
@@ -352,8 +355,10 @@ static int virEventDispatchHandles(struct pollfd *fds) {
 }
 
 if (fds[i].revents) {
-EVENT_DEBUG(Dispatch %d %d %p, fds[i].fd, fds[i].revents, eventLoop.handles[i].opaque);
-(eventLoop.handles[i].cb)(fds[i].fd, fds[i].revents,
+hEvents = virPollEventToEventHandleType(fds[i].revents);
+EVENT_DEBUG(Dispatch %d %d %p, fds[i].fd, fds[i].revents,
+eventLoop.handles[i].opaque);
+(eventLoop.handles[i].cb)(fds[i].fd, hEvents,
   eventLoop.handles[i].opaque);
 }
 }
diff --git a/qemud/event.h b/qemud/event.h
index adf7b6d..3fff617 100644
--- a/qemud/event.h
+++ b/qemud/event.h
@@ -36,7 +36,8 @@
  *
  * returns -1 if the file handle cannot be registered, 0 upon success
  */
-int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *opaque);
+int virEventAddHandleImpl(int fd, virEventHandleType events,
+  virEventHandleCallback cb, void *opaque);
 
 /**
  * virEventUpdateHandleImpl: change event set for a monitored file handle
@@ -46,7 +47,7 @@ int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *o
  *
  * Will not fail if fd exists
  */
-void virEventUpdateHandleImpl(int fd, int events);
+void virEventUpdateHandleImpl(int fd, virEventHandleType events);
 
 /**
  * virEventRemoveHandleImpl: unregister a callback from a file handle
diff --git a/qemud/mdns.c b/qemud/mdns.c
index 9147946..df1b6c9 100644
--- a/qemud/mdns.c
+++ b/qemud/mdns.c
@@ -228,17 +228,20 @@ static void libvirtd_mdns_client_callback(AvahiClient *c, AvahiClientState state
 }
 
 
-static void libvirtd_mdns_watch_dispatch(int fd, int events, void *opaque)
+static void libvirtd_mdns_watch_dispatch(int fd, virEventHandleType events, 
+ void *opaque)
 {
 AvahiWatch *w = (AvahiWatch*)opaque;
-AVAHI_DEBUG(Dispatch watch FD %d Event %d, fd, events);
-w-revents = events;
-w-callback(w, fd, events, 

[libvirt] Re: [PATCH 04/12] Domain Events - rpc changes

2008-10-21 Thread Ben Guthro
[PATCH 04/12] Domain Events - rpc changes
Changes to the RPC protocol

 remote_dispatch_localvars.h   |3 +++
 remote_dispatch_proc_switch.h |   18 ++
 remote_dispatch_prototypes.h  |3 +++
 remote_protocol.c |   29 +
 remote_protocol.h |   25 +
 remote_protocol.x |   25 -
 6 files changed, 102 insertions(+), 1 deletion(-)
diff --git a/qemud/remote_dispatch_localvars.h b/qemud/remote_dispatch_localvars.h
index f46b493..505fb30 100644
--- a/qemud/remote_dispatch_localvars.h
+++ b/qemud/remote_dispatch_localvars.h
@@ -6,6 +6,7 @@ remote_domain_lookup_by_uuid_args lv_remote_domain_lookup_by_uuid_args;
 remote_domain_lookup_by_uuid_ret lv_remote_domain_lookup_by_uuid_ret;
 remote_storage_pool_list_volumes_args lv_remote_storage_pool_list_volumes_args;
 remote_storage_pool_list_volumes_ret lv_remote_storage_pool_list_volumes_ret;
+remote_domain_events_deregister_ret lv_remote_domain_events_deregister_ret;
 remote_domain_shutdown_args lv_remote_domain_shutdown_args;
 remote_list_defined_domains_args lv_remote_list_defined_domains_args;
 remote_list_defined_domains_ret lv_remote_list_defined_domains_ret;
@@ -20,6 +21,7 @@ remote_domain_get_autostart_args lv_remote_domain_get_autostart_args;
 remote_domain_get_autostart_ret lv_remote_domain_get_autostart_ret;
 remote_domain_set_vcpus_args lv_remote_domain_set_vcpus_args;
 remote_get_hostname_ret lv_remote_get_hostname_ret;
+remote_domain_events_register_ret lv_remote_domain_events_register_ret;
 remote_network_undefine_args lv_remote_network_undefine_args;
 remote_domain_create_args lv_remote_domain_create_args;
 remote_network_destroy_args lv_remote_network_destroy_args;
@@ -121,6 +123,7 @@ remote_num_of_defined_storage_pools_ret lv_remote_num_of_defined_storage_pools_r
 remote_domain_core_dump_args lv_remote_domain_core_dump_args;
 remote_list_defined_storage_pools_args lv_remote_list_defined_storage_pools_args;
 remote_list_defined_storage_pools_ret lv_remote_list_defined_storage_pools_ret;
+remote_domain_event_ret lv_remote_domain_event_ret;
 remote_domain_get_max_memory_args lv_remote_domain_get_max_memory_args;
 remote_domain_get_max_memory_ret lv_remote_domain_get_max_memory_ret;
 remote_num_of_domains_ret lv_remote_num_of_domains_ret;
diff --git a/qemud/remote_dispatch_proc_switch.h b/qemud/remote_dispatch_proc_switch.h
index 89296d7..3cd5d78 100644
--- a/qemud/remote_dispatch_proc_switch.h
+++ b/qemud/remote_dispatch_proc_switch.h
@@ -116,6 +116,24 @@ case REMOTE_PROC_DOMAIN_DUMP_XML:
 ret = (char *) lv_remote_domain_dump_xml_ret;
 memset (lv_remote_domain_dump_xml_ret, 0, sizeof lv_remote_domain_dump_xml_ret);
 break;
+case REMOTE_PROC_DOMAIN_EVENT:
+fn = (dispatch_fn) remoteDispatchDomainEvent;
+ret_filter = (xdrproc_t) xdr_remote_domain_event_ret;
+ret = (char *) lv_remote_domain_event_ret;
+memset (lv_remote_domain_event_ret, 0, sizeof lv_remote_domain_event_ret);
+break;
+case REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER:
+fn = (dispatch_fn) remoteDispatchDomainEventsDeregister;
+ret_filter = (xdrproc_t) xdr_remote_domain_events_deregister_ret;
+ret = (char *) lv_remote_domain_events_deregister_ret;
+memset (lv_remote_domain_events_deregister_ret, 0, sizeof lv_remote_domain_events_deregister_ret);
+break;
+case REMOTE_PROC_DOMAIN_EVENTS_REGISTER:
+fn = (dispatch_fn) remoteDispatchDomainEventsRegister;
+ret_filter = (xdrproc_t) xdr_remote_domain_events_register_ret;
+ret = (char *) lv_remote_domain_events_register_ret;
+memset (lv_remote_domain_events_register_ret, 0, sizeof lv_remote_domain_events_register_ret);
+break;
 case REMOTE_PROC_DOMAIN_GET_AUTOSTART:
 fn = (dispatch_fn) remoteDispatchDomainGetAutostart;
 args_filter = (xdrproc_t) xdr_remote_domain_get_autostart_args;
diff --git a/qemud/remote_dispatch_prototypes.h b/qemud/remote_dispatch_prototypes.h
index 3f4eb9f..4b27a9f 100644
--- a/qemud/remote_dispatch_prototypes.h
+++ b/qemud/remote_dispatch_prototypes.h
@@ -18,6 +18,9 @@ static int remoteDispatchDomainDefineXml (struct qemud_server *server, struct qe
 static int remoteDispatchDomainDestroy (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_domain_destroy_args *args, void *ret);
 static int remoteDispatchDomainDetachDevice (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_domain_detach_device_args *args, void *ret);
 static int remoteDispatchDomainDumpXml (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_domain_dump_xml_args *args, remote_domain_dump_xml_ret *ret);
+static int remoteDispatchDomainEvent (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_domain_event_ret 

[libvirt] Re: [PATCH 05/12] Domain Events - Driver API

2008-10-21 Thread Ben Guthro
[PATCH 05/12] Domain Events - Driver API
Additions to the driver API

 driver.h |   13 +
 1 file changed, 13 insertions(+)
diff --git a/src/driver.h b/src/driver.h
index 0540f80..d1b541f 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -280,6 +280,17 @@ typedef unsigned long long
 (*virDrvNodeGetFreeMemory)
 (virConnectPtr conn);
 
+typedef int
+(*virDrvDomainEventRegister)
+(virConnectPtr conn,
+ void *callback,
+ void *opaque);
+
+typedef int
+(*virDrvDomainEventDeregister)
+(virConnectPtr conn,
+ void *callback);
+
 /**
  * _virDriver:
  *
@@ -352,6 +363,8 @@ struct _virDriver {
 virDrvDomainMemoryPeek  domainMemoryPeek;
 virDrvNodeGetCellsFreeMemory	nodeGetCellsFreeMemory;
 virDrvNodeGetFreeMemory		getFreeMemory;
+virDrvDomainEventRegister domainEventRegister;
+virDrvDomainEventDeregister   domainEventDeregister;
 };
 
 typedef int
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] Re: [PATCH 06/12] Domain Events - qemu driver

2008-10-21 Thread Ben Guthro
[PATCH 06/12] Domain Events - qemu driver
Register for, and dispatch domain event callbacks

 qemu_conf.h   |3 +
 qemu_driver.c |  101 +-
 2 files changed, 97 insertions(+), 7 deletions(-)
diff --git a/src/qemu_conf.h b/src/qemu_conf.h
index cfd7d35..d06c4d7 100644
--- a/src/qemu_conf.h
+++ b/src/qemu_conf.h
@@ -63,6 +63,9 @@ struct qemud_driver {
 char *vncListen;
 
 virCapsPtr caps;
+
+/* An array of callbacks */
+virDomainEventCallbackListPtr domainEventCallbacks;
 };
 
 
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 59d7166..a9a9340 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -106,7 +106,12 @@ static int qemudSetNonBlock(int fd) {
 }
 
 
-static void qemudDispatchVMEvent(int fd, int events, void *opaque);
+static void qemudDomainEventDispatch (struct qemud_driver *driver,
+  virDomainObjPtr vm,
+  virDomainEventType evt);
+
+static void qemudDispatchVMEvent(int fd, virEventHandleType events,
+ void *opaque);
 static int qemudStartVMDaemon(virConnectPtr conn,
   struct qemud_driver *driver,
   virDomainObjPtr vm,
@@ -159,6 +164,10 @@ qemudStartup(void) {
 /* Don't have a dom0 so start from 1 */
 qemu_driver-nextvmid = 1;
 
+/* Init callback list */
+if(VIR_ALLOC(qemu_driver-domainEventCallbacks)  0)
+return -1;
+
 if (!uid) {
 if (asprintf(qemu_driver-logDir,
  %s/log/libvirt/qemu, LOCAL_STATE_DIR) == -1)
@@ -301,6 +310,9 @@ qemudShutdown(void) {
 VIR_FREE(qemu_driver-autostartDir);
 VIR_FREE(qemu_driver-vncTLSx509certdir);
 
+/* Free domain callback list */
+virDomainEventCallbackListFree(qemu_driver-domainEventCallbacks);
+
 if (qemu_driver-brctl)
 brShutdown(qemu_driver-brctl);
 
@@ -742,6 +754,9 @@ static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
 return -1;
 }
 
+static virDomainPtr qemudDomainLookupByName(virConnectPtr conn,
+const char *name);
+
 static int qemudStartVMDaemon(virConnectPtr conn,
   struct qemud_driver *driver,
   virDomainObjPtr vm,
@@ -756,6 +771,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
 unsigned int qemuCmdFlags;
 fd_set keepfd;
 const char *emulator;
+virDomainPtr dom;
 
 FD_ZERO(keepfd);
 
@@ -905,11 +921,15 @@ static int qemudStartVMDaemon(virConnectPtr conn,
 
 if (ret == 0) {
 if ((virEventAddHandle(vm-stdout_fd,
-   POLLIN | POLLERR | POLLHUP,
+   VIR_EVENT_HANDLE_READABLE |
+   VIR_EVENT_HANDLE_ERROR |
+   VIR_EVENT_HANDLE_HANGUP,
qemudDispatchVMEvent,
driver)  0) ||
 (virEventAddHandle(vm-stderr_fd,
-   POLLIN | POLLERR | POLLHUP,
+   VIR_EVENT_HANDLE_READABLE |
+   VIR_EVENT_HANDLE_ERROR |
+   VIR_EVENT_HANDLE_HANGUP,
qemudDispatchVMEvent,
driver)  0) ||
 (qemudWaitForMonitor(conn, driver, vm)  0) ||
@@ -918,6 +938,11 @@ static int qemudStartVMDaemon(virConnectPtr conn,
 qemudShutdownVMDaemon(conn, driver, vm);
 return -1;
 }
+dom = qemudDomainLookupByName(conn,vm-def-name);
+if(dom)
+qemudDomainEventDispatch(driver, vm, VIR_DOMAIN_EVENT_STARTED);
+else
+DEBUG0(Warning - dom is NULL at domain start);
 }
 
 return ret;
@@ -1012,6 +1037,7 @@ static int qemudDispatchVMLog(struct qemud_driver *driver, virDomainObjPtr vm, i
 static int qemudDispatchVMFailure(struct qemud_driver *driver, virDomainObjPtr vm,
   int fd ATTRIBUTE_UNUSED) {
 qemudShutdownVMDaemon(NULL, driver, vm);
+qemudDomainEventDispatch(driver, vm, VIR_DOMAIN_EVENT_STOPPED);
 if (!vm-persistent)
 virDomainRemoveInactive(driver-domains,
 vm);
@@ -1019,7 +1045,8 @@ static int qemudDispatchVMFailure(struct qemud_driver *driver, virDomainObjPtr v
 }
 
 
-static void qemudDispatchVMEvent(int fd, int events, void *opaque) {
+static void
+qemudDispatchVMEvent(int fd, virEventHandleType events, void *opaque) {
 struct qemud_driver *driver = (struct qemud_driver *)opaque;
 virDomainObjPtr vm = NULL;
 unsigned int i;
@@ -1036,7 +1063,7 @@ static void qemudDispatchVMEvent(int fd, int events, void *opaque) {
 if (!vm)
 return;
 
-if (events == POLLIN)
+if (events == VIR_EVENT_HANDLE_READABLE)
 

[libvirt] Re: [PATCH 07/12] Domain Events - remote driver

2008-10-21 Thread Ben Guthro
[PATCH 07/12] Domain Events - remote driver
Deliver local callbacks in response to remote events

 remote_internal.c |  276 +-
 1 file changed, 271 insertions(+), 5 deletions(-)
diff --git a/src/remote_internal.c b/src/remote_internal.c
index 35b7b4b..8875674 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -34,6 +34,7 @@
 #include signal.h
 #include sys/types.h
 #include sys/stat.h
+#include sys/poll.h
 #include fcntl.h
 
 #ifdef HAVE_SYS_WAIT_H
@@ -73,6 +74,7 @@
 #include remote_protocol.h
 #include memory.h
 #include util.h
+#include event.h
 
 /* Per-connection private data. */
 #define MAGIC 999   /* private_data-magic if OK */
@@ -97,6 +99,13 @@ struct private_data {
 unsigned int saslDecodedLength;
 unsigned int saslDecodedOffset;
 #endif
+/* The list of domain event callbacks */
+virDomainEventCallbackListPtr callbackList;
+/* The queue of domain events generated
+   during a call / response rpc  */
+virDomainEventQueuePtr domainEvents;
+/* Timer for flushing domainEvents queue */
+int eventFlushTimer;
 };
 
 #define GET_PRIVATE(conn,retcode)   \
@@ -156,7 +165,10 @@ static void make_nonnull_domain (remote_nonnull_domain *dom_dst, virDomainPtr do
 static void make_nonnull_network (remote_nonnull_network *net_dst, virNetworkPtr net_src);
 static void make_nonnull_storage_pool (remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr vol_src);
 static void make_nonnull_storage_vol (remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src);
-
+void remoteDomainEventFired(int fd, virEventHandleType event, void *data);
+static void remoteDomainProcessEvent(virConnectPtr conn, XDR *xdr);
+static void remoteDomainQueueEvent(virConnectPtr conn, XDR *xdr);
+void remoteDomainEventQueueFlush(int timer, void *opaque);
 /*--*/
 
 /* Helper functions for remoteOpen. */
@@ -680,6 +692,36 @@ doRemoteOpen (virConnectPtr conn,
   (xdrproc_t) xdr_void, (char *) NULL) == -1)
 goto failed;
 
+if(VIR_ALLOC(priv-callbackList)0) {
+error(conn, VIR_ERR_INVALID_ARG, _(Error allocating callbacks list));
+goto failed;
+}
+
+if(VIR_ALLOC(priv-domainEvents)0) {
+error(conn, VIR_ERR_INVALID_ARG, _(Error allocating domainEvents));
+goto failed;
+}
+
+DEBUG0(Adding Handler for remote events);
+/* Set up a callback to listen on the socket data */
+if (virEventAddHandle(priv-sock,
+  VIR_EVENT_HANDLE_READABLE |
+  VIR_EVENT_HANDLE_ERROR |
+  VIR_EVENT_HANDLE_HANGUP,
+  remoteDomainEventFired,
+  conn)  0) {
+DEBUG0(virEventAddHandle failed: No addHandleImpl defined.
+continuing without events.);
+} else {
+
+DEBUG0(Adding Timeout for remote event queue flushing);
+if ( (priv-eventFlushTimer = virEventAddTimeout(-1,
+   remoteDomainEventQueueFlush,
+   conn))  0) {
+DEBUG0(virEventAddTimeout failed: No addTimeoutImpl defined. 
+continuing without events.);
+}
+}
 /* Successful. */
 retcode = VIR_DRV_OPEN_SUCCESS;
 
@@ -1101,6 +1143,11 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv)
   (xdrproc_t) xdr_void, (char *) NULL) == -1)
 return -1;
 
+/* Remove handle for remote events */
+virEventRemoveHandle(priv-sock);
+/* Remove timout */
+virEventRemoveTimeout(priv-eventFlushTimer);
+
 /* Close socket. */
 if (priv-uses_tls  priv-session) {
 gnutls_bye (priv-session, GNUTLS_SHUT_RDWR);
@@ -1132,6 +1179,12 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv)
 /* Free private data. */
 priv-magic = DEAD;
 
+/* Free callback list */
+virDomainEventCallbackListFree(priv-callbackList);
+
+/* Free queued events */
+virDomainEventQueueFree(priv-domainEvents);
+
 return 0;
 }
 
@@ -4288,6 +4341,52 @@ remoteAuthPolkit (virConnectPtr conn, struct private_data *priv, int in_open,
 return 0;
 }
 #endif /* HAVE_POLKIT */
+/*--*/
+
+static int remoteDomainEventRegister (virConnectPtr conn,
+   void *callback ATTRIBUTE_UNUSED,
+   void *opaque ATTRIBUTE_UNUSED)
+{
+struct private_data *priv = conn-privateData;
+
+if (virDomainEventCallbackListAdd(conn, priv-callbackList,
+  callback, opaque)  0) {
+ error (conn, VIR_ERR_RPC, _(adding cb to list));
+ return -1;
+}
+
+if ( priv-callbackList-count == 1 ) {
+/* Tell the server when we are 

[libvirt] Re: [PATCH 08/12] Domain Events - lxc driver

2008-10-21 Thread Ben Guthro
[PATCH 08/12] Domain Events - lxc driver
Minor changes to LXC driver structure to prevent compile errors

 lxc_driver.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/lxc_driver.c b/src/lxc_driver.c
index c598d1d..d1e4418 100644
--- a/src/lxc_driver.c
+++ b/src/lxc_driver.c
@@ -583,7 +583,7 @@ static int lxcVmTerminate(virConnectPtr conn,
 }
 
 static void lxcMonitorEvent(int fd,
-int events ATTRIBUTE_UNUSED,
+virEventHandleType events ATTRIBUTE_UNUSED,
 void *data)
 {
 lxc_driver_t *driver = data;
@@ -811,7 +811,7 @@ static int lxcVmStart(virConnectPtr conn,
 vm-state = VIR_DOMAIN_RUNNING;
 
 if (virEventAddHandle(vm-monitor,
-  POLLERR | POLLHUP,
+  VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP,
   lxcMonitorEvent,
   driver)  0) {
 lxcVmTerminate(conn, driver, vm, 0);
@@ -1278,6 +1278,8 @@ static virDriver lxcDriver = {
 NULL, /* domainMemoryPeek */
 NULL, /* nodeGetCellsFreeMemory */
 NULL, /* getFreeMemory */
+NULL, /* domainEventRegister */
+NULL, /* domainEventDeregister */
 };
 
 static virStateDriver lxcStateDriver = {
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] Re: [PATCH 09/12] Domain Events - openvz driver

2008-10-21 Thread Ben Guthro
[PATCH 09/12] Domain Events - openvz driver
Minor changes to openvz driver structure to prevent compile errors

 openvz_driver.c |2 ++
 1 file changed, 2 insertions(+)
diff --git a/src/openvz_driver.c b/src/openvz_driver.c
index b82d0df..2d0ddaa 100644
--- a/src/openvz_driver.c
+++ b/src/openvz_driver.c
@@ -1012,6 +1012,8 @@ static virDriver openvzDriver = {
 NULL, /* domainMemoryPeek */
 NULL, /* nodeGetCellsFreeMemory */
 NULL, /* nodeGetFreeMemory */
+NULL, /* domainEventRegister */
+NULL, /* domainEventDeregister */
 };
 
 int openvzRegister(void) {
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] Re: [PATCH 10/12] Domain Events - test driver

2008-10-21 Thread Ben Guthro
[PATCH 10/12] Domain Events - test driver
Minor changes to test driver structure to prevent compile errors

 test.c |2 ++
 1 file changed, 2 insertions(+)
diff --git a/src/test.c b/src/test.c
index aab74e4..34d35db 100644
--- a/src/test.c
+++ b/src/test.c
@@ -1552,6 +1552,8 @@ static virDriver testDriver = {
 NULL, /* domainMemoryPeek */
 testNodeGetCellsFreeMemory, /* nodeGetCellsFreeMemory */
 NULL, /* getFreeMemory */
+NULL, /* domainEventRegister */
+NULL, /* domainEventDeregister */
 };
 
 static virNetworkDriver testNetworkDriver = {
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] Re: [PATCH 11/12] Domain Events - test harness

2008-10-21 Thread Ben Guthro
[PATCH 11/12] Domain Events - test harness
Test app, and infrastructure changes for an example dir

 Makefile.am  |2
 configure.in |3
 examples/domain-events/events-c/Makefile.am  |5
 examples/domain-events/events-c/event-test.c |  261 +++
 libvirt.spec.in  |3
 5 files changed, 272 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 073063d..d40a151 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,7 +4,7 @@ LCOV = lcov
 GENHTML = genhtml
 
 SUBDIRS = gnulib/lib include src qemud proxy docs gnulib/tests \
-  python tests po
+  python tests po examples/domain-events/events-c
 
 ACLOCAL_AMFLAGS = -I m4 -I gnulib/m4
 
diff --git a/configure.in b/configure.in
index 66d271a..b7890d1 100644
--- a/configure.in
+++ b/configure.in
@@ -1067,7 +1067,8 @@ AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
   tests/sexpr2xmldata/Makefile \
   tests/xmconfigdata/Makefile \
   tests/xencapsdata/Makefile \
-  tests/virshdata/Makefile tests/confdata/Makefile)
+  tests/virshdata/Makefile tests/confdata/Makefile \
+  examples/domain-events/events-c/Makefile)
 
 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([Configuration summary])
diff --git a/examples/domain-events/events-c/Makefile.am b/examples/domain-events/events-c/Makefile.am
new file mode 100644
index 000..3c63ca3
--- /dev/null
+++ b/examples/domain-events/events-c/Makefile.am
@@ -0,0 +1,5 @@
+INCLUDES = [EMAIL PROTECTED]@/include
+bin_PROGRAMS = event-test
+event_test_CFLAGS = $(WARN_CFLAGS)
+event_test_SOURCES = event-test.c
+event_test_LDADD = @top_builddir@/src/libvirt.la
diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
new file mode 100644
index 000..55ed2f7
--- /dev/null
+++ b/examples/domain-events/events-c/event-test.c
@@ -0,0 +1,261 @@
+#include config.h
+#include stdio.h
+#include string.h
+#include sys/types.h
+#include sys/poll.h
+#include libvirt/libvirt.h
+
+#define DEBUG0(fmt) printf(%s:%d ::  fmt \n, \
+__FUNCTION__, __LINE__)
+#define DEBUG(fmt, ...) printf(%s:%d:  fmt \n, \
+__FUNCTION__, __LINE__, __VA_ARGS__)
+#define STREQ(a,b) (strcmp((a),(b)) == 0)
+
+#ifndef ATTRIBUTE_UNUSED
+#define ATTRIBUTE_UNUSED __attribute__((__unused__))
+#endif
+
+/* handle globals */
+int h_fd = 0;
+virEventHandleType h_event = 0;
+virEventHandleCallback h_cb = NULL;
+void *h_opaque = NULL;
+
+/* timeout globals */
+#define TIMEOUT_MS 1000
+int t_active = 0;
+int t_timeout = -1;
+virEventTimeoutCallback t_cb = NULL;
+void *t_opaque = NULL;
+
+
+/* Prototypes */
+const char *eventToString(int event);
+int myDomainEventCallback1 (virConnectPtr conn, virDomainPtr dom,
+int event, void *opaque);
+int myDomainEventCallback2 (virConnectPtr conn, virDomainPtr dom,
+int event, void *opaque);
+int myEventAddHandleFunc  (int fd, virEventHandleType event,
+   virEventHandleCallback cb, void *opaque);
+void myEventUpdateHandleFunc(int fd, virEventHandleType event);
+int  myEventRemoveHandleFunc(int fd);
+
+int myEventAddTimeoutFunc(int timeout, virEventTimeoutCallback cb,
+  void *opaque);
+void myEventUpdateTimeoutFunc(int timer, int timout);
+int myEventRemoveTimeoutFunc(int timer);
+
+int myEventHandleTypeToPollEvent(virEventHandleType events);
+virEventHandleType myPollEventToEventHandleType(int events);
+
+void usage(const char *pname);
+
+/* Callback functions */
+
+const char *eventToString(int event) {
+const char *ret = NULL;
+switch(event) {
+case VIR_DOMAIN_EVENT_ADDED:
+ret =Added;
+break;
+case VIR_DOMAIN_EVENT_REMOVED:
+ret =Removed;
+break;
+case VIR_DOMAIN_EVENT_STARTED:
+ret =Started;
+break;
+case VIR_DOMAIN_EVENT_SUSPENDED:
+ret =Suspended;
+break;
+case VIR_DOMAIN_EVENT_RESUMED:
+ret =Resumed;
+break;
+case VIR_DOMAIN_EVENT_STOPPED:
+ret =Stopped;
+break;
+case VIR_DOMAIN_EVENT_SAVED:
+ret =Saved;
+break;
+case VIR_DOMAIN_EVENT_RESTORED:
+ret =Restored;
+break;
+default:
+ret =Unknown Event;
+}
+return ret;
+}
+
+int myDomainEventCallback1 (virConnectPtr conn ATTRIBUTE_UNUSED,
+virDomainPtr dom,
+int event,
+void *opaque ATTRIBUTE_UNUSED)
+{
+printf(%s EVENT: Domain %s(%d) %s\n, __FUNCTION__, virDomainGetName(dom),
+   virDomainGetID(dom), eventToString(event));
+return 0;
+}
+
+int myDomainEventCallback2 (virConnectPtr conn ATTRIBUTE_UNUSED,
+virDomainPtr dom,
+   

[libvirt] [PATCH 00/12] Domain Events - Round 3

2008-10-21 Thread Ben Guthro
The following patch series implements the Events API discussed here previously 
in this thread:
http://www.redhat.com/archives/libvir-list/2008-September/msg00321.html 
http://www.redhat.com/archives/libvir-list/2008-October/msg00245.html and
https://www.redhat.com/archives/libvir-list/2008-October/msg00432.html

Once again, I have broken these into the following patches:

events-01-public-api  Changes to libvirt.h, and libvirt.c
events-02-internal-apiChanges to internal.h and event code
events-03-qemud   Changes to the daemon 
events-04-qemud-rpc-protocol  Changes to the qemud rpc protocol
events-05-driver.patchChanges to the driver API
events-06-driver-qemu Changes to the qemu driver
events-07-driver-remote   Changes to the remote driver
events-08-driver-lxc  Minor changes to LXC driver structure to prevent 
compile errors
events-09-driver-openvz   Minor changes to openvz driver structure to 
prevent compile errors
events-10-driver-test Minor changes to test driver structure to prevent 
compile errors
events-11-example-testapp Test app, and infrastructure changes for an 
example dir
events-12-python-ignore.patch Add functions to be ignored, for now

Differences from last submission - 
Formatting issues brought up by Daniel V
Some protocol simplifications
General fixes suggested from last time around.
Removal of POLLxxx stuff (this caused a bit of churn)

I think I got them all, but please let me know if I missed something.

Again, domain events are only emitted from qemu/kvm guests.


Ben Guthro



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


[libvirt] [PATCH 00/12] Domain Events - Round 3

2008-10-21 Thread Ben Guthro
The following patch series implements the Events API discussed here previously 
in this thread:
http://www.redhat.com/archives/libvir-list/2008-September/msg00321.html 
http://www.redhat.com/archives/libvir-list/2008-October/msg00245.html and
https://www.redhat.com/archives/libvir-list/2008-October/msg00432.html

Once again, I have broken these into the following patches:

events-01-public-api  Changes to libvirt.h, and libvirt.c
events-02-internal-apiChanges to internal.h and event code
events-03-qemud   Changes to the daemon 
events-04-qemud-rpc-protocol  Changes to the qemud rpc protocol
events-05-driver.patchChanges to the driver API
events-06-driver-qemu Changes to the qemu driver
events-07-driver-remote   Changes to the remote driver
events-08-driver-lxc  Minor changes to LXC driver structure to prevent 
compile errors
events-09-driver-openvz   Minor changes to openvz driver structure to 
prevent compile errors
events-10-driver-test Minor changes to test driver structure to prevent 
compile errors
events-11-example-testapp Test app, and infrastructure changes for an 
example dir
events-12-python-ignore.patch Add functions to be ignored, for now

Differences from last submission - 
Formatting issues brought up by Daniel V
Some protocol simplifications
General fixes suggested from last time around.
Removal of POLLxxx stuff (this caused a bit of churn)

I think I got them all, but please let me know if I missed something.

Again, domain events are only emitted from qemu/kvm guests.


Ben Guthro


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


[libvirt] Re: [PATCH 02/12] Domain Events - Internal API

2008-10-21 Thread Ben Guthro
[PATCH 02/12] Domain Events - Internal API
This patch
   -Removes EventImpl from being a private function
   -Introduces the virDomainEventCallbackListPtr, and virDomainEventQueuePtr 
objects
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 5902cab..75ba6b4 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -17,6 +17,7 @@ libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \
 @top_srcdir@/src/memory.c \
 @top_srcdir@/src/domain_conf.c \
 @top_srcdir@/src/util.c \
+	@top_srcdir@/src/event.c \
 	@top_srcdir@/src/uuid.c
 libvirt_proxy_LDFLAGS = $(WARN_CFLAGS)
 libvirt_proxy_DEPENDENCIES =
diff --git a/src/event.c b/src/event.c
index 49a9e61..1e2b234 100644
--- a/src/event.c
+++ b/src/event.c
@@ -34,14 +34,15 @@ static virEventAddTimeoutFunc addTimeoutImpl = NULL;
 static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL;
 static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
 
-int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque) {
+int virEventAddHandle(int fd, virEventHandleType events,
+  virEventHandleCallback cb, void *opaque) {
 if (!addHandleImpl)
 return -1;
 
 return addHandleImpl(fd, events, cb, opaque);
 }
 
-void virEventUpdateHandle(int fd, int events) {
+void virEventUpdateHandle(int fd, virEventHandleType events) {
 updateHandleImpl(fd, events);
 }
 
@@ -70,12 +71,22 @@ int virEventRemoveTimeout(int timer) {
 return removeTimeoutImpl(timer);
 }
 
-void __virEventRegisterImpl(virEventAddHandleFunc addHandle,
-virEventUpdateHandleFunc updateHandle,
-virEventRemoveHandleFunc removeHandle,
-virEventAddTimeoutFunc addTimeout,
-virEventUpdateTimeoutFunc updateTimeout,
-virEventRemoveTimeoutFunc removeTimeout) {
+/**
+ * virEventRegisterImpl:
+ * Register an EventImpl
+ * @addHandle: the callback to add fd handles
+ * @updateHandle: the callback to update fd handles
+ * @removeHandle: the callback to remove fd handles
+ * @addTimeout: the callback to add a timeout
+ * @updateTimeout: the callback to update a timeout
+ * @removeTimeout: the callback to remove a timeout
+ */
+void virEventRegisterImpl(virEventAddHandleFunc addHandle,
+  virEventUpdateHandleFunc updateHandle,
+  virEventRemoveHandleFunc removeHandle,
+  virEventAddTimeoutFunc addTimeout,
+  virEventUpdateTimeoutFunc updateTimeout,
+  virEventRemoveTimeoutFunc removeTimeout) {
 addHandleImpl = addHandle;
 updateHandleImpl = updateHandle;
 removeHandleImpl = removeHandle;
diff --git a/src/event.h b/src/event.h
index 758573c..5cd6310 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,38 +23,29 @@
 
 #ifndef __VIR_EVENT_H__
 #define __VIR_EVENT_H__
-
-
-/**
- * virEventHandleCallback: callback for receiving file handle events
- *
- * @fd: file handle on which the event occurred
- * @events: bitset of events from POLLnnn constants
- * @opaque: user data registered with handle
- */
-typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
-
+#include internal.h
 /**
  * virEventAddHandle: register a callback for monitoring file handle events
  *
  * @fd: file handle to monitor for events
- * @events: bitset of events to watch from POLLnnn constants
+ * @events: bitset of events to watch from virEventHandleType constants
  * @cb: callback to invoke when an event occurs
  * @opaque: user data to pass to callback
  *
  * returns -1 if the file handle cannot be registered, 0 upon success
  */
-int virEventAddHandle(int fd, int events, virEventHandleCallback cb, void *opaque);
+int virEventAddHandle(int fd, virEventHandleType events,
+  virEventHandleCallback cb, void *opaque);
 
 /**
  * virEventUpdateHandle: change event set for a monitored file handle
  *
  * @fd: file handle to monitor for events
- * @events: bitset of events to watch from POLLnnn constants
+ * @events: bitset of events to watch from virEventHandleType constants
  *
  * Will not fail if fd exists
  */
-void virEventUpdateHandle(int fd, int events);
+void virEventUpdateHandle(int fd, virEventHandleType events);
 
 /**
  * virEventRemoveHandle: unregister a callback from a file handle
@@ -66,14 +57,6 @@ void virEventUpdateHandle(int fd, int events);
 int virEventRemoveHandle(int fd);
 
 /**
- * virEventTimeoutCallback: callback for receiving timer events
- *
- * @timer: timer id emitting the event
- * @opaque: user data registered with handle
- */
-typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
-
-/**
  * virEventAddTimeout: register a callback for a timer event
  *
  * @frequency: time between events in milliseconds
@@ -110,21 +93,4 @@ void virEventUpdateTimeout(int timer, int frequency);
  */
 int 

[libvirt] Re: [PATCH 01/12] Domain Events - Public API

2008-10-21 Thread Ben Guthro
[PATCH 01/12] Domain Events - Public API

This patch does the following:
   -implements the Event register/deregister code
   -Adds some callback lists, and queue functions used by drivers
   -Move EventImpl definitions into the public
diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h
index 35b80d0..7f784c6 100644
--- a/include/libvirt/libvirt.h
+++ b/include/libvirt/libvirt.h
@@ -993,6 +993,156 @@ char *  virStorageVolGetPath(virStorageVolPtr vol);
 virDomainPtrvirDomainCreateLinux(virConnectPtr conn,
  const char *xmlDesc,
  unsigned int flags);
+
+/*
+ * Domain Event Notification
+ */
+
+/**
+ * virDomainEventType:
+ *
+ * a virDomainEventType is emitted during domain lifecycle events
+ */
+typedef enum {
+  VIR_DOMAIN_EVENT_ADDED,
+  VIR_DOMAIN_EVENT_REMOVED,
+  VIR_DOMAIN_EVENT_STARTED,
+  VIR_DOMAIN_EVENT_SUSPENDED,
+  VIR_DOMAIN_EVENT_RESUMED,
+  VIR_DOMAIN_EVENT_STOPPED,
+  VIR_DOMAIN_EVENT_SAVED,
+  VIR_DOMAIN_EVENT_RESTORED,
+} virDomainEventType;
+
+/**
+ * virConnectDomainEventCallback:
+ * @conn: virConnect connection
+ * @dom: The domain on which the event occured
+ * @event: The specfic virDomainEventType which occured
+ * @opaque: opaque user data
+ *
+ * A callback function to be registered, and called when a domain event occurs 
+ */
+typedef int (*virConnectDomainEventCallback)(virConnectPtr conn,
+ virDomainPtr dom,
+ int event,
+ void *opaque);
+
+int virConnectDomainEventRegister(virConnectPtr conn,
+  virConnectDomainEventCallback cb,
+  void *opaque);
+
+int virConnectDomainEventDeregister(virConnectPtr conn,
+virConnectDomainEventCallback cb);
+
+/*
+ * Events Implementation
+ */
+
+/**
+ * virEventHandleType:
+ *
+ * a virEventHandleType is used similar to POLLxxx FD events, but is specific
+ * to libvirt. A client app must translate to, and from POLL events when using
+ * this construct.
+ */
+typedef enum {
+VIR_EVENT_HANDLE_READABLE  = (1  0),
+VIR_EVENT_HANDLE_WRITABLE  = (1  1),
+VIR_EVENT_HANDLE_ERROR = (1  2),
+VIR_EVENT_HANDLE_HANGUP= (1  3),
+} virEventHandleType;
+
+/**
+ * virEventHandleCallback: callback for receiving file handle events
+ *
+ * @fd: file handle on which the event occurred
+ * @events: bitset of events from virEventHandleType constants
+ * @opaque: user data registered with handle
+ */
+typedef void (*virEventHandleCallback)(int fd, virEventHandleType events,
+   void *opaque);
+
+/**
+ * virEventAddHandleFunc:
+ * @fd: file descriptor to listen on
+ * @event: events on which to fire the callback
+ * @cb: the callback to be called
+ * @opaque: user data to pass to the callback
+ *
+ * Part of the EventImpl, this callback Adds a file handle callback to
+ *  listen for specific events
+ */
+typedef int (*virEventAddHandleFunc)(int fd, virEventHandleType event,
+ virEventHandleCallback cb, void *opaque);
+
+/**
+ * virEventUpdateHandleFunc:
+ * @fd: file descriptor to modify
+ * @event: new events to listen on
+ *
+ * Part of the EventImpl, this user-provided callback is notified when
+ * events to listen on change
+ */
+typedef void (*virEventUpdateHandleFunc)(int fd, virEventHandleType event);
+
+/**
+ * virEventRemoveHandleFunc:
+ * @fd: file descriptor to stop listening on
+ *
+ * Part of the EventImpl, this user-provided callback is notified when
+ * an fd is no longer being listened on
+ */
+typedef int (*virEventRemoveHandleFunc)(int fd);
+
+/**
+ * virEventTimeoutCallback: callback for receiving timer events
+ *
+ * @timer: timer id emitting the event
+ * @opaque: user data registered with handle
+ */
+typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
+
+/**
+ * virEventAddTimeoutFunc:
+ * @timeout: The timeout to monitor
+ * @cb: the callback to call when timeout has expired
+ * @opaque: user data to pass to the callback
+ *
+ * Part of the EventImpl, this user-defined callback handles adding an
+ * event timeout.
+ *
+ * Returns a timer value
+ */
+typedef int (*virEventAddTimeoutFunc)(int timeout, virEventTimeoutCallback cb,
+  void *opaque);
+
+/**
+ * virEventUpdateTimeoutFunc:
+ * @timer: the timer to modify
+ * @timeout: the new timeout value
+ *
+ * Part of the EventImpl, this user-defined callback updates an
+ * event timeout.
+ */
+typedef void (*virEventUpdateTimeoutFunc)(int timer, int timeout);
+
+/**
+ * virEventRemoveTimeoutFunc:
+ * @timer: the timer to remove
+ *
+ * Part of the EventImpl, this user-defined callback removes a timer
+ *
+ * Returns 0 on success, -1 on 

[libvirt] Re: [PATCH 01/12] Domain Events - Public API

2008-10-21 Thread Ben Guthro
[PATCH 01/12] Domain Events - Public API

This patch does the following:
   -implements the Event register/deregister code
   -Adds some callback lists, and queue functions used by drivers
   -Move EventImpl definitions into the public

diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h
index 35b80d0..7f784c6 100644
--- a/include/libvirt/libvirt.h
+++ b/include/libvirt/libvirt.h
@@ -993,6 +993,156 @@ char *  virStorageVolGetPath(virStorageVolPtr vol);
 virDomainPtrvirDomainCreateLinux(virConnectPtr conn,
  const char *xmlDesc,
  unsigned int flags);
+
+/*
+ * Domain Event Notification
+ */
+
+/**
+ * virDomainEventType:
+ *
+ * a virDomainEventType is emitted during domain lifecycle events
+ */
+typedef enum {
+  VIR_DOMAIN_EVENT_ADDED,
+  VIR_DOMAIN_EVENT_REMOVED,
+  VIR_DOMAIN_EVENT_STARTED,
+  VIR_DOMAIN_EVENT_SUSPENDED,
+  VIR_DOMAIN_EVENT_RESUMED,
+  VIR_DOMAIN_EVENT_STOPPED,
+  VIR_DOMAIN_EVENT_SAVED,
+  VIR_DOMAIN_EVENT_RESTORED,
+} virDomainEventType;
+
+/**
+ * virConnectDomainEventCallback:
+ * @conn: virConnect connection
+ * @dom: The domain on which the event occured
+ * @event: The specfic virDomainEventType which occured
+ * @opaque: opaque user data
+ *
+ * A callback function to be registered, and called when a domain event occurs 
+ */
+typedef int (*virConnectDomainEventCallback)(virConnectPtr conn,
+ virDomainPtr dom,
+ int event,
+ void *opaque);
+
+int virConnectDomainEventRegister(virConnectPtr conn,
+  virConnectDomainEventCallback cb,
+  void *opaque);
+
+int virConnectDomainEventDeregister(virConnectPtr conn,
+virConnectDomainEventCallback cb);
+
+/*
+ * Events Implementation
+ */
+
+/**
+ * virEventHandleType:
+ *
+ * a virEventHandleType is used similar to POLLxxx FD events, but is specific
+ * to libvirt. A client app must translate to, and from POLL events when using
+ * this construct.
+ */
+typedef enum {
+VIR_EVENT_HANDLE_READABLE  = (1  0),
+VIR_EVENT_HANDLE_WRITABLE  = (1  1),
+VIR_EVENT_HANDLE_ERROR = (1  2),
+VIR_EVENT_HANDLE_HANGUP= (1  3),
+} virEventHandleType;
+
+/**
+ * virEventHandleCallback: callback for receiving file handle events
+ *
+ * @fd: file handle on which the event occurred
+ * @events: bitset of events from virEventHandleType constants
+ * @opaque: user data registered with handle
+ */
+typedef void (*virEventHandleCallback)(int fd, virEventHandleType events,
+   void *opaque);
+
+/**
+ * virEventAddHandleFunc:
+ * @fd: file descriptor to listen on
+ * @event: events on which to fire the callback
+ * @cb: the callback to be called
+ * @opaque: user data to pass to the callback
+ *
+ * Part of the EventImpl, this callback Adds a file handle callback to
+ *  listen for specific events
+ */
+typedef int (*virEventAddHandleFunc)(int fd, virEventHandleType event,
+ virEventHandleCallback cb, void *opaque);
+
+/**
+ * virEventUpdateHandleFunc:
+ * @fd: file descriptor to modify
+ * @event: new events to listen on
+ *
+ * Part of the EventImpl, this user-provided callback is notified when
+ * events to listen on change
+ */
+typedef void (*virEventUpdateHandleFunc)(int fd, virEventHandleType event);
+
+/**
+ * virEventRemoveHandleFunc:
+ * @fd: file descriptor to stop listening on
+ *
+ * Part of the EventImpl, this user-provided callback is notified when
+ * an fd is no longer being listened on
+ */
+typedef int (*virEventRemoveHandleFunc)(int fd);
+
+/**
+ * virEventTimeoutCallback: callback for receiving timer events
+ *
+ * @timer: timer id emitting the event
+ * @opaque: user data registered with handle
+ */
+typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
+
+/**
+ * virEventAddTimeoutFunc:
+ * @timeout: The timeout to monitor
+ * @cb: the callback to call when timeout has expired
+ * @opaque: user data to pass to the callback
+ *
+ * Part of the EventImpl, this user-defined callback handles adding an
+ * event timeout.
+ *
+ * Returns a timer value
+ */
+typedef int (*virEventAddTimeoutFunc)(int timeout, virEventTimeoutCallback cb,
+  void *opaque);
+
+/**
+ * virEventUpdateTimeoutFunc:
+ * @timer: the timer to modify
+ * @timeout: the new timeout value
+ *
+ * Part of the EventImpl, this user-defined callback updates an
+ * event timeout.
+ */
+typedef void (*virEventUpdateTimeoutFunc)(int timer, int timeout);
+
+/**
+ * virEventRemoveTimeoutFunc:
+ * @timer: the timer to remove
+ *
+ * Part of the EventImpl, this user-defined callback removes a timer
+ *
+ * Returns 0 on success, -1 on 

Re: [libvirt] [PATCH 00/12] Domain Events - Round 3

2008-10-21 Thread Ben Guthro
Apologies about the duplicate 00, 01, and 02 emails.

My email seems to be acting up, and I didn't see those patches come 
through...so I resent those 3 
Then they arrived in pairs.

Please ignore the duplicates.


Ben Guthro wrote on 10/21/2008 03:10 PM:
 The following patch series implements the Events API discussed here 
 previously in this thread:
 http://www.redhat.com/archives/libvir-list/2008-September/msg00321.html 
 http://www.redhat.com/archives/libvir-list/2008-October/msg00245.html and
 https://www.redhat.com/archives/libvir-list/2008-October/msg00432.html
 
 Once again, I have broken these into the following patches:
 
 events-01-public-api  Changes to libvirt.h, and libvirt.c
 events-02-internal-apiChanges to internal.h and event code
 events-03-qemud   Changes to the daemon 
 events-04-qemud-rpc-protocol  Changes to the qemud rpc protocol
 events-05-driver.patchChanges to the driver API
 events-06-driver-qemu Changes to the qemu driver
 events-07-driver-remote   Changes to the remote driver
 events-08-driver-lxc  Minor changes to LXC driver structure to 
 prevent compile errors
 events-09-driver-openvz   Minor changes to openvz driver structure to 
 prevent compile errors
 events-10-driver-test Minor changes to test driver structure to 
 prevent compile errors
 events-11-example-testapp Test app, and infrastructure changes for an 
 example dir
 events-12-python-ignore.patch Add functions to be ignored, for now
 
 Differences from last submission - 
 Formatting issues brought up by Daniel V
 Some protocol simplifications
 General fixes suggested from last time around.
 Removal of POLLxxx stuff (this caused a bit of churn)
 
 I think I got them all, but please let me know if I missed something.
 
 Again, domain events are only emitted from qemu/kvm guests.
 
 
 Ben Guthro
 
 
 --
 Libvir-list mailing list
 Libvir-list@redhat.com
 https://www.redhat.com/mailman/listinfo/libvir-list

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


[libvirt] errors building rpm

2008-10-21 Thread Ben Guthro
I keep getting the following error when trying to build via a
'sudo make rpm' on the tip of the tree

+ /usr/lib/rpm/find-lang.sh /var/tmp/libvirt-0.4.6-1.fc9-root libvirt
No translations found for libvirt in /var/tmp/libvirt-0.4.6-1.fc9-root
error: Bad exit status from /var/tmp/rpm-tmp.82848 (%install)


RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.82848 (%install)
make: *** [rpm] Error 1


This looks like it came in with one of Jim Meyering's latest checkins.

I'm wondering if I'm doing something wrong - or if I'm missing a build
dependency that I did not need previously?

Ben Guthro

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


Re: [libvirt] Re: [PATCH 07/12] Domain Events - remote driver

2008-10-20 Thread Ben Guthro

 Just discovered one tiny problem here - need to check 'event' to see
 if the POLLHUP or POLLERR flags are set, and unregister the callback.
 Otherwise if you kill the server, the client will just spin on POLLHUP
 or ERR  forever. Something like this ought todo the trick
 
 if (event  (POLLERR | POLLHUP)) {
  virEventRemoveHandle(fd);
  return;
 }
 

I've been looking over the rest of your changes.
Generally, I agree all these suggestions are good ones...except for the code 
above

With this code in, I run the following test
1. start libvirtd
2. begin to monitor events with event-test
3. virsh create foo.xml

At this point, the event-test app encounters a HUP, or ERR, and stops 
monitoring for events - it will only ever get the Started event

I handle this in the event-test poll loop via

if ( pfd.revents  POLLHUP ) {
DEBUG0(Reset by peer);
return -1;
}


Is it not a reasonable restriction to require the client app to handle a Hangup?


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


Re: [libvirt] Re: [PATCH 07/12] Domain Events - remote driver

2008-10-20 Thread Ben Guthro
OK - it looks like my EventImpl was passing along the wrong bits.

I'll look into the token scheme suggested in an earlier email, and get this 
ready for re-submission.

Would you prefer a new patch series, as before - or another patch that modifies 
the prior series?




Daniel P. Berrange wrote on 10/20/2008 10:59 AM:
 On Mon, Oct 20, 2008 at 10:48:38AM -0400, Ben Guthro wrote:
 Just discovered one tiny problem here - need to check 'event' to see
 if the POLLHUP or POLLERR flags are set, and unregister the callback.
 Otherwise if you kill the server, the client will just spin on POLLHUP
 or ERR  forever. Something like this ought todo the trick

 if (event  (POLLERR | POLLHUP)) {
  virEventRemoveHandle(fd);
  return;
 }

 I've been looking over the rest of your changes.
 Generally, I agree all these suggestions are good ones...except for the code 
 above

 With this code in, I run the following test
 1. start libvirtd
 2. begin to monitor events with event-test
 3. virsh create foo.xml

 At this point, the event-test app encounters a HUP, or ERR, and stops
 monitoring for events - it will only ever get the Started event
 
 That's a little odd - I'm not sure why 'event-test' would be getting
 a HUP/ERR when 'virsh' starts a domain.
 
 'event-test' should only get a HUP/ERR if it looses its socket connection
 to the libvirtd server. Once you've lost the connection like this, the 
 entire virConnectPtr is non-operative, and the client app needs to 
 create a new virConnectPtr to re-connect. So removing the FD from the
 event loop shouldn't result in us loosing any events - we're already
 doomed there.to 
 
 I handle this in the event-test poll loop via

 if ( pfd.revents  POLLHUP ) {
 DEBUG0(Reset by peer);
 return -1;
 }
 
 The integration into the event loop though is only something the app
 will have general control off - eg, in the example libvirt-glib code
 I posted its totally opaque to the app.
 
 Is it not a reasonable restriction to require the client app to handle a 
 Hangup?
 
 Once the socket is dead, all subsequent libvirt call made on that 
 virConnectPtr object will throw errors, which the app should see. 
 Though if they're only ever waiting for events, and not making any
 other calls, they'd not see it. Perhaps we could do with an explicit
 callback for connection disconnect.
 
 
 Daniel

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


[libvirt] [PATCH 00/12] Domain Events - Round 2

2008-10-17 Thread Ben Guthro
The following patch series implements the Events API discussed here previously 
in this thread:
http://www.redhat.com/archives/libvir-list/2008-September/msg00321.html and
http://www.redhat.com/archives/libvir-list/2008-October/msg00245.html

By Daniel B's advice - I have broken this patch into the following:

events-01-public-api  Changes to libvirt.h, and libvirt.c
events-02-internal-apiChanges to internal.h and event code
events-03-qemud   Changes to the daemon 
events-04-qemud-rpc-protocol  Changes to the qemud rpc protocol
events-05-driver.patchChanges to the driver API
events-06-driver-qemu Changes to the qemu driver
events-07-driver-remote   Changes to the remote driver
events-08-driver-lxc  Minor changes to LXC driver structure to prevent 
compile errors
events-09-driver-openvz   Minor changes to openvz driver structure to 
prevent compile errors
events-10-driver-test Minor changes to test driver structure to prevent 
compile errors
events-11-example-testapp Test app, and infrastructure changes for an 
example dir
events-12-python-ignore.patch Add functions to be ignored, for now

For now, domain events are only emitted from qemu/kvm guests.


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


[libvirt] Re: [PATCH 01/12] Domain Events - Public API

2008-10-17 Thread Ben Guthro
 This patch does the following:
   -implements the Event register/deregister code
   -Adds some callback lists, and queue functions used by drivers
   -Move EventImpl definitions into the public

 include/libvirt/libvirt.h|   59 +
 include/libvirt/libvirt.h.in |   59 +
 src/libvirt.c|  256 +++
 src/libvirt_sym.version  |9 +
 4 files changed, 381 insertions(+), 2 deletions(-)


diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h
index 35b80d0..53ad6b7 100644
--- a/include/libvirt/libvirt.h
+++ b/include/libvirt/libvirt.h
@@ -993,6 +993,65 @@ char *  virStorageVolGetPath(virStorageVolPtr vol);
 virDomainPtrvirDomainCreateLinux(virConnectPtr conn,
  const char *xmlDesc,
  unsigned int flags);
+
+/*
+ * Domain Event Notification
+ */
+
+typedef enum {
+  VIR_DOMAIN_EVENT_ADDED,
+  VIR_DOMAIN_EVENT_REMOVED,
+  VIR_DOMAIN_EVENT_STARTED,
+  VIR_DOMAIN_EVENT_SUSPENDED,
+  VIR_DOMAIN_EVENT_RESUMED,
+  VIR_DOMAIN_EVENT_STOPPED,
+  VIR_DOMAIN_EVENT_SAVED,
+  VIR_DOMAIN_EVENT_RESTORED,
+} virDomainEventType;
+
+typedef int (*virConnectDomainEventCallback)(virConnectPtr conn,
+ virDomainPtr dom,
+ int event,
+ void *opaque);
+
+int virConnectDomainEventRegister(virConnectPtr conn,
+  virConnectDomainEventCallback cb,
+  void *opaque);
+
+int virConnectDomainEventDeregister(virConnectPtr conn,
+virConnectDomainEventCallback cb);
+
+/**
+ * virEventHandleCallback: callback for receiving file handle events
+ *
+ * @fd: file handle on which the event occurred
+ * @events: bitset of events from POLLnnn constants
+ * @opaque: user data registered with handle
+ */
+typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
+
+typedef int (*virEventAddHandleFunc)(int, int, virEventHandleCallback, void *);
+typedef void (*virEventUpdateHandleFunc)(int, int);
+typedef int (*virEventRemoveHandleFunc)(int);
+
+/**
+ * virEventTimeoutCallback: callback for receiving timer events
+ *
+ * @timer: timer id emitting the event
+ * @opaque: user data registered with handle
+ */
+typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
+
+typedef int (*virEventAddTimeoutFunc)(int, virEventTimeoutCallback, void *);
+typedef void (*virEventUpdateTimeoutFunc)(int, int);
+typedef int (*virEventRemoveTimeoutFunc)(int);
+
+void virEventRegisterImpl(virEventAddHandleFunc addHandle,
+  virEventUpdateHandleFunc updateHandle,
+  virEventRemoveHandleFunc removeHandle,
+  virEventAddTimeoutFunc addTimeout,
+  virEventUpdateTimeoutFunc updateTimeout,
+  virEventRemoveTimeoutFunc removeTimeout);
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 3624367..6af5329 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -993,6 +993,65 @@ char *  virStorageVolGetPath(virStorageVolPtr vol);
 virDomainPtrvirDomainCreateLinux(virConnectPtr conn,
  const char *xmlDesc,
  unsigned int flags);
+
+/*
+ * Domain Event Notification
+ */
+
+typedef enum {
+  VIR_DOMAIN_EVENT_ADDED,
+  VIR_DOMAIN_EVENT_REMOVED,
+  VIR_DOMAIN_EVENT_STARTED,
+  VIR_DOMAIN_EVENT_SUSPENDED,
+  VIR_DOMAIN_EVENT_RESUMED,
+  VIR_DOMAIN_EVENT_STOPPED,
+  VIR_DOMAIN_EVENT_SAVED,
+  VIR_DOMAIN_EVENT_RESTORED,
+} virDomainEventType;
+
+typedef int (*virConnectDomainEventCallback)(virConnectPtr conn,
+ virDomainPtr dom,
+ int event,
+ void *opaque);
+
+int virConnectDomainEventRegister(virConnectPtr conn,
+  virConnectDomainEventCallback cb,
+  void *opaque);
+
+int virConnectDomainEventDeregister(virConnectPtr conn,
+virConnectDomainEventCallback cb);
+
+/**
+ * virEventHandleCallback: callback for receiving file handle events
+ *
+ * @fd: file handle on which the event occurred
+ * @events: bitset of events from POLLnnn constants
+ * @opaque: user data registered with handle
+ */
+typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
+
+typedef int (*virEventAddHandleFunc)(int, int, virEventHandleCallback, void *);
+typedef void (*virEventUpdateHandleFunc)(int, 

[libvirt] Re: [PATCH 03/12] Domain Events - daemon changes

2008-10-17 Thread Ben Guthro
This code changes the daemaon to:
  use the pulic def of virEventRegisterImpl
  Add functionality to dispatch events to connected remote drivers

 qemud.c  |   28 ---
 qemud.h  |   14 +
 remote.c |  158 +++
 3 files changed, 193 insertions(+), 7 deletions(-)
diff --git a/qemud/qemud.c b/qemud/qemud.c
index 9da27d2..3020d81 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -723,12 +723,12 @@ static struct qemud_server *qemudInitialize(int sigread) {
 
 server-sigread = sigread;
 
-__virEventRegisterImpl(virEventAddHandleImpl,
-   virEventUpdateHandleImpl,
-   virEventRemoveHandleImpl,
-   virEventAddTimeoutImpl,
-   virEventUpdateTimeoutImpl,
-   virEventRemoveTimeoutImpl);
+virEventRegisterImpl(virEventAddHandleImpl,
+ virEventUpdateHandleImpl,
+ virEventRemoveHandleImpl,
+ virEventAddTimeoutImpl,
+ virEventUpdateTimeoutImpl,
+ virEventRemoveTimeoutImpl);
 
 virStateInitialize();
 
@@ -1105,7 +1105,12 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket
 client-auth = sock-auth;
 memcpy (client-addr, addr, sizeof addr);
 client-addrlen = addrlen;
+client-server = server;
 
+if(VIR_ALLOC(client-domainEventCallbacks)0) {
+qemudLog(QEMUD_ERR, _(Error allocating domainEventCallbacks: %s), strerror(errno));
+goto cleanup;
+}
 #if HAVE_POLKIT
 /* Only do policy checks for non-root - allow root user
through with no checks, as a fail-safe - root can easily
@@ -1199,6 +1204,15 @@ static void qemudDispatchClientFailure(struct qemud_server *server, struct qemud
 
 virEventRemoveHandleImpl(client-fd);
 
+/* Deregister event delivery callback */
+if(client-conn) {
+qemudDebug(Deregistering to relay remote events);
+virConnectDomainEventDeregister(client-conn, remoteRelayDomainEvent);
+}
+
+/* Free domain callback list */
+__virDomainEventCallbackListFree(client-domainEventCallbacks);
+
 if (client-conn)
 virConnectClose(client-conn);
 
@@ -1503,7 +1517,7 @@ static int qemudClientWrite(struct qemud_server *server,
 }
 
 
-static void qemudDispatchClientWrite(struct qemud_server *server, struct qemud_client *client) {
+void qemudDispatchClientWrite(struct qemud_server *server, struct qemud_client *client) {
 switch (client-mode) {
 case QEMUD_MODE_TX_PACKET: {
 if (qemudClientWrite(server, client)  0)
diff --git a/qemud/qemud.h b/qemud/qemud.h
index 91cb939..2fb3ca9 100644
--- a/qemud/qemud.h
+++ b/qemud/qemud.h
@@ -132,6 +132,12 @@ struct qemud_client {
  */
 virConnectPtr conn;
 
+/* This is the list of remote callbacks registered */
+virDomainEventCallbackListPtr domainEventCallbacks;
+
+/* back-pointer to our server */
+struct qemud_server *server;
+
 struct qemud_client *next;
 };
 
@@ -179,8 +185,16 @@ void qemudLog(int priority, const char *fmt, ...)
 void remoteDispatchClientRequest (struct qemud_server *server,
   struct qemud_client *client);
 
+void qemudDispatchClientWrite(struct qemud_server *server,
+ struct qemud_client *client);
+
 #if HAVE_POLKIT
 int qemudGetSocketIdentity(int fd, uid_t *uid, pid_t *pid);
 #endif
 
+int remoteRelayDomainEvent (virConnectPtr conn ATTRIBUTE_UNUSED,
+virDomainPtr dom,
+int event,
+void *opaque);
+
 #endif
diff --git a/qemud/remote.c b/qemud/remote.c
index 72e064e..eeed5fd 100644
--- a/qemud/remote.c
+++ b/qemud/remote.c
@@ -75,6 +75,13 @@ typedef int (*dispatch_fn) (struct qemud_server *server,
 char *args,
 char *ret);
 
+/* Prototypes */
+static void
+remoteDispatchDomainEventSend (struct qemud_client *client,
+   virDomainPtr dom,
+   virDomainEventType event,
+   virDomainEventCallbackPtr callback);
+
 /* This function gets called from qemud when it detects an incoming
  * remote protocol message.  At this point, client-buffer contains
  * the full call message (including length word which we skip).
@@ -405,6 +412,24 @@ remoteDispatchError (struct qemud_client *client,
 remoteDispatchSendError (client, req, VIR_ERR_RPC, msg);
 }
 
+int remoteRelayDomainEvent (virConnectPtr conn ATTRIBUTE_UNUSED,
+   virDomainPtr dom,
+   int event,
+   void *opaque)
+{
+int i;
+struct qemud_client *c = opaque;
+REMOTE_DEBUG(Relaying domain event %d, event);
+
+if(c  c-domainEventCallbacks) {
+

[libvirt] Re: [PATCH 02/12] Domain Events - Internal API

2008-10-17 Thread Ben Guthro
This patch
   -Removes EventImpl from being a private function
   -Introduces the virDomainEventCallbackListPtr, and virDomainEventQueuePtr 
objects

 proxy/Makefile.am |1
 src/event.c   |   12 +-
 src/event.h   |   37 ---
 src/internal.h|   63 ++
 4 files changed, 71 insertions(+), 42 deletions(-)


diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 5902cab..75ba6b4 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -17,6 +17,7 @@ libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \
 @top_srcdir@/src/memory.c \
 @top_srcdir@/src/domain_conf.c \
 @top_srcdir@/src/util.c \
+	@top_srcdir@/src/event.c \
 	@top_srcdir@/src/uuid.c
 libvirt_proxy_LDFLAGS = $(WARN_CFLAGS)
 libvirt_proxy_DEPENDENCIES =
diff --git a/src/event.c b/src/event.c
index 49a9e61..7ce70ec 100644
--- a/src/event.c
+++ b/src/event.c
@@ -70,12 +70,12 @@ int virEventRemoveTimeout(int timer) {
 return removeTimeoutImpl(timer);
 }
 
-void __virEventRegisterImpl(virEventAddHandleFunc addHandle,
-virEventUpdateHandleFunc updateHandle,
-virEventRemoveHandleFunc removeHandle,
-virEventAddTimeoutFunc addTimeout,
-virEventUpdateTimeoutFunc updateTimeout,
-virEventRemoveTimeoutFunc removeTimeout) {
+void virEventRegisterImpl(virEventAddHandleFunc addHandle,
+  virEventUpdateHandleFunc updateHandle,
+  virEventRemoveHandleFunc removeHandle,
+  virEventAddTimeoutFunc addTimeout,
+  virEventUpdateTimeoutFunc updateTimeout,
+  virEventRemoveTimeoutFunc removeTimeout) {
 addHandleImpl = addHandle;
 updateHandleImpl = updateHandle;
 removeHandleImpl = removeHandle;
diff --git a/src/event.h b/src/event.h
index 758573c..fbff0e8 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,17 +23,7 @@
 
 #ifndef __VIR_EVENT_H__
 #define __VIR_EVENT_H__
-
-
-/**
- * virEventHandleCallback: callback for receiving file handle events
- *
- * @fd: file handle on which the event occurred
- * @events: bitset of events from POLLnnn constants
- * @opaque: user data registered with handle
- */
-typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
-
+#include internal.h
 /**
  * virEventAddHandle: register a callback for monitoring file handle events
  *
@@ -66,14 +56,6 @@ void virEventUpdateHandle(int fd, int events);
 int virEventRemoveHandle(int fd);
 
 /**
- * virEventTimeoutCallback: callback for receiving timer events
- *
- * @timer: timer id emitting the event
- * @opaque: user data registered with handle
- */
-typedef void (*virEventTimeoutCallback)(int timer, void *opaque);
-
-/**
  * virEventAddTimeout: register a callback for a timer event
  *
  * @frequency: time between events in milliseconds
@@ -110,21 +92,4 @@ void virEventUpdateTimeout(int timer, int frequency);
  */
 int virEventRemoveTimeout(int timer);
 
-typedef int (*virEventAddHandleFunc)(int, int, virEventHandleCallback, void *);
-typedef void (*virEventUpdateHandleFunc)(int, int);
-typedef int (*virEventRemoveHandleFunc)(int);
-
-typedef int (*virEventAddTimeoutFunc)(int, virEventTimeoutCallback, void *);
-typedef void (*virEventUpdateTimeoutFunc)(int, int);
-typedef int (*virEventRemoveTimeoutFunc)(int);
-
-void __virEventRegisterImpl(virEventAddHandleFunc addHandle,
-virEventUpdateHandleFunc updateHandle,
-virEventRemoveHandleFunc removeHandle,
-virEventAddTimeoutFunc addTimeout,
-virEventUpdateTimeoutFunc updateTimeout,
-virEventRemoveTimeoutFunc removeTimeout);
-
-#define virEventRegisterImpl(ah,rh,at,rt) __virEventRegisterImpl(ah,rh,at,rt)
-
 #endif /* __VIR_EVENT_H__ */
diff --git a/src/internal.h b/src/internal.h
index 2ae764d..e996eea 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -383,4 +383,67 @@ char *virStringListJoin(const virStringList *list, const char *pre,
 const char *post, const char *sep);
 void virStringListFree(virStringList *list);
 
+/**
+ * Domain Event Notification
+ */
+
+struct _virDomainEventCallback {
+virConnectPtr conn;
+virConnectDomainEventCallback cb;
+void *opaque;
+};
+typedef struct _virDomainEventCallback virDomainEventCallback;
+typedef virDomainEventCallback *virDomainEventCallbackPtr;
+
+struct _virDomainEventCallbackList {
+unsigned int count;
+virDomainEventCallbackPtr *callbacks;
+};
+typedef struct _virDomainEventCallbackList virDomainEventCallbackList;
+typedef virDomainEventCallbackList *virDomainEventCallbackListPtr;
+
+void __virDomainEventCallbackListFree(virDomainEventCallbackListPtr list);
+#define 

[libvirt] Re: [PATCH 04/12] Domain Events - rpc changes

2008-10-17 Thread Ben Guthro
Changes to the RPC protocol

 remote_dispatch_localvars.h   |3 +++
 remote_dispatch_proc_switch.h |   18 ++
 remote_dispatch_prototypes.h  |3 +++
 remote_protocol.c |   35 +++
 remote_protocol.h |   28 
 remote_protocol.x |   23 ++-
 6 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/qemud/remote_dispatch_localvars.h b/qemud/remote_dispatch_localvars.h
index f46b493..df36239 100644
--- a/qemud/remote_dispatch_localvars.h
+++ b/qemud/remote_dispatch_localvars.h
@@ -6,6 +6,7 @@ remote_domain_lookup_by_uuid_args lv_remote_domain_lookup_by_uuid_args;
 remote_domain_lookup_by_uuid_ret lv_remote_domain_lookup_by_uuid_ret;
 remote_storage_pool_list_volumes_args lv_remote_storage_pool_list_volumes_args;
 remote_storage_pool_list_volumes_ret lv_remote_storage_pool_list_volumes_ret;
+remote_domain_events_deregister_args lv_remote_domain_events_deregister_args;
 remote_domain_shutdown_args lv_remote_domain_shutdown_args;
 remote_list_defined_domains_args lv_remote_list_defined_domains_args;
 remote_list_defined_domains_ret lv_remote_list_defined_domains_ret;
@@ -20,6 +21,7 @@ remote_domain_get_autostart_args lv_remote_domain_get_autostart_args;
 remote_domain_get_autostart_ret lv_remote_domain_get_autostart_ret;
 remote_domain_set_vcpus_args lv_remote_domain_set_vcpus_args;
 remote_get_hostname_ret lv_remote_get_hostname_ret;
+remote_domain_events_register_args lv_remote_domain_events_register_args;
 remote_network_undefine_args lv_remote_network_undefine_args;
 remote_domain_create_args lv_remote_domain_create_args;
 remote_network_destroy_args lv_remote_network_destroy_args;
@@ -121,6 +123,7 @@ remote_num_of_defined_storage_pools_ret lv_remote_num_of_defined_storage_pools_r
 remote_domain_core_dump_args lv_remote_domain_core_dump_args;
 remote_list_defined_storage_pools_args lv_remote_list_defined_storage_pools_args;
 remote_list_defined_storage_pools_ret lv_remote_list_defined_storage_pools_ret;
+remote_domain_event_ret lv_remote_domain_event_ret;
 remote_domain_get_max_memory_args lv_remote_domain_get_max_memory_args;
 remote_domain_get_max_memory_ret lv_remote_domain_get_max_memory_ret;
 remote_num_of_domains_ret lv_remote_num_of_domains_ret;
diff --git a/qemud/remote_dispatch_proc_switch.h b/qemud/remote_dispatch_proc_switch.h
index 89296d7..2254a96 100644
--- a/qemud/remote_dispatch_proc_switch.h
+++ b/qemud/remote_dispatch_proc_switch.h
@@ -116,6 +116,24 @@ case REMOTE_PROC_DOMAIN_DUMP_XML:
 ret = (char *) lv_remote_domain_dump_xml_ret;
 memset (lv_remote_domain_dump_xml_ret, 0, sizeof lv_remote_domain_dump_xml_ret);
 break;
+case REMOTE_PROC_DOMAIN_EVENT:
+fn = (dispatch_fn) remoteDispatchDomainEvent;
+ret_filter = (xdrproc_t) xdr_remote_domain_event_ret;
+ret = (char *) lv_remote_domain_event_ret;
+memset (lv_remote_domain_event_ret, 0, sizeof lv_remote_domain_event_ret);
+break;
+case REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER:
+fn = (dispatch_fn) remoteDispatchDomainEventsDeregister;
+args_filter = (xdrproc_t) xdr_remote_domain_events_deregister_args;
+args = (char *) lv_remote_domain_events_deregister_args;
+memset (lv_remote_domain_events_deregister_args, 0, sizeof lv_remote_domain_events_deregister_args);
+break;
+case REMOTE_PROC_DOMAIN_EVENTS_REGISTER:
+fn = (dispatch_fn) remoteDispatchDomainEventsRegister;
+args_filter = (xdrproc_t) xdr_remote_domain_events_register_args;
+args = (char *) lv_remote_domain_events_register_args;
+memset (lv_remote_domain_events_register_args, 0, sizeof lv_remote_domain_events_register_args);
+break;
 case REMOTE_PROC_DOMAIN_GET_AUTOSTART:
 fn = (dispatch_fn) remoteDispatchDomainGetAutostart;
 args_filter = (xdrproc_t) xdr_remote_domain_get_autostart_args;
diff --git a/qemud/remote_dispatch_prototypes.h b/qemud/remote_dispatch_prototypes.h
index 3f4eb9f..79e26e3 100644
--- a/qemud/remote_dispatch_prototypes.h
+++ b/qemud/remote_dispatch_prototypes.h
@@ -18,6 +18,9 @@ static int remoteDispatchDomainDefineXml (struct qemud_server *server, struct qe
 static int remoteDispatchDomainDestroy (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_domain_destroy_args *args, void *ret);
 static int remoteDispatchDomainDetachDevice (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_domain_detach_device_args *args, void *ret);
 static int remoteDispatchDomainDumpXml (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_domain_dump_xml_args *args, remote_domain_dump_xml_ret *ret);
+static int remoteDispatchDomainEvent (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_domain_event_ret *ret);
+static int 

[libvirt] Re: [PATCH 05/12] Domain Events - Driver API

2008-10-17 Thread Ben Guthro
Additions to the driver API

 driver.h |   19 +++
 1 file changed, 19 insertions(+)

diff --git a/src/driver.h b/src/driver.h
index 0540f80..c88dea8 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -280,6 +280,22 @@ typedef unsigned long long
 (*virDrvNodeGetFreeMemory)
 (virConnectPtr conn);
 
+typedef int
+(*virDrvDomainEventRegister)
+(virConnectPtr conn,
+ void *callback,
+ void *opaque);
+
+typedef int
+(*virDrvDomainEventDeregister)
+(virConnectPtr conn,
+ void *callback);
+
+typedef void
+(*virDrvDomainEventDispatch)
+(virDomainPtr dom,
+ virDomainEventType evt);
+
 /**
  * _virDriver:
  *
@@ -352,6 +368,9 @@ struct _virDriver {
 virDrvDomainMemoryPeek  domainMemoryPeek;
 virDrvNodeGetCellsFreeMemory	nodeGetCellsFreeMemory;
 virDrvNodeGetFreeMemory		getFreeMemory;
+virDrvDomainEventRegister domainEventRegister;
+virDrvDomainEventDeregister   domainEventDeregister;
+virDrvDomainEventDispatch domainEventDispatch;
 };
 
 typedef int

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


[libvirt] Re: [PATCH 07/12] Domain Events - remote driver

2008-10-17 Thread Ben Guthro
Deliver local callbacks in response to remote events

 remote_internal.c |  255 --
 1 file changed, 248 insertions(+), 7 deletions(-)
diff --git a/src/remote_internal.c b/src/remote_internal.c
index 35b7b4b..13537f7 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -34,6 +34,7 @@
 #include signal.h
 #include sys/types.h
 #include sys/stat.h
+#include sys/poll.h
 #include fcntl.h
 
 #ifdef HAVE_SYS_WAIT_H
@@ -73,6 +74,7 @@
 #include remote_protocol.h
 #include memory.h
 #include util.h
+#include event.h
 
 /* Per-connection private data. */
 #define MAGIC 999   /* private_data-magic if OK */
@@ -97,6 +99,10 @@ struct private_data {
 unsigned int saslDecodedLength;
 unsigned int saslDecodedOffset;
 #endif
+
+virDomainEventQueuePtr domainEvents; /* The queue of events generated
+  * during a call / response rpc */
+int eventFlushTimer; /* Timer for flushing domainEvents queue */
 };
 
 #define GET_PRIVATE(conn,retcode)   \
@@ -156,7 +162,10 @@ static void make_nonnull_domain (remote_nonnull_domain *dom_dst, virDomainPtr do
 static void make_nonnull_network (remote_nonnull_network *net_dst, virNetworkPtr net_src);
 static void make_nonnull_storage_pool (remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr vol_src);
 static void make_nonnull_storage_vol (remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src);
-
+void remoteDomainEventFired(int fd, int event, void *data);
+static void remoteDomainProcessEvent(virConnectPtr conn, XDR *xdr);
+static void remoteDomainQueueEvent(virConnectPtr conn, XDR *xdr);
+void remoteDomainEventQueueFlush(int timer, void *opaque);
 /*--*/
 
 /* Helper functions for remoteOpen. */
@@ -680,6 +689,26 @@ doRemoteOpen (virConnectPtr conn,
   (xdrproc_t) xdr_void, (char *) NULL) == -1)
 goto failed;
 
+if(VIR_ALLOC(priv-domainEvents)0) {
+error(conn, VIR_ERR_INVALID_ARG, _(Error allocating domainEvents));
+goto failed;
+}
+
+DEBUG0(Adding Handler for remote events);
+/* Set up a callback to listen on the socket data */
+if (virEventAddHandle(priv-sock,
+  POLLIN | POLLERR | POLLHUP,
+  remoteDomainEventFired,
+  conn)  0) {
+DEBUG0(virEventAddHandle failed: No addHandleImpl defined. continuing without events.);
+}
+
+DEBUG0(Adding Timeout for remote event queue flushing);
+if ( (priv-eventFlushTimer = virEventAddTimeout(0,
+ remoteDomainEventQueueFlush,
+ conn))  0) {
+DEBUG0(virEventAddTimeout failed: No addTimeoutImpl defined. continuing without events.);
+}
 /* Successful. */
 retcode = VIR_DRV_OPEN_SUCCESS;
 
@@ -1101,6 +1130,11 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv)
   (xdrproc_t) xdr_void, (char *) NULL) == -1)
 return -1;
 
+/* Remove handle for remote events */
+virEventRemoveHandle(priv-sock);
+/* Remove timout */
+virEventRemoveTimeout(priv-eventFlushTimer);
+
 /* Close socket. */
 if (priv-uses_tls  priv-session) {
 gnutls_bye (priv-session, GNUTLS_SHUT_RDWR);
@@ -1132,6 +1166,9 @@ doRemoteClose (virConnectPtr conn, struct private_data *priv)
 /* Free private data. */
 priv-magic = DEAD;
 
+/* Free queued events */
+virDomainEventQueueFree(priv-domainEvents);
+
 return 0;
 }
 
@@ -4288,6 +4325,46 @@ remoteAuthPolkit (virConnectPtr conn, struct private_data *priv, int in_open,
 return 0;
 }
 #endif /* HAVE_POLKIT */
+/*--*/
+
+static int remoteDomainEventRegister (virConnectPtr conn,
+   void *callback,
+   void *opaque)
+{
+struct private_data *priv = conn-privateData;
+
+/* dispatch an rpc - so the server sde can track
+   how many callbacks are regstered */
+remote_domain_events_register_args args;
+args.callback = (unsigned long)callback;
+args.user_data = (unsigned long)opaque;
+
+if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_REGISTER,
+  (xdrproc_t) xdr_remote_domain_events_register_args, (char *) args,
+  (xdrproc_t) xdr_void, (char *) NULL) == -1)
+return -1;
+
+
+return 0;
+}
+
+static int remoteDomainEventDeregister (virConnectPtr conn,
+ void *callback)
+{
+struct private_data *priv = conn-privateData;
+
+/* dispatch an rpc - so the server sde can track
+how many callbacks are regstered */
+remote_domain_events_deregister_args args;
+args.callback = (unsigned long)callback;
+
+if (call 

[libvirt] Re: [PATCH 06/12] Domain Events - qemu driver

2008-10-17 Thread Ben Guthro
 Register for, and dispatch domain event callbacks

 qemu_conf.h   |3 ++
 qemu_driver.c |   76 --
 2 files changed, 77 insertions(+), 2 deletions(-)


diff --git a/src/qemu_conf.h b/src/qemu_conf.h
index cfd7d35..d06c4d7 100644
--- a/src/qemu_conf.h
+++ b/src/qemu_conf.h
@@ -63,6 +63,9 @@ struct qemud_driver {
 char *vncListen;
 
 virCapsPtr caps;
+
+/* An array of callbacks */
+virDomainEventCallbackListPtr domainEventCallbacks;
 };
 
 
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index a86b787..9792541 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -159,6 +159,10 @@ qemudStartup(void) {
 /* Don't have a dom0 so start from 1 */
 qemu_driver-nextvmid = 1;
 
+/* Init callback list */
+if(VIR_ALLOC(qemu_driver-domainEventCallbacks)  0)
+return -1;
+
 if (!uid) {
 if (asprintf(qemu_driver-logDir,
  %s/log/libvirt/qemu, LOCAL_STATE_DIR) == -1)
@@ -301,6 +305,9 @@ qemudShutdown(void) {
 VIR_FREE(qemu_driver-autostartDir);
 VIR_FREE(qemu_driver-vncTLSx509certdir);
 
+/* Free domain callback list */
+virDomainEventCallbackListFree(qemu_driver-domainEventCallbacks);
+
 if (qemu_driver-brctl)
 brShutdown(qemu_driver-brctl);
 
@@ -742,6 +749,8 @@ static int qemudNextFreeVNCPort(struct qemud_driver *driver ATTRIBUTE_UNUSED) {
 return -1;
 }
 
+static virDomainPtr qemudDomainLookupByName(virConnectPtr conn, const char *name);
+
 static int qemudStartVMDaemon(virConnectPtr conn,
   struct qemud_driver *driver,
   virDomainObjPtr vm,
@@ -756,6 +765,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
 unsigned int qemuCmdFlags;
 fd_set keepfd;
 const char *emulator;
+virDomainPtr dom;
 
 FD_ZERO(keepfd);
 
@@ -918,6 +928,11 @@ static int qemudStartVMDaemon(virConnectPtr conn,
 qemudShutdownVMDaemon(conn, driver, vm);
 return -1;
 }
+dom = qemudDomainLookupByName(conn,vm-def-name);
+if(dom)
+virDispatchDomainEvent(dom, VIR_DOMAIN_EVENT_STARTED);
+else
+DEBUG0(Warning - dom is NULL at domain start);
 }
 
 return ret;
@@ -1503,6 +1518,7 @@ static int qemudDomainSuspend(virDomainPtr dom) {
 }
 vm-state = VIR_DOMAIN_PAUSED;
 qemudDebug(Reply %s, info);
+virDispatchDomainEvent(dom, VIR_DOMAIN_EVENT_SUSPENDED);
 VIR_FREE(info);
 return 0;
 }
@@ -1531,6 +1547,7 @@ static int qemudDomainResume(virDomainPtr dom) {
 }
 vm-state = VIR_DOMAIN_RUNNING;
 qemudDebug(Reply %s, info);
+virDispatchDomainEvent(dom, VIR_DOMAIN_EVENT_RESUMED);
 VIR_FREE(info);
 return 0;
 }
@@ -1572,7 +1589,7 @@ static int qemudDomainDestroy(virDomainPtr dom) {
 if (!vm-persistent)
 virDomainRemoveInactive(driver-domains,
 vm);
-
+virDispatchDomainEvent(dom, VIR_DOMAIN_EVENT_STOPPED);
 return 0;
 }
 
@@ -1903,7 +1920,7 @@ static int qemudDomainSave(virDomainPtr dom,
 if (!vm-persistent)
 virDomainRemoveInactive(driver-domains,
 vm);
-
+virDispatchDomainEvent(dom, VIR_DOMAIN_EVENT_SAVED);
 return 0;
 }
 
@@ -2104,6 +2121,7 @@ static int qemudDomainRestore(virConnectPtr conn,
 struct qemud_driver *driver = (struct qemud_driver *)conn-privateData;
 virDomainDefPtr def;
 virDomainObjPtr vm;
+virDomainPtrdom;
 int fd;
 int ret;
 char *xml;
@@ -2210,6 +2228,11 @@ static int qemudDomainRestore(virConnectPtr conn,
 vm-state = VIR_DOMAIN_RUNNING;
 }
 
+dom = virDomainLookupByID(conn, def-id);
+if(dom) {
+virDispatchDomainEvent(dom, VIR_DOMAIN_EVENT_RESTORED);
+VIR_FREE(dom);
+}
 return 0;
 }
 
@@ -3051,6 +3074,52 @@ done:
 }
 
 
+static int qemudDomainEventRegister (virConnectPtr conn,
+ void *callback,
+ void *opaque)
+{
+struct qemud_driver *driver = (struct qemud_driver *)conn-privateData;
+
+return virDomainEventCallbackListAdd(conn, driver-domainEventCallbacks, callback, opaque);
+}
+
+static int qemudDomainEventDeregister (virConnectPtr conn,
+ void *callback)
+{
+struct qemud_driver *driver = (struct qemud_driver *)conn-privateData;
+
+return virDomainEventCallbackListRemove(conn, driver-domainEventCallbacks, callback);
+}
+
+static void qemudDomainEventDispatch (virDomainPtr dom,
+  virDomainEventType evt)
+{
+int i;
+struct qemud_driver *driver;
+virDomainEventCallbackListPtr cbList;
+
+if(!dom-conn) {
+DEBUG0(Invalid conn);
+return;
+}
+driver = (struct qemud_driver *)dom-conn-privateData;
+
+if(!driver) {
+DEBUG0(Invalid driver);
+return;
+}
+cbList = 

[libvirt] Re: [PATCH 08/12] Domain Events - lxc driver

2008-10-17 Thread Ben Guthro
Minor changes to LXC driver structure to prevent compile errors

 lxc_driver.c |3 +++
 1 file changed, 3 insertions(+)
diff --git a/src/lxc_driver.c b/src/lxc_driver.c
index c598d1d..56e68fc 100644
--- a/src/lxc_driver.c
+++ b/src/lxc_driver.c
@@ -1278,6 +1278,9 @@ static virDriver lxcDriver = {
 NULL, /* domainMemoryPeek */
 NULL, /* nodeGetCellsFreeMemory */
 NULL, /* getFreeMemory */
+NULL, /* domainEventRegister */
+NULL, /* domainEventDeregister */
+NULL, /* domainEventDispatch */
 };
 
 static virStateDriver lxcStateDriver = {
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] Re: [PATCH 10/12] Domain Events - test driver

2008-10-17 Thread Ben Guthro
Minor changes to test driver structure to prevent compile errors

 test.c |3 +++
 1 file changed, 3 insertions(+)
diff --git a/src/test.c b/src/test.c
index aab74e4..9f40576 100644
--- a/src/test.c
+++ b/src/test.c
@@ -1552,6 +1552,9 @@ static virDriver testDriver = {
 NULL, /* domainMemoryPeek */
 testNodeGetCellsFreeMemory, /* nodeGetCellsFreeMemory */
 NULL, /* getFreeMemory */
+NULL, /* domainEventRegister */
+NULL, /* domainEventDeregister */
+NULL, /* domainEventDispatch */
 };
 
 static virNetworkDriver testNetworkDriver = {
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] Re: [PATCH 11/12] Domain Events - test harness

2008-10-17 Thread Ben Guthro
Test app, and infrastructure changes for an example dir

 Makefile.am  |2
 configure.in |3
 examples/domain-events/events-c/Makefile.am  |5
 examples/domain-events/events-c/event-test.c |  214 +++
 libvirt.spec.in  |3
 5 files changed, 225 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 073063d..d40a151 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,7 +4,7 @@ LCOV = lcov
 GENHTML = genhtml
 
 SUBDIRS = gnulib/lib include src qemud proxy docs gnulib/tests \
-  python tests po
+  python tests po examples/domain-events/events-c
 
 ACLOCAL_AMFLAGS = -I m4 -I gnulib/m4
 
diff --git a/configure.in b/configure.in
index 497251f..9be3fec 100644
--- a/configure.in
+++ b/configure.in
@@ -1072,7 +1072,8 @@ AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
   tests/sexpr2xmldata/Makefile \
   tests/xmconfigdata/Makefile \
   tests/xencapsdata/Makefile \
-  tests/virshdata/Makefile tests/confdata/Makefile)
+  tests/virshdata/Makefile tests/confdata/Makefile \
+  examples/domain-events/events-c/Makefile)
 
 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([Configuration summary])
diff --git a/examples/domain-events/events-c/Makefile.am b/examples/domain-events/events-c/Makefile.am
new file mode 100644
index 000..1788dac
--- /dev/null
+++ b/examples/domain-events/events-c/Makefile.am
@@ -0,0 +1,5 @@
+INCLUDES = [EMAIL PROTECTED]@/include
+bin_PROGRAMS = event-test
+event_test_CFLAGS = $(WARN_CFLAGS)
+event_test_SOURCES = event-test.c
+event_test_LDADD = [EMAIL PROTECTED]@/src/.libs -lvirt
diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
new file mode 100644
index 000..f26ffdb
--- /dev/null
+++ b/examples/domain-events/events-c/event-test.c
@@ -0,0 +1,214 @@
+#include config.h
+#include stdio.h
+#include string.h
+#include sys/types.h
+#include sys/poll.h
+#include libvirt/libvirt.h
+
+#define DEBUG0(fmt) printf(%s:%d ::  fmt \n, __FUNCTION__, __LINE__)
+#define DEBUG(fmt, ...) printf(%s:%d:  fmt \n, __FUNCTION__, __LINE__, __VA_ARGS__)
+#define STREQ(a,b) (strcmp((a),(b)) == 0)
+
+#ifndef ATTRIBUTE_UNUSED
+#define ATTRIBUTE_UNUSED __attribute__((__unused__))
+#endif
+
+/* handle globals */
+int h_fd = 0;
+int h_event = 0;
+virEventHandleCallback h_cb = NULL;
+void *h_opaque = NULL;
+
+/* timeout globals */
+#define TIMEOUT_MS 1000
+int t_timeout = -1;
+virEventTimeoutCallback t_cb = NULL;
+void *t_opaque = NULL;
+
+
+/* Prototypes */
+const char *eventToString(int event);
+int myDomainEventCallback1 (virConnectPtr conn, virDomainPtr dom, int event, void *opaque);
+int myDomainEventCallback2 (virConnectPtr conn, virDomainPtr dom, int event, void *opaque);
+
+int myEventAddHandleFunc  (int fd, int event, virEventHandleCallback cb, void *opaque);
+void myEventUpdateHandleFunc(int fd, int event);
+int  myEventRemoveHandleFunc(int fd);
+
+int myEventAddTimeoutFunc(int timeout, virEventTimeoutCallback cb, void *opaque);
+void myEventUpdateTimeoutFunc(int timer, int timout);
+int myEventRemoveTimeoutFunc(int timer);
+
+void usage(const char *pname);
+
+/* Callback functions */
+
+const char *eventToString(int event) {
+const char *ret = NULL;
+switch(event) {
+case VIR_DOMAIN_EVENT_ADDED:
+ret =Added;
+break;
+case VIR_DOMAIN_EVENT_REMOVED:
+ret =Removed;
+break;
+case VIR_DOMAIN_EVENT_STARTED:
+ret =Started;
+break;
+case VIR_DOMAIN_EVENT_SUSPENDED:
+ret =Suspended;
+break;
+case VIR_DOMAIN_EVENT_RESUMED:
+ret =Resumed;
+break;
+case VIR_DOMAIN_EVENT_STOPPED:
+ret =Stopped;
+break;
+case VIR_DOMAIN_EVENT_SAVED:
+ret =Saved;
+break;
+case VIR_DOMAIN_EVENT_RESTORED:
+ret =Restored;
+break;
+default:
+ret =Unknown Event;
+}
+return ret;
+}
+
+int myDomainEventCallback1 (virConnectPtr conn ATTRIBUTE_UNUSED,
+virDomainPtr dom,
+int event,
+void *opaque ATTRIBUTE_UNUSED)
+{
+printf(%s EVENT: Domain %s(%d) %s\n, __FUNCTION__, virDomainGetName(dom), virDomainGetID(dom), eventToString(event));
+return 0;
+}
+
+int myDomainEventCallback2 (virConnectPtr conn ATTRIBUTE_UNUSED,
+virDomainPtr dom,
+int event,
+void *opaque ATTRIBUTE_UNUSED)
+{
+printf(%s EVENT: Domain %s(%d) %s\n, __FUNCTION__, virDomainGetName(dom), virDomainGetID(dom), eventToString(event));
+return 0;
+}
+
+
+/* EventImpl Functions */
+
+int  myEventAddHandleFunc(int fd, int event, virEventHandleCallback cb, void *opaque)
+{
+

[libvirt] Re: [PATCH 12/12] Domain Events - python

2008-10-17 Thread Ben Guthro
Add functions to be ignored, to prevent rpm build failures

 generator.py |3 +++
 1 file changed, 3 insertions(+)
diff --git a/python/generator.py b/python/generator.py
index c706b19..ca83eaf 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -332,6 +332,9 @@ skip_function = (
 'virCopyLastError', # Python API is called virGetLastError instead
 'virConnectOpenAuth', # Python C code is manually written
 'virDefaultErrorFunc', # Python virErrorFuncHandler impl calls this from C
+'virConnectDomainEventRegister', # TODO: generate python bindings for these below XXX
+'virConnectDomainEventDeregister',
+'virEventRegisterImpl',
 )
 
 
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/3] Domain events - primary implementation

2008-10-15 Thread Ben Guthro
I've been off implementing all of these changes, and I came across a point I 
would like to discuss, and get your opinion on.

...
 In fat I think this scheme ought to let you do away with the mutex
 locking completely. The contract for virConnectPtr dictates that
 you are forbidden to use a single virConnectPtr object from more than
 one thread at once, so if we're queueing  dispatching events from
 and timeout handler, we shouldn't ever get a reentrancy/locking 
 problem.

We potentially have a race condition for pulling data off the wire by the 
following functions:

call()
remoteDomainEventFired()

These 2 functions lock on not the connection lock, but the private_data-lock.

Since the remoteDomainEventFired() is called from a client app via HandleImpl - 
it has no
knowledge of that the opaque pointer being passed is a conn. 

There is nothing constraining the EventImpl from making a callback while using 
a conn ptr in another thread.

So - if that callback happens concurrent with an explicit use of the conn ptr 
bad things will happen.


 

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


[libvirt] [PATCH 0/3] Domain events - overview

2008-10-09 Thread Ben Guthro
The following patch series implements the Events API discussed here previously 
in this thread:
http://www.redhat.com/archives/libvir-list/2008-September/msg00321.html

This is a rather large patch, and touches quite a few files, but in the end, 
accomplishes the goal of event delivery of notificaton of domain events.

It does so in a manner that is able to co-exist with older clients, or older 
libvirtd implementations. 
  In the former case, events will never be delivered to a client that does not 
request them.
  In the latter case, we will fail registration, and so events will not be 
available.

I have broken this up into 3 patches in the following manner:
1/3 - events.patch
This is the bulk of the work. It emits, and delivers events to clients that 
are supported, and have registered to recieve the events.

2/3 - events-xen.patch
These changes are currently untested (as I did my development with KVM), 
but are the changes that will be necessary to monitor xenstore for changes in 
domain states

3/3 - events-test.patch
This is a test harness implemented to receive (and print) when domain 
events occur. I was unsure where this should live in the tree - so it currently 
is an independant patch (.c and Makefile in its own dir)

Please note that I have not yet made any effort to generate any Python, or Java 
bindings, but wanted to get this out on the list first.

NOTES:
Thread safeness:
We know that there are 2 data structures that need protection against 
concurrent access
_virDriver.conns and 
_virConnect.domainEventCallbacks

However, we have not addressed these issues at this juncture. 
We are considering recursive mutexes (specifically making conn-lock one) to 
avoid deadlocks in a vir* call from within a callback. We plan on addressing 
this with the next version of this code, after addressing any other issues the 
list may come up with, as well.

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


Re: [libvirt] [PATCH 2/3] Domain events - xen

2008-10-09 Thread Ben Guthro
Monitor xenstore for domain changes
NOTE: this patch is currently untested

Signed-off-by: Ben Guthro [EMAIL PROTECTED]

 proxy/Makefile.am |1
 src/xen_unified.c |8 ++
 src/xen_unified.h |3
 src/xs_internal.c |  176 ++
 src/xs_internal.h |   39 +++
 5 files changed, 227 insertions(+)
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 5902cab..75ba6b4 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -17,6 +17,7 @@ libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \
 @top_srcdir@/src/memory.c \
 @top_srcdir@/src/domain_conf.c \
 @top_srcdir@/src/util.c \
+	@top_srcdir@/src/event.c \
 	@top_srcdir@/src/uuid.c
 libvirt_proxy_LDFLAGS = $(WARN_CFLAGS)
 libvirt_proxy_DEPENDENCIES =
diff --git a/src/xen_unified.c b/src/xen_unified.c
index dae68d3..4ebf347 100644
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -1294,6 +1294,12 @@ xenUnifiedNodeGetFreeMemory (virConnectPtr conn)
 return(0);
 }
 
+static int
+xenUnifiedDomainEventEmitted (virDomainEventType evt)
+{
+return xenStoreDomainEventEmitted(evt);
+}
+
 /*- Register with libvirt.c, and initialise Xen drivers. -*/
 
 #define HV_VERSION ((DOM0_INTERFACE_VERSION  24) * 100 + \
@@ -1305,6 +1311,7 @@ static virDriver xenUnifiedDriver = {
 .no = VIR_DRV_XEN_UNIFIED,
 .name = Xen,
 .ver = HV_VERSION,
+.conns = NULL,
 .probe 			= xenUnifiedProbe,
 .open 			= xenUnifiedOpen,
 .close 			= xenUnifiedClose,
@@ -1359,6 +1366,7 @@ static virDriver xenUnifiedDriver = {
 .domainBlockPeek	= xenUnifiedDomainBlockPeek,
 .nodeGetCellsFreeMemory = xenUnifiedNodeGetCellsFreeMemory,
 .getFreeMemory = xenUnifiedNodeGetFreeMemory,
+.domainEventEmitted = xenUnifiedDomainEventEmitted,
 };
 
 /**
diff --git a/src/xen_unified.h b/src/xen_unified.h
index c17b498..e4e7a59 100644
--- a/src/xen_unified.h
+++ b/src/xen_unified.h
@@ -12,6 +12,7 @@
 #define __VIR_XEN_UNIFIED_H__
 
 #include internal.h
+#include xs_internal.h
 #include capabilities.h
 
 #ifndef HAVE_WINSOCK2_H
@@ -110,6 +111,8 @@ struct _xenUnifiedPrivate {
  * xen_unified.c.
  */
 int opened[XEN_UNIFIED_NR_DRIVERS];
+
+xenStoreWatchListPtr xsWatchHead;
 };
 
 typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr;
diff --git a/src/xs_internal.c b/src/xs_internal.c
index 316604a..e60549b 100644
--- a/src/xs_internal.c
+++ b/src/xs_internal.c
@@ -17,6 +17,7 @@
 #include fcntl.h
 #include sys/mman.h
 #include sys/ioctl.h
+#include sys/poll.h
 
 #include stdint.h
 
@@ -28,6 +29,8 @@
 
 #include internal.h
 #include driver.h
+#include memory.h
+#include event.h
 #include xen_unified.h
 #include xs_internal.h
 #include xen_internal.h /* for xenHypervisorCheckID */
@@ -40,6 +43,9 @@
 #error unsupported platform
 #endif
 
+#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
+#define DEBUG0(msg) VIR_DEBUG(__FILE__, %s, msg)
+
 #ifndef PROXY
 static char *xenStoreDomainGetOSType(virDomainPtr domain);
 
@@ -319,6 +325,19 @@ xenStoreOpen(virConnectPtr conn,
 }
 return (-1);
 }
+
+/* Register for domain watch callbacks */
+xenStoreAddWatch(priv-xsWatchHead, @introduceDomain,
+ introduceDomain, xenStoreDomainIntroduced, priv);
+xenStoreAddWatch(priv-xsWatchHead, @releaseDomain,
+ releaseDomain, xenStoreDomainReleased, priv);
+/* Add an event handle */
+if (virEventAddHandle(xs_fileno(priv-xshandle),
+  POLLIN | POLLPRI,
+  xenStoreWatchEvent,
+  conn)  0) {
+return (-1);
+}
 return (0);
 }
 
@@ -344,6 +363,7 @@ xenStoreClose(virConnectPtr conn)
 if (priv-xshandle == NULL)
 return(-1);
 
+xenStoreWatchListFree(priv-xsWatchHead);
 xs_daemon_close(priv-xshandle);
 return (0);
 }
@@ -937,3 +957,159 @@ char *xenStoreDomainGetName(virConnectPtr conn,
 return xs_read(priv-xshandle, 0, prop, len);
 }
 
+void xenStoreWatchListFree(xenStoreWatchListPtr head)
+{
+while (head) {
+xenStoreWatchListPtr p = head-next;
+VIR_FREE(head-path);
+VIR_FREE(head-token);
+VIR_FREE(head);
+head = p;
+}
+}
+
+int xenStoreAddWatch(xenStoreWatchListPtr head,
+ const char *path,
+ const char *token,
+ xenStoreWatchCallback cb,
+ void *opaque)
+{
+xenStoreWatchListPtr watch;
+xenStoreWatchListPtr p = head;
+
+if (VIR_ALLOC(watch)  0)
+return -1;
+watch-path   = strdup(path);
+watch-token  = strdup(token);
+watch-cb = cb;
+watch-opaque = opaque;
+
+/* find end of list */
+while(p) p = p-next;
+
+DEBUG(Added xs watch %s %s, path, token);
+p = watch;
+return 0;
+}
+
+int xenStoreRemoveWatch

Re: [libvirt] [PATCH 3/3] Domain events - test harness

2008-10-09 Thread Ben Guthro
This test app prints domain events as they are emitted.
I was not sure where it belonged in the tree - so this is not in the context of 
the rest of the libvirt tree

Signed-off-by: Ben Guthro [EMAIL PROTECTED]

 Makefile |2
 event-test.c |  134 +++
 2 files changed, 136 insertions(+)
--- /dev/null	2008-09-18 12:09:06 -04:00
+++ ./event-test.c	2008-10-03 14:31:49 -04:00
@@ -0,0 +1,134 @@
+#include stdio.h
+#include sys/types.h
+#include sys/poll.h
+
+#include libvirt/libvirt.h
+
+#define DEBUG0(fmt) printf(%s:%d ::  fmt \n, __FUNCTION__, __LINE__)
+#define DEBUG(fmt, ...) printf(%s:%d:  fmt \n, __FUNCTION__, __LINE__, __VA_ARGS__)
+
+int g_fd = 0;
+int g_event = 0;
+virEventHandleCallback g_cb = NULL;
+void *g_opaque = NULL;
+#define TIMEOUT_MS 1000
+
+int myDomainEventCallback (virConnectPtr conn,
+virDomainPtr dom,
+int event,
+void *opaque)
+{
+printf(EVENT: Domain %s(%d) , virDomainGetName(dom), virDomainGetID(dom));
+switch(event) {
+case VIR_DOMAIN_EVENT_ADDED:
+printf(Added);
+break;
+case VIR_DOMAIN_EVENT_REMOVED:
+printf(Removed);
+break;
+case VIR_DOMAIN_EVENT_STARTED:
+printf(Started);
+break;
+case VIR_DOMAIN_EVENT_SUSPENDED:
+printf(Suspended);
+break;
+case VIR_DOMAIN_EVENT_RESUMED:
+printf(Resumed);
+break;
+case VIR_DOMAIN_EVENT_STOPPED:
+printf(Stopped);
+break;
+case VIR_DOMAIN_EVENT_SAVED:
+printf(Saved);
+break;
+case VIR_DOMAIN_EVENT_RESTORED:
+printf(Restored);
+break;
+default:
+printf(Unknown Event);
+}
+printf(\n);
+return 0;
+}
+
+int  myEventAddHandleFunc(int fd, int event, virEventHandleCallback cb, void *opaque)
+{
+DEBUG(Add handle %d %d %p %p, fd, event, cb, opaque);
+g_fd = fd;
+g_event = event;
+g_cb = cb;
+g_opaque = opaque;
+return 0;
+}
+void myEventUpdateHandleFunc(int fd, int event)
+{
+DEBUG(Updated Handle %d %d, fd, event);
+return;
+}
+int  myEventRemoveHandleFunc(int fd)
+{
+DEBUG(Removed Handle %d, fd);
+return 0;
+}
+
+void virEventRegisterHandleImpl(virEventAddHandleFunc addHandle,
+virEventUpdateHandleFunc updateHandle,
+virEventRemoveHandleFunc removeHandle);
+
+void usage(const char *pname)
+{
+printf(%s uri\n, pname);
+}
+int main(int argc, char **argv)
+{
+int run=1;
+int sts;
+
+if(argv[1]  strcmp(argv[1],--help)==0) { 
+usage(argv[0]);
+return -1;
+}
+virEventRegisterHandleImpl( myEventAddHandleFunc, 
+myEventUpdateHandleFunc,
+myEventRemoveHandleFunc);
+virConnectPtr dconn = NULL;
+dconn = virConnectOpen (argv[1] ? argv[1] : qemu:///system);
+if (!dconn) {
+printf(error opening\n);
+return -1;
+}
+
+DEBUG0(Registering domain event cb);
+virConnectDomainEventRegister(dconn, myDomainEventCallback, NULL);
+
+while(run) {
+struct pollfd pfd = { .fd = g_fd, 
+  .events = g_event,
+  .revents = 0};
+
+sts = poll(pfd, 1, TIMEOUT_MS);
+if (sts == 0) {
+/* DEBUG0(Poll timeout); */
+continue;
+}
+if (sts  0 ) {
+DEBUG0(Poll failed);
+continue;
+}
+if ( pfd.revents  POLLHUP ) {
+DEBUG0(Reset by peer);
+return -1;
+}
+
+DEBUG(sts = %d, sts);
+DEBUG(Calling CB: %p (%d,%d,%p), g_cb, g_fd, g_event, g_opaque);
+g_cb(g_fd, g_event, g_opaque);
+
+}
+
+if( dconn  virConnectClose(dconn)0 ) {
+printf(error closing\n);
+}
+printf(done\n);
+}
+
--- /dev/null	2008-09-18 12:09:06 -04:00
+++ ./Makefile	2008-09-30 12:56:44 -04:00
@@ -0,0 +1,2 @@
+LDFLAGS += -lvirt
+event-test: event-test.c
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


RE: [libvirt] [PATCH] Don't remove devel files in spec

2008-09-18 Thread Ben Guthro
Hrm. My apologies for missing this piece. 
I thought I tested that prior to the second submission...but clearly I missed 
it.

+1 for me.

Ben

-Original Message-
From: [EMAIL PROTECTED] on behalf of Daniel P. Berrange
Sent: Thu 9/18/2008 6:20 AM
To: Cole Robinson
Cc: libvir-list@redhat.com
Subject: Re: [libvirt] [PATCH] Don't remove devel files in spec
 
On Wed, Sep 17, 2008 at 02:20:17PM -0400, Cole Robinson wrote:
 The second iteration of the spec file enhancements
 didn't fully remove some pieces that were dependent
 on the devel package switch. The attached patch fixes
 'make rpm' to work again.

I've just applied the very same fix myself.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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

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


Re: [libvirt] [PATCH] spec file enhancements for minimal client-only build

2008-09-17 Thread Ben Guthro

No - we don't (AFAIK)

Patch attached, without the text mangling. I'll read over the article 
about making Thunderbird not suck before my next patch submission (or 
I'll just submit as attachments)



Richard W.M. Jones wrote on 09/17/2008 06:31 AM:

On Wed, Sep 17, 2008 at 11:30:23AM +0100, Richard W.M. Jones wrote:
  

On Tue, Sep 16, 2008 at 10:20:54AM -0400, Ben Guthro wrote:


New patch below, with changes discussed (removal of --without devel)
  

+1



Ben, do you/VirtualIron have commit access now?

Rich.

  
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 18b2127..cc5aca5 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1,11 +1,15 @@
 # -*- rpm-spec -*-
 
-%define with_xen   1
-%define with_xen_proxy 1
-%define with_qemu  1
-%define with_openvz1
-%define with_lxc   1
-%define with_polkit0
+%define with_xen   0%{!?_without_xen:1}
+%define with_xen_proxy 0%{!?_without_xen_proxy:1}
+%define with_qemu  0%{!?_without_qemu:1}
+%define with_openvz0%{!?_without_openvz:1}
+%define with_lxc   0%{!?_without_lxc:1}
+%define with_sasl  0%{!?_without_sasl:1}
+%define with_avahi 0%{!?_without_avahi:1}
+%define with_polkit0%{!?_without_polkit:0}
+%define with_python0%{!?_without_python:1}
+%define with_libvirtd  0%{!?_without_libvirtd:1}
 
 # Xen is available only on i386 x86_64 ia64
 %ifnarch i386 i686 x86_64 ia64
@@ -23,7 +27,7 @@
 %endif
 
 %if 0%{fedora} = 8
-%define with_polkit1
+%define with_polkit0%{!?_without_polkit:1}
 %define with_xen_proxy 0
 %endif
 
@@ -46,10 +50,12 @@ Requires: iptables
 # So remote clients can access libvirt over SSH tunnel
 # (client invokes 'nc' against the UNIX socket on the server)
 Requires: nc
+%if %{with_sasl}
 Requires: cyrus-sasl
 # Not technically required, but makes 'out-of-box' config
 # work correctly  doesn't have onerous dependencies
 Requires: cyrus-sasl-md5
+%endif
 %if %{with_polkit}
 Requires: PolicyKit = 0.6
 %endif
@@ -82,14 +88,18 @@ BuildRequires: readline-devel
 BuildRequires: ncurses-devel
 BuildRequires: gettext
 BuildRequires: gnutls-devel
+%if %{with_avahi}
 BuildRequires: avahi-devel
+%endif
 BuildRequires: libselinux-devel
 BuildRequires: dnsmasq
 BuildRequires: bridge-utils
 %if %{with_qemu}
 BuildRequires: qemu
 %endif
+%if %{with_sasl}
 BuildRequires: cyrus-sasl-devel
+%endif
 %if %{with_polkit}
 BuildRequires: PolicyKit-devel = 0.6
 %endif
@@ -133,6 +143,7 @@ Obsoletes: libvir-devel
 Includes and documentations for the C library providing an API to use
 the virtualization capabilities of recent versions of Linux (and other OSes).
 
+%if %{with_python}
 %package python
 Summary: Python bindings for the libvirt library
 Group: Development/Libraries
@@ -144,6 +155,7 @@ The libvirt-python package contains a module that permits applications
 written in the Python programming language to use the interface
 supplied by the libvirt library to use the virtualization capabilities
 of recent versions of Linux (and other OSes).
+%endif
 
 %prep
 %setup -q
@@ -165,10 +177,35 @@ of recent versions of Linux (and other OSes).
 %define _without_lxc --without-lxc
 %endif
 
+%if ! %{with_sasl}
+%define _without_sasl --without-sasl
+%endif
+
+%if ! %{with_avahi}
+%define _without_avahi --without-avahi
+%endif
+
+%if ! %{with_polkit}
+%define _without_polkit --without-polkit
+%endif
+
+%if ! %{with_python}
+%define _without_python --without-python
+%endif
+
+%if ! %{with_libvirtd}
+%define _without_libvirtd --without-libvirtd
+%endif
+
 %configure %{?_without_xen} \
%{?_without_qemu} \
%{?_without_openvz} \
%{?_without_lxc} \
+   %{?_without_sasl} \
+   %{?_without_avahi} \
+   %{?_without_polkit} \
+   %{?_without_python} \
+   %{?_without_libvirtd} \
--with-init-script=redhat \
--with-qemud-pid-file=%{_localstatedir}/run/libvirt_qemud.pid \
--with-remote-file=%{_localstatedir}/run/libvirtd.pid
@@ -190,6 +227,7 @@ install -d -m 0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/libvirt/images/
 # Default dir for kernel+initrd images defnied in SELinux policy
 install -d -m 0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/libvirt/boot/
 
+%if %{with_qemu}
 # We don't want to install /etc/libvirt/qemu/networks in the main %files list
 # because if the admin wants to delete the default network completely, we don't
 # want to end up re-incarnating it on every RPM upgrade.
@@ -200,14 +238,31 @@ rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/default.xml
 rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/autostart/default.xml
 # Strip auto-generated UUID - we need it generated per-install
 sed -i -e /uuid/d $RPM_BUILD_ROOT%{_datadir}/libvirt/networks/default.xml
+%endif
 %find_lang %{name}
 
+# If we are not building with certain options, we need to remove files
+# so that we don't get Installed (but unpackaged) errors
+rm -rf $RPM_BUILD_ROOT%{_datadir}/gtk-doc/html/libvirt 
+rm

Re: [libvirt] cpu flags

2008-09-17 Thread Ben Guthro


 I think the most likely place for exposing CPU flags would be in the
 capabilities XML format. We do in fact already expose 3 flags there,
 PAE, VMX and SVM. 

This looks like all of the info that I need - I guess I overlooked this part of 
the code prior to my message. 

The problem that I see currently is that despite the capabilities string 
containing the host tag, with this cpu info - it is up to each hypervisor 
driver to implement the broadcasting of host features.

For example - Xen will report PAE,VMX,SVM - but my ovirt node running KVM 
currently only reports the following:

  host
cpu
  archx86_64/arch
/cpu
  /host

It seems to me that it might be useful for some sort of node info driver, 
where we might be able to share code for hypervisor independent info about the 
physical machine it is running on. 

We should not have to re-write the scanning of /proc/cpuinfo in every 
hypervisor driver, IMHO.

Ben 

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


RE: [libvirt] [PATCH] spec file enhancements for minimal client-only build

2008-09-16 Thread Ben Guthro
I really only put in the removal of the devel sub-package for symmetry with the 
optional removal of the python sub-package. 

However - I don't really feel strongly one way or the other about that...so can 
redo this without the devel removal. It should be an easy fix...I'll have time 
to take a look at it a little later today.




-Original Message-
From: Daniel P. Berrange [mailto:[EMAIL PROTECTED]
Sent: Tue 9/16/2008 6:38 AM
To: Ben Guthro
Cc: libvir-list@redhat.com
Subject: Re: [libvirt] [PATCH] spec file enhancements for minimal client-only 
build
 
On Mon, Sep 15, 2008 at 02:55:40PM -0400, Ben Guthro wrote:
 Attached is a patch to add some additional options to the spec file, 
 allowing for more flexibility when building.
 With this patch, it allows you to build a client-only version of 
 libvirt for machines that may have an interest in communicating over the 
 remote driver, but do not have a hypervisor themselves.

While in general I think this is useful, I don't see the point in
the disabling of the -devel sub-RPM. This doesn't impact anything
at compile time, and if you don't want it post-build, then simply
don't distribute it. The -devel could still be useful for a client
only version, if people want to build client apps. As it is the
extra conditionals for disabling -devel just clutter the spec file
more without any obvious advantage.

I'd ACK something without the -devel conditionals.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] [PATCH] spec file enhancements for minimal client-only build

2008-09-16 Thread Ben Guthro

New patch below, with changes discussed (removal of --without devel)

Example minimal client only build:
rpmbuild \
   --define _topdir %(pwd)/rpm-build   \
   --define _builddir %{_topdir} \
--define _rpmdir %{_topdir} \
--define _srcrpmdir %{_topdir} \
--define _specdir %{_topdir} \
--define _sourcedir %{_topdir} \
--nodeps \
--without xen \
--without xen_proxy \
--without qemu \
--without openvz \
--without lxc \
--without polkit \
--without libvirtd \
--without avahi \
--without sasl \
--without python \
-ta --clean libvirt*.tar.gz

Signed-off-by: Ben Guthro [EMAIL PROTECTED]

libvirt.spec.in |  112 
+++-

1 file changed, 102 insertions(+), 10 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 18b2127..cc5aca5 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1,11 +1,15 @@
# -*- rpm-spec -*-

-%define with_xen   1
-%define with_xen_proxy 1
-%define with_qemu  1
-%define with_openvz1
-%define with_lxc   1
-%define with_polkit0
+%define with_xen   0%{!?_without_xen:1}
+%define with_xen_proxy 0%{!?_without_xen_proxy:1}
+%define with_qemu  0%{!?_without_qemu:1}
+%define with_openvz0%{!?_without_openvz:1}
+%define with_lxc   0%{!?_without_lxc:1}
+%define with_sasl  0%{!?_without_sasl:1}
+%define with_avahi 0%{!?_without_avahi:1}
+%define with_polkit0%{!?_without_polkit:0}
+%define with_python0%{!?_without_python:1}
+%define with_libvirtd  0%{!?_without_libvirtd:1}

# Xen is available only on i386 x86_64 ia64
%ifnarch i386 i686 x86_64 ia64
@@ -23,7 +27,7 @@
%endif

%if 0%{fedora} = 8
-%define with_polkit1
+%define with_polkit0%{!?_without_polkit:1}
%define with_xen_proxy 0
%endif

@@ -46,10 +50,12 @@ Requires: iptables
# So remote clients can access libvirt over SSH tunnel
# (client invokes 'nc' against the UNIX socket on the server)
Requires: nc
+%if %{with_sasl}
Requires: cyrus-sasl
# Not technically required, but makes 'out-of-box' config
# work correctly  doesn't have onerous dependencies
Requires: cyrus-sasl-md5
+%endif
%if %{with_polkit}
Requires: PolicyKit = 0.6
%endif
@@ -82,14 +88,18 @@ BuildRequires: readline-devel
BuildRequires: ncurses-devel
BuildRequires: gettext
BuildRequires: gnutls-devel
+%if %{with_avahi}
BuildRequires: avahi-devel
+%endif
BuildRequires: libselinux-devel
BuildRequires: dnsmasq
BuildRequires: bridge-utils
%if %{with_qemu}
BuildRequires: qemu
%endif
+%if %{with_sasl}
BuildRequires: cyrus-sasl-devel
+%endif
%if %{with_polkit}
BuildRequires: PolicyKit-devel = 0.6
%endif
@@ -133,6 +143,7 @@ Obsoletes: libvir-devel
Includes and documentations for the C library providing an API to use
the virtualization capabilities of recent versions of Linux (and other 
OSes).


+%if %{with_python}
%package python
Summary: Python bindings for the libvirt library
Group: Development/Libraries
@@ -144,6 +155,7 @@ The libvirt-python package contains a module that 
permits applications

written in the Python programming language to use the interface
supplied by the libvirt library to use the virtualization capabilities
of recent versions of Linux (and other OSes).
+%endif

%prep
%setup -q
@@ -165,10 +177,35 @@ of recent versions of Linux (and other OSes).
%define _without_lxc --without-lxc
%endif

+%if ! %{with_sasl}
+%define _without_sasl --without-sasl
+%endif
+
+%if ! %{with_avahi}
+%define _without_avahi --without-avahi
+%endif
+
+%if ! %{with_polkit}
+%define _without_polkit --without-polkit
+%endif
+
+%if ! %{with_python}
+%define _without_python --without-python
+%endif
+
+%if ! %{with_libvirtd}
+%define _without_libvirtd --without-libvirtd
+%endif
+
%configure %{?_without_xen} \
   %{?_without_qemu} \
   %{?_without_openvz} \
   %{?_without_lxc} \
+   %{?_without_sasl} \
+   %{?_without_avahi} \
+   %{?_without_polkit} \
+   %{?_without_python} \
+   %{?_without_libvirtd} \
   --with-init-script=redhat \
   --with-qemud-pid-file=%{_localstatedir}/run/libvirt_qemud.pid \
   --with-remote-file=%{_localstatedir}/run/libvirtd.pid
@@ -190,6 +227,7 @@ install -d -m 0755 
$RPM_BUILD_ROOT%{_localstatedir}/lib/libvirt/images/

# Default dir for kernel+initrd images defnied in SELinux policy
install -d -m 0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/libvirt/boot/

+%if %{with_qemu}
# We don't want to install /etc/libvirt/qemu/networks in the main 
%files list
# because if the admin wants to delete the default network completely, 
we don't

# want to end up re-incarnating it on every RPM upgrade.
@@ -200,14 +238,31 @@ rm -f 
$RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/default.xml
rm -f 
$RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/autostart/default.xml

# Strip auto-generated UUID - we need it generated per-install
sed -i -e /uuid/d 
$RPM_BUILD_ROOT%{_datadir}/libvirt/networks/default.xml

+%endif
%find_lang

[libvirt] cpu flags

2008-09-16 Thread Ben Guthro

Hi,

We're finding that we are going to be needing the cpu flags (as reported 
in /proc/cpuinfo)

...specifically to find out if we are a vmx enabled machine.

So - off I went looking into this for a patch to submit upstream.
Unfortunately, I ran into some questions which need answering before I 
really proceed with this


It seems to me that this info would best be parsed in src/nodeinfo.c
This is where other cpuinfo things are parsed...and stored in the 
nodeinfo struct
Perhaps we store this as a bitmask encoded int, as defined in 
/usr/include/asm/cpufeature.h and tack this onto the end of sad struct.


My concern is that adding to the nodeinfo struct breaks the API - such 
that the structs will be different sizes between versions.


Also - this seems to be x86 specific. Are we primarily destined for x86? 
Or would this type of change be unacceptable due to not working on PPC, 
for example?


Thoughts?

Ben



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


[libvirt] [PATCH] spec file enhancements for minimal client-only build

2008-09-15 Thread Ben Guthro
Attached is a patch to add some additional options to the spec file, 
allowing for more flexibility when building.
With this patch, it allows you to build a client-only version of 
libvirt for machines that may have an interest in communicating over the 
remote driver, but do not have a hypervisor themselves.


It enables command line overrides of control variables for the build
eg:
rpmbuild $(RPM_FLAGS) --nodeps \
   --without xen \
   --without xen_proxy \
   --without qemu \
   --without openvz \
   --without lxc \
   --without polkit \
   --without libvirtd \
   --without avahi \
   --without sasl \
   --without python \
   --without devel \
   -ta --clean libvirt*.tar.gz

Signed-off-by: Ben Guthro [EMAIL PROTECTED]

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 18b2127..666fb83 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1,11 +1,16 @@
# -*- rpm-spec -*-

-%define with_xen   1
-%define with_xen_proxy 1
-%define with_qemu  1
-%define with_openvz1
-%define with_lxc   1
-%define with_polkit0
+%define with_xen   0%{!?_without_xen:1}
+%define with_xen_proxy 0%{!?_without_xen_proxy:1}
+%define with_qemu  0%{!?_without_qemu:1}
+%define with_openvz0%{!?_without_openvz:1}
+%define with_lxc   0%{!?_without_lxc:1}
+%define with_sasl  0%{!?_without_sasl:1}
+%define with_avahi 0%{!?_without_avahi:1}
+%define with_polkit0%{!?_without_polkit:0}
+%define with_python0%{!?_without_python:1}
+%define with_libvirtd  0%{!?_without_libvirtd:1}
+%define with_devel 0%{!?_without_devel:1}

# Xen is available only on i386 x86_64 ia64
%ifnarch i386 i686 x86_64 ia64
@@ -23,7 +28,7 @@
%endif

%if 0%{fedora} = 8
-%define with_polkit1
+%define with_polkit0%{!?_without_polkit:1}
%define with_xen_proxy 0
%endif

@@ -46,10 +51,12 @@ Requires: iptables
# So remote clients can access libvirt over SSH tunnel
# (client invokes 'nc' against the UNIX socket on the server)
Requires: nc
+%if %{with_sasl}
Requires: cyrus-sasl
# Not technically required, but makes 'out-of-box' config
# work correctly  doesn't have onerous dependencies
Requires: cyrus-sasl-md5
+%endif
%if %{with_polkit}
Requires: PolicyKit = 0.6
%endif
@@ -82,14 +89,18 @@ BuildRequires: readline-devel
BuildRequires: ncurses-devel
BuildRequires: gettext
BuildRequires: gnutls-devel
+%if %{with_avahi}
BuildRequires: avahi-devel
+%endif
BuildRequires: libselinux-devel
BuildRequires: dnsmasq
BuildRequires: bridge-utils
%if %{with_qemu}
BuildRequires: qemu
%endif
+%if %{with_sasl}
BuildRequires: cyrus-sasl-devel
+%endif
%if %{with_polkit}
BuildRequires: PolicyKit-devel = 0.6
%endif
@@ -119,6 +130,7 @@ BuildRequires: gawk
Libvirt is a C toolkit to interact with the virtualization capabilities
of recent versions of Linux (and other OSes).

+%if %{with_devel}
%package devel
Summary: Libraries, includes, etc. to compile with the libvirt library
Group: Development/Libraries
@@ -132,7 +144,9 @@ Obsoletes: libvir-devel
%description devel
Includes and documentations for the C library providing an API to use
the virtualization capabilities of recent versions of Linux (and other 
OSes).

+%endif

+%if %{with_python}
%package python
Summary: Python bindings for the libvirt library
Group: Development/Libraries
@@ -144,6 +158,7 @@ The libvirt-python package contains a module that 
permits applications

written in the Python programming language to use the interface
supplied by the libvirt library to use the virtualization capabilities
of recent versions of Linux (and other OSes).
+%endif

%prep
%setup -q
@@ -190,6 +205,7 @@ install -d -m 0755 
$RPM_BUILD_ROOT%{_localstatedir}/lib/libvirt/images/

# Default dir for kernel+initrd images defnied in SELinux policy
install -d -m 0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/libvirt/boot/

+%if %{with_qemu}
# We don't want to install /etc/libvirt/qemu/networks in the main 
%files list
# because if the admin wants to delete the default network completely, 
we don't

# want to end up re-incarnating it on every RPM upgrade.
@@ -200,14 +216,33 @@ rm -f 
$RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/default.xml
rm -f 
$RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/autostart/default.xml

# Strip auto-generated UUID - we need it generated per-install
sed -i -e /uuid/d 
$RPM_BUILD_ROOT%{_datadir}/libvirt/networks/default.xml

+%endif
%find_lang %{name}

+# If we are not building with certain options, we need to remove files
+# so that we don't get Installed (but unpackaged) errors
+%if ! %{with_devel}
+rm -rf $RPM_BUILD_ROOT%{_datadir}/gtk-doc/html/libvirt
+rm -rf $RPM_BUILD_ROOT%{_includedir}/libvirt
+rm -rf $RPM_BUILD_ROOT%{_libdir}/lib*.so
+rm -rf $RPM_BUILD_ROOT%{_libdir}/pkgconfig/libvirt.pc
+%endif
+
+%if ! %{with_python}
+rm -rf $RPM_BUILD_ROOT%{_datadir}/doc/libvirt-python-%{version}
+%endif
+
+%if ! %{with_qemu}
+rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu.conf
+%endif
+
%clean
rm -fr %{buildroot}

%post
/sbin