what a correct use for virConnectDomainEventRegisterAny API, how to Obtain a stable expected result

thomas.kuang ks002278 at 163.com
Mon Apr 13 09:32:38 UTC 2020


HI, everyone:


My target  deal with network hotplug use virDomainDetachDeviceFlags. Because when the API return ,the network maybe doesn’t remove from my vm guest os.

So I use virConnectDomainEventRegisterAny  to register an event ID: VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED ,

 my process as follow:

cb_para->call_id=virConnectDomainEventRegisterAny(cb_para->conn,cb_para->dom,VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED, VIR_DOMAIN_EVENT_CALLBACK(vnf_control_del_network_cb), cb_para, vnf_control_del_network_cb_free); 



    flags |= VIR_DOMAIN_AFFECT_CONFIG;
    if (virDomainIsActive(dom) == 1) {
        flags |= VIR_DOMAIN_AFFECT_LIVE;
    }

    ret = virDomainDetachDeviceFlags(dom, xml, flags);


 

above code write in thread loop ,then in the same loop :

 

       while (1) {

              mission = vnf_mission_queue_get(task);

              if (mission == NULL) {

                     sleep(1);

                     continue;

              } 

              vnf_op_process(&mission->info); // this will deal with network hotplug,will call virConnectDomainEventRegisterAny  then call  virDomainDetachDeviceFlags

              if (mission) {

                     vnf_mission_free(mission);

              } 

              if(virEventRunDefaultImpl() < 0) { // at here process  the registered callback for event-registered

                    printf();....


              }     

       }

My problem is: some time  , the virEventRunDefaultImpl can trigger the vnf_control_del_network_cb  callback ,but some time  there is nothing ,as if the VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED has lost.
what cause the Unpredictable behavior ?  what is a correct use for virConnectDomainEventRegisterAny ?



if can't trigger the vnf_control_del_network_cb callback , the memory :cb_para will mem-leak,

so in order to deal the execpt ,i  register a timer to process the VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED timeout

cb_para->timer_id = virEventAddTimeout(cb_para->time_out, vnf_control_del_network_timeout_cb, cb_para, vnf_control_del_network_cb_free);
thought use the timer ,can i avoid the cb_para mem-leak, but fail to achive  hotplug network .
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200413/4260e6fe/attachment-0001.htm>


More information about the libvir-list mailing list