when virEventAddTimeout trigger timeout ,should in the callback call virConnectDomainEventDeregisterAny ?

thomas.kuang ks002278 at 163.com
Tue Apr 7 11:39:27 UTC 2020


hi, all
    I do a hotplug detach a network in a thread,  because virDomainDetachDeviceFlags maybe asynchronous, so I do like follow:
    cb_para->cluster_id = info->cluster_id;
    cb_para->group_id = info->group_id;
    cb_para->vsys_id = info->vsysid;
    cb_para->vnf_id = info->vnf_id;
    cb_para->conn = conn;
    cb_para->time_out = 20*1000;//20s
    cb_para->call_id = virConnectDomainEventRegisterAny(conn, 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;
    }

    cb_para->timer_id = virEventAddTimeout(cb_para->time_out, vnf_control_del_network_timeout_cb, cb_para, vnf_control_del_network_cb_free);
    ret = virDomainDetachDeviceFlags(dom, xml, flags);
//above run in a thread function





void vnf_control_del_network_cb(virConnectPtr conn,        virDomainPtr dom, const  char  *dev,void * opaque)
{
    struct vnf_del_netwk_opaque * arg = (struct vnf_del_netwk_opaque *)opaque;  

   if(0 == virConnectDomainEventDeregisterAny(conn, arg->call_id)) {
        VNF_DBG("succ to deRegister, conn:%p, call id:%d\n", conn, arg->call_id);
    } else {
        VNF_DBG("fail to deRegister, conn:%p, call id:%d\n", conn, arg->call_id);
    }
    ....................

  virEventRemoveTimeout(arg->timer_id);
}





void vnf_control_del_network_timeout_cb(int timer, void *opaque)
{
    struct vnf_del_netwk_opaque * arg = (struct vnf_del_netwk_opaque *)opaque;
    ................
    if(0 == virConnectDomainEventDeregisterAny(arg->conn, arg->call_id)) {   //here, dead lock ,are thoses APIs not correct using ??
        VNF_DBG("succ to deRegister, conn:%p, call id:%d\n", arg->conn, arg->call_id);
    } else {
        VNF_DBG("fail to deRegister, conn:%p, call id:%d\n", arg->conn, arg->call_id);
    }
       virEventRemoveTimeout(arg->timer_id);
}



(gdb) i threads

  Id   Target Id         Frame
  7    Thread 0x7f29fa5ff700 (LWP 104950) "vnfd" 0x00007f2a064f656d in nanosleep () from /lib64/libc.so.6
  6    Thread 0x7f29f9bfe700 (LWP 104951) "vnfd" 0x00007f2a0761851d in __lll_lock_wait () from /lib64/libpthread.so.0
  5    Thread 0x7f29f8dff700 (LWP 104952) "vnfd" 0x00007f2a064f656d in nanosleep () from /lib64/libc.so.6
  4    Thread 0x7f29f7fff700 (LWP 104953) "vnfd" 0x00007f2a064f656d in nanosleep () from /lib64/libc.so.6
  3    Thread 0x7f29f71ff700 (LWP 104954) "vnfd" 0x00007f2a064f656d in nanosleep () from /lib64/libc.so.6
  2    Thread 0x7f29f63ff700 (LWP 104955) "vnfd" 0x00007f2a064f656d in nanosleep () from /lib64/libc.so.6
* 1    Thread 0x7f2a087f8900 (LWP 104946) "vnfd" 0x00007f2a06530183 in epoll_wait () from /lib64/libc.so.6
(gdb) thread 6
[Switching to thread 6 (Thread 0x7f29f9bfe700 (LWP 104951))]
#0  0x00007f2a0761851d in __lll_lock_wait () from /lib64/libpthread.so.0
(gdb) bt
#0  0x00007f2a0761851d in __lll_lock_wait () from /lib64/libpthread.so.0
#1  0x00007f2a07613e1b in _L_lock_812 () from /lib64/libpthread.so.0
#2  0x00007f2a07613ce8 in pthread_mutex_lock () from /lib64/libpthread.so.0
#3  0x00007f2a072a1a0e in remoteConnectClose () from /lib64/libvirt.so.0
#4  0x00007f2a072b2740 in virConnectDispose () from /lib64/libvirt.so.0
#5  0x00007f2a0710bbab in virObjectUnref () from /lib64/libvirt.so.0
#6  0x00007f2a07195577 in virObjectEventCallbackFree () from /lib64/libvirt.so.0
#7  0x00007f2a07196532 in virObjectEventStateDeregisterID () from /lib64/libvirt.so.0
#8  0x00007f2a07287238 in remoteConnectDomainEventDeregisterAny () from /lib64/libvirt.so.0
#9  0x00007f2a072d36d7 in virConnectDomainEventDeregisterAny () from /lib64/libvirt.so.0
#10 0x0000000000405bce in vnf_control_del_network_timeout_cb (timer=<optimized out>, opaque=0x7f29e9e99de0) at vnf_mgt/vnf_control.c:1293
#11 0x00007f2a070d20e9 in virEventPollRunOnce () from /lib64/libvirt.so.0
#12 0x00007f2a070d0a42 in virEventRunDefaultImpl () from /lib64/libvirt.so.0
#13 0x000000000040d099 in vnf_worker_proc (arg=<optimized out>) at vnf_mgt/vnf_control.c:1727
#14 0x00007f2a07611e25 in start_thread () from /lib64/libpthread.so.0
#15 0x00007f2a0652fbad in clone () from /lib64/libc.so.6
(gdb) f 10
#10 0x0000000000405bce in vnf_control_del_network_timeout_cb (timer=<optimized out>, opaque=0x7f29e9e99de0) at vnf_mgt/vnf_control.c:1293
1293            if(0 == virConnectDomainEventDeregisterAny(arg->conn, arg->call_id)) {
(gdb) p arg->time_id
There is no member named time_id.
(gdb) set print pretty
(gdb) p *arg
$1 = {
  cluster_id = 0,
  vsys_id = 0,
  group_id = 2,
  vnf_id = 1,
  call_id = 0,
  timer_id = 16,
  time_out = 20000,
  conn = 0x7f29f8013000
}
(gdb) quit
A debugging session is active.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20200407/a4f2cc3e/attachment.htm>


More information about the libvirt-users mailing list