[libvirt-users] virConnectDomainEventRegisterAny problem

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 good day. i trying to make callback function for VIR_DOMAIN_EVENT_ID_LIFECYCLE, i have successfully registering callback, but it never called, i need to know when domain started, stopped or crashed, i have write following code static int domain_event_handler(virConnectPtr conn, virDomainPtr dom, int event, int detail, void * opaque) { switch(event) { } return 0; } ..... int callback = virConnectDomainEventRegisterAny(libvirt_connection, NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL); if(callback == -1) { std::cout<<"Error: failed to register domain event handle callback\n"; return -1; } ..... but "domain_event_handler" is never called, what is wrong here ? -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSE/XIAAoJEH3ap8veG8EHNO4H/iu8FLlL2fXMrWC6Z75fgoL+ 1LKH504VD/oZ4UUyEMURdywNOp4cHmXQOiCbgN3ardFMjhFQ/hwbDHgBXLuQGsr0 yXyUoX8ft3sEojTJS0ys9J+vkFcqm/eOykCeAKRPHQPAeUivKQpRhx3+6mXDJ3z8 OyTGqD5GFdhgktz/4IbqeOp4PKI55QXVrrsB2414hPykBq6xsRqbtQC9QZ/Df2SP kHGAymEYK+i242xJYZSxTy5BLH+JNa1yzJNE+XoAtaMz2ypRg3ycMipo0io+8VMy KJWRxmq3O/ZKrqGsI++D7ugAkkLCLUbpyC35fXK7GXAEnxk/uTkQInU7F26FdJs= =32hk -----END PGP SIGNATURE-----

On Wed 21 Aug 2013 01:03:37 AM CEST, Alexandr wrote:
good day. i trying to make callback function for VIR_DOMAIN_EVENT_ID_LIFECYCLE, i have successfully registering callback, but it never called, i need to know when domain started, stopped or crashed, i have write following code
static int domain_event_handler(virConnectPtr conn, virDomainPtr dom, int event, int detail, void * opaque) { switch(event) { } return 0; }
..... int callback = virConnectDomainEventRegisterAny(libvirt_connection, NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL); if(callback == -1) { std::cout<<"Error: failed to register domain event handle callback\n"; return -1; } .....
but "domain_event_handler" is never called, what is wrong here ?
Are you running an event loop? You can have a look at our examples [1] and see what's being done there. Especially note the virEventRunDefaultImpl() [2] there. Martin [1] http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events... [2] http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 21.08.2013 09:32, Martin Kletzander пишет:
On Wed 21 Aug 2013 01:03:37 AM CEST, Alexandr wrote:
good day. i trying to make callback function for VIR_DOMAIN_EVENT_ID_LIFECYCLE, i have successfully registering callback, but it never called, i need to know when domain started, stopped or crashed, i have write following code
static int domain_event_handler(virConnectPtr conn, virDomainPtr dom, int event, int detail, void * opaque) { switch(event) { } return 0; }
..... int callback = virConnectDomainEventRegisterAny(libvirt_connection, NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL); if(callback == -1) { std::cout<<"Error: failed to register domain event handle callback\n"; return -1; } .....
but "domain_event_handler" is never called, what is wrong here ?
Are you running an event loop? You can have a look at our examples [1] and see what's being done there. Especially note the virEventRunDefaultImpl() [2] there.
Martin
[1] http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
[2]
http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
oh..., i missed it, thx for hint and sorry for stupid questions . -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSFGI9AAoJEH3ap8veG8EHl6QH/iHtRzwc/WRUTiPjvWTIVcKR wsTMByOqUE82A1pWScJJDF/C8+HTVb5dgF4sXH61TJT8mMu/h721oSv/mh3jMjwJ KUO5X/7h75RPVizLvUW6PofI4DWzSyJec73UG+4QIYyMs8en9D4C46QqVdXnnlVd yXGAAIV5y4BPPHV+QYaPp09oEqf+DnVhTrf14LjHOhUZF+6rO56n7fP9heOAXe5Z vhifJ0y8NiiAl1uGeEm4ty7rdw2geTZaSIo1EFVc7/j4Ejlb4+Bosg67aFlW+PmU gN5A08/l/9FnDk1qZL7twwc3+38CQr9n88hhZLaVs8sgm9R7VhQum8qMpSRS3oE= =Xrdk -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 21.08.2013 09:46, Alexandr пишет:
21.08.2013 09:32, Martin Kletzander пишет:
On Wed 21 Aug 2013 01:03:37 AM CEST, Alexandr wrote:
good day. i trying to make callback function for VIR_DOMAIN_EVENT_ID_LIFECYCLE, i have successfully registering callback, but it never called, i need to know when domain started, stopped or crashed, i have write following code
static int domain_event_handler(virConnectPtr conn, virDomainPtr dom, int event, int detail, void * opaque) { switch(event) { } return 0; }
..... int callback = virConnectDomainEventRegisterAny(libvirt_connection, NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL); if(callback == -1) { std::cout<<"Error: failed to register domain event handle callback\n"; return -1; } .....
but "domain_event_handler" is never called, what is wrong here ?
Are you running an event loop? You can have a look at our examples [1] and see what's being done there. Especially note the virEventRunDefaultImpl() [2] there.
Martin
[1] http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
[2]
http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
oh..., i missed it, thx for hint and sorry for stupid questions .
_______________________________________________ libvirt-users mailing list libvirt-users@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-users
now it's working except for events from other connections, for example i want to handle domain started by virt-manager, now i do not have event when it's started, is exists any api to handle this events, or i need to implement internal polling of domains state in my application ? -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSFIoGAAoJEH3ap8veG8EHD3kIALAivHCNxKX6WN99MRbQQcUb wLuZL1DALOrRr0YEI5fm+rWGb2nYJjMrkRGTmD1/sW7oGLfYz9hzEj3f6vnOOkH+ DlfNU8Td7ssPicIBhNrKXqDF/1OebImCcYivEVEyhNigwoSIjJ8Y3KkON9TO7jc1 pu8POIoxG/7nBuxaNBlaBioLx8QwGtFG0fWU2UhTK63dVVTjCqTwI5STHugAAQhf ws3xJxkeLKbtDajaIvgzh5oZ/4zHNEeViviR2qW4VqHq1MWiOkj1T8Q4sGzSzpLe 5ALXdVjnUfPxMI3szrz80XuqEyRR0CrHEfoz8dnWaR2s84B7gfwu7oV/TdJnIts= =lJBr -----END PGP SIGNATURE-----

On Wed, Aug 21, 2013 at 12:36:06PM +0300, Alexandr wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
21.08.2013 09:46, Alexandr пишет:
21.08.2013 09:32, Martin Kletzander пишет:
On Wed 21 Aug 2013 01:03:37 AM CEST, Alexandr wrote:
good day. i trying to make callback function for VIR_DOMAIN_EVENT_ID_LIFECYCLE, i have successfully registering callback, but it never called, i need to know when domain started, stopped or crashed, i have write following code
static int domain_event_handler(virConnectPtr conn, virDomainPtr dom, int event, int detail, void * opaque) { switch(event) { } return 0; }
..... int callback = virConnectDomainEventRegisterAny(libvirt_connection, NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL); if(callback == -1) { std::cout<<"Error: failed to register domain event handle callback\n"; return -1; } .....
but "domain_event_handler" is never called, what is wrong here ?
Are you running an event loop? You can have a look at our examples [1] and see what's being done there. Especially note the virEventRunDefaultImpl() [2] there.
Martin
[1] http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
[2]
http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
oh..., i missed it, thx for hint and sorry for stupid questions .
now it's working except for events from other connections, for example i want to handle domain started by virt-manager, now i do not have event when it's started, is exists any api to handle this events, or i need to implement internal polling of domains state in my application ?
The events system reports all lifecycle events, regardless of which connection triggered them. If you're not seeing events from domains started by virt-manager then your almost certainly connecting to a different libvirt URI than virt-manager is using. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 21.08.2013 12:39, Daniel P. Berrange пишет:
On Wed, Aug 21, 2013 at 12:36:06PM +0300, Alexandr wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
21.08.2013 09:46, Alexandr пишет:
21.08.2013 09:32, Martin Kletzander пишет:
On Wed 21 Aug 2013 01:03:37 AM CEST, Alexandr wrote:
good day. i trying to make callback function for VIR_DOMAIN_EVENT_ID_LIFECYCLE, i have successfully registering callback, but it never called, i need to know when domain started, stopped or crashed, i have write following code
static int domain_event_handler(virConnectPtr conn, virDomainPtr dom, int event, int detail, void * opaque) { switch(event) { } return 0; }
..... int callback = virConnectDomainEventRegisterAny(libvirt_connection, NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL); if(callback == -1) { std::cout<<"Error: failed to register domain event handle callback\n"; return -1; } .....
but "domain_event_handler" is never called, what is wrong here ?
Are you running an event loop? You can have a look at our examples [1] and see what's being done there. Especially note the virEventRunDefaultImpl() [2] there.
Martin
[1] http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
[2]
http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
oh..., i missed it, thx for hint and sorry for stupid questions .
now it's working except for events from other connections, for example i want to handle domain started by virt-manager, now i do not have event when it's started, is exists any api to handle this events, or i need to implement internal polling of domains state in my application ?
The events system reports all lifecycle events, regardless of which connection triggered them.
If you're not seeing events from domains started by virt-manager then your almost certainly connecting to a different libvirt URI than virt-manager is using.
Daniel
also looks like i do not receiving last event, i mean last event what passed to callback is "eventcount - 1" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSFI8vAAoJEH3ap8veG8EHfmkH/1FKXCBGLTTzU8DN2DrvobDx whVooW5J5Y4PBfSkKDqdERk+d5uxV2eWnobRxXVZCjDKk3M3Q6HztW5OvcMoGXM+ guGDok/Hp7n9XC17DnVbS4GpMSkaIcbpN6s8+PWu3r1nI7sX1o+YssT48a88XYjF MtrMVOganILKHjQkoVmJAC22ajk89OnnPBkXwqrdUN1fxi7+SJpgPM/3UDyFoFEv pwfMSHoKSaqlb99Q6ir2qom+bJKOfjez9xerHulIbYhYVW8vxTTceLGOQU++sN6i EsH2LGVHggptOMPUom2zXo6+gOTVT1xp1VSYusKHCT8PobXUEJT8fEAnwKSoWWY= =Lfmn -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 21.08.2013 12:58, Alexandr пишет:
21.08.2013 12:39, Daniel P. Berrange пишет:
On Wed, Aug 21, 2013 at 12:36:06PM +0300, Alexandr wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
21.08.2013 09:46, Alexandr пишет:
21.08.2013 09:32, Martin Kletzander пишет:
On Wed 21 Aug 2013 01:03:37 AM CEST, Alexandr wrote:
good day. i trying to make callback function for VIR_DOMAIN_EVENT_ID_LIFECYCLE, i have successfully registering callback, but it never called, i need to know when domain started, stopped or crashed, i have write following code
static int domain_event_handler(virConnectPtr conn, virDomainPtr dom, int event, int detail, void * opaque) { switch(event) { } return 0; }
..... int callback = virConnectDomainEventRegisterAny(libvirt_connection, NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL); if(callback == -1) { std::cout<<"Error: failed to register domain event handle callback\n"; return -1; } .....
but "domain_event_handler" is never called, what is wrong here ?
Are you running an event loop? You can have a look at our examples [1] and see what's being done there. Especially note the virEventRunDefaultImpl() [2] there.
Martin
[1] http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
[2]
http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
oh..., i missed it, thx for hint and sorry for stupid questions .
now it's working except for events from other connections, for example i want to handle domain started by virt-manager, now i do not have event when it's started, is exists any api to handle this events, or i need to implement internal polling of domains state in my application ?
The events system reports all lifecycle events, regardless of which connection triggered them.
If you're not seeing events from domains started by virt-manager then your almost certainly connecting to a different libvirt URI than virt-manager is using.
Daniel
also looks like i do not receiving last event, i mean last event what passed to callback is "eventcount - 1"
_______________________________________________ libvirt-users mailing list libvirt-users@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-users
after few days of trying i have not resolved problem, and have followinf situation: i receiving events from my connection sometimes (not all and not always), i do not receiving events from other connections (virt-manager) at all (i am sure that connection url are same for both connections), my code follows: static int domain_event_handler(virConnectPtr conn, virDomainPtr dom, int event, int detail, void * opaque) { std::cout<<"domain event handler called\n"; } void libvirt_eventloop_thr_func() { while(true) //TODO: stop somehow on exit { if(virEventRunDefaultImpl() < 0) { virErrorPtr err = virGetLastError(); fprintf(stderr, "Failed to run event loop: %s\n", err && err->message ? err->message : "Unknown error"); } } } .... virSetErrorFunc(NULL, libvirt_error_handler); libvirt_connection = virConnectOpen("qemu:///system"); if(libvirt_connection == NULL) { std::cout<<"failed to connect to qemu:///system\n"; return -1; } std::cout<<"connected to qemu:///system\n"; if (virEventRegisterDefaultImpl() < 0) { virErrorPtr err = virGetLastError(); fprintf(stderr, "Failed to register event implementation: %s\n", err && err->message ? err->message: "Unknown error"); return -1; } { int callback = virConnectDomainEventRegisterAny(libvirt_connection, NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL); if(callback == -1) { std::cout<<"Error: failed to register domain event handle callback\n"; return -1; } } boost::thread(boost::bind(&libvirt_eventloop_thr_func)); .... am i doing something wrong here ? -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSFofkAAoJEH3ap8veG8EHFowH/ipkeTcQZeX6MMaYVazm4kQL IUsnhTuQt/OIVCD7LU3g27ii4T4Y4YeXuMI9p5DrqEjL9TE6jS2ZlZXE29ji48xJ PMpTERz78R/bs0lcffk2pO1MuH8nMDpNT7HI1zdaYZ9vRP9IS4ksGWvw3Jif4lXw o/pLpCTPGQkWJO3ppKo4EVvJbaGi/YyuepOBPFWC2YYD+5zRfFhxZVbfAG1TdilN jMqfrqObeVKIOyCnikGCIwU7XTLY3beTf3g9cgX+Lq03GvS8OpjHDIkd90qX5MNs yt0cJCKX8S4OBv1xsYelXrGulC57YqiQek6o8pQV4qFv2yp8FgRVb4GBNNKsFAE= =5vgP -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 23.08.2013 00:51, Alexandr пишет:
21.08.2013 12:58, Alexandr пишет:
21.08.2013 12:39, Daniel P. Berrange пишет:
On Wed, Aug 21, 2013 at 12:36:06PM +0300, Alexandr wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
21.08.2013 09:46, Alexandr пишет:
21.08.2013 09:32, Martin Kletzander пишет:
On Wed 21 Aug 2013 01:03:37 AM CEST, Alexandr wrote: > > good day. i trying to make callback function for > VIR_DOMAIN_EVENT_ID_LIFECYCLE, i have successfully > registering callback, but it never called, i need to > know when domain started, stopped or crashed, i have > write following code > > static int domain_event_handler(virConnectPtr conn, > virDomainPtr dom, int event, int detail, void * > opaque) { switch(event) { } return 0; } > > ..... int callback = > virConnectDomainEventRegisterAny(libvirt_connection, > NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, > VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, > NULL); if(callback == -1) { std::cout<<"Error: failed > to register domain event handle callback\n"; return -1; > } ..... > > > but "domain_event_handler" is never called, what is > wrong here ?
Are you running an event loop? You can have a look at our examples [1] and see what's being done there. Especially note the virEventRunDefaultImpl() [2] there.
Martin
[1] http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
[2]
http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/domain-events/events...
oh..., i missed it, thx for hint and sorry for stupid questions .
now it's working except for events from other connections, for example i want to handle domain started by virt-manager, now i do not have event when it's started, is exists any api to handle this events, or i need to implement internal polling of domains state in my application ?
The events system reports all lifecycle events, regardless of which connection triggered them.
If you're not seeing events from domains started by virt-manager then your almost certainly connecting to a different libvirt URI than virt-manager is using.
Daniel
also looks like i do not receiving last event, i mean last event what passed to callback is "eventcount - 1"
_______________________________________________ libvirt-users mailing list libvirt-users@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-users
after few days of trying i have not resolved problem, and have followinf situation: i receiving events from my connection sometimes (not all and not always), i do not receiving events from other connections (virt-manager) at all (i am sure that connection url are same for both connections), my code follows:
static int domain_event_handler(virConnectPtr conn, virDomainPtr dom, int event, int detail, void * opaque) { std::cout<<"domain event handler called\n"; }
void libvirt_eventloop_thr_func() { while(true) //TODO: stop somehow on exit { if(virEventRunDefaultImpl() < 0) { virErrorPtr err = virGetLastError(); fprintf(stderr, "Failed to run event loop: %s\n", err && err->message ? err->message : "Unknown error"); } } }
.... virSetErrorFunc(NULL, libvirt_error_handler); libvirt_connection = virConnectOpen("qemu:///system"); if(libvirt_connection == NULL) { std::cout<<"failed to connect to qemu:///system\n"; return -1; } std::cout<<"connected to qemu:///system\n";
if (virEventRegisterDefaultImpl() < 0) { virErrorPtr err = virGetLastError(); fprintf(stderr, "Failed to register event implementation: %s\n", err && err->message ? err->message: "Unknown error"); return -1; } { int callback = virConnectDomainEventRegisterAny(libvirt_connection, NULL, VIR_DOMAIN_EVENT_ID_LIFECYCLE, VIR_DOMAIN_EVENT_CALLBACK(domain_event_handler), NULL, NULL); if(callback == -1) { std::cout<<"Error: failed to register domain event handle callback\n"; return -1; } }
boost::thread(boost::bind(&libvirt_eventloop_thr_func)); ....
am i doing something wrong here ?
_______________________________________________ libvirt-users mailing list libvirt-users@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-users
also i have started libvirt/libvirt-1.1.1/examples/domain-events/events-c example, and it have same problems as my code, it does not receiving any events from virt-manager -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSFo6uAAoJEH3ap8veG8EHYO8H/3uFilTQAKz0xg4oTfKcfZMP spdx10L3yAWCoL4GYjHtZD1mPNHtJo2MgUX5PrwEEnu+npF8a3yYqTGF6DZcNSdu aurO3T5/Wljg5E1d0TuN3W7J/Xmb4U0sRW7HqtTsb6lAKGn9gRWFWmrj+FH+KSbb D+CL4sKCqeYuiFnYbF4X3w0m9oXzsN36hZ1ALKhlL6/n93GeOyp32nx+NRaZchgz /QiZEAyUwQL3AK37a8Mw8uNshuvQc+Gw5tnghLIeQivUTsHGPiUyPAqbW0b+aAfd JLfJ7esOXsaOl916AFl68GBXzEH89y0b8RPNe4vS3VCOjp8UrXJGMju6YVMFVoM= =KfMJ -----END PGP SIGNATURE-----
participants (3)
-
Alexandr
-
Daniel P. Berrange
-
Martin Kletzander