]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: improve thread naming with human targetted names
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 14 Feb 2020 11:20:10 +0000 (11:20 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 5 Mar 2020 12:23:04 +0000 (12:23 +0000)
Historically threads are given a name based on the C function,
and this name is just used inside libvirt. With OS level thread
naming this name is now visible to debuggers, but also has to
fit in 15 characters on Linux, so function names are too long
in some cases.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
18 files changed:
src/libxl/libxl_domain.c
src/libxl/libxl_migration.c
src/lxc/lxc_fuse.c
src/node_device/node_device_udev.c
src/nwfilter/nwfilter_dhcpsnoop.c
src/nwfilter/nwfilter_learnipaddr.c
src/qemu/qemu_driver.c
src/qemu/qemu_migration.c
src/qemu/qemu_process.c
src/remote/remote_daemon.c
src/rpc/virnetserver.c
src/storage/storage_backend_scsi.c
src/storage/storage_driver.c
src/util/vircommand.c
src/util/virfdstream.c
src/util/virnodesuspend.c
src/util/virthreadpool.c
src/util/virthreadpool.h

index c8b68665af26145e6abda94712b1a78982af39b4..e3da9f777d0e6eb629f863bfbd4a07a0d5db08ed 100644 (file)
@@ -664,6 +664,7 @@ libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
     virThread thread;
     g_autoptr(libxlDriverConfig) cfg = NULL;
     int ret = -1;
+    g_autofree char *name = NULL;
 
     if (event->type != LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN &&
             event->type != LIBXL_EVENT_TYPE_DOMAIN_DEATH) {
@@ -687,12 +688,13 @@ libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
 
     shutdown_info->driver = driver;
     shutdown_info->event = (libxl_event *)event;
+    name = g_strdup_printf("ev-%d", event->domid);
     if (event->type == LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN)
-        ret = virThreadCreate(&thread, false, libxlDomainShutdownThread,
-                              shutdown_info);
+        ret = virThreadCreateFull(&thread, false, libxlDomainShutdownThread,
+                                  name, false, shutdown_info);
     else if (event->type == LIBXL_EVENT_TYPE_DOMAIN_DEATH)
-        ret = virThreadCreate(&thread, false, libxlDomainDeathThread,
-                              shutdown_info);
+        ret = virThreadCreateFull(&thread, false, libxlDomainDeathThread,
+                                  name, false, shutdown_info);
 
     if (ret < 0) {
         /*
index 95516f676b054604bd39aa3cf89d8ffaf4b29414..defdda5ed68e579d78d31105609f8510483b16b7 100644 (file)
@@ -294,6 +294,7 @@ libxlMigrateDstReceive(virNetSocketPtr sock,
     virNetSocketPtr client_sock;
     int recvfd = -1;
     size_t i;
+    g_autofree char *name = NULL;
 
     /* Accept migration connection */
     if (virNetSocketAccept(sock, &client_sock) < 0 || !client_sock) {
@@ -314,8 +315,13 @@ libxlMigrateDstReceive(virNetSocketPtr sock,
     VIR_FREE(priv->migrationDstReceiveThr);
     if (VIR_ALLOC(priv->migrationDstReceiveThr) < 0)
         goto fail;
-    if (virThreadCreate(priv->migrationDstReceiveThr, true,
-                        libxlDoMigrateDstReceive, args) < 0) {
+
+    name = g_strdup_printf("mig-%s", args->vm->def->name);
+    if (virThreadCreateFull(priv->migrationDstReceiveThr, true,
+                            libxlDoMigrateDstReceive,
+                            name,
+                            false,
+                            args) < 0) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                        _("Failed to create thread for receiving migration data"));
         goto fail;
@@ -554,6 +560,7 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn,
     char *xmlout = NULL;
     int dataFD[2] = { -1, -1 };
     int ret = -1;
+    g_autofree char *name = NULL;
 
     if (libxlDomainMigrationPrepareAny(dconn, def, cookiein, cookieinlen,
                                        &mig, &xmlout, &taint_hook) < 0)
@@ -611,7 +618,10 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn,
     VIR_FREE(priv->migrationDstReceiveThr);
     if (VIR_ALLOC(priv->migrationDstReceiveThr) < 0)
         goto error;
-    if (virThreadCreate(priv->migrationDstReceiveThr, true, libxlDoMigrateDstReceive, args) < 0) {
+    name = g_strdup_printf("mig-%s", args->vm->def->name);
+    if (virThreadCreateFull(priv->migrationDstReceiveThr, true,
+                            libxlDoMigrateDstReceive,
+                            name, false, args) < 0) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                        _("Failed to create thread for receiving migration data"));
         goto endjob;
@@ -910,6 +920,7 @@ libxlMigrationSrcStartTunnel(libxlDriverPrivatePtr driver,
     struct libxlTunnelControl *tc = NULL;
     libxlTunnelMigrationThread *arg = NULL;
     int ret = -1;
+    g_autofree char *name = NULL;
 
     if (VIR_ALLOC(tc) < 0)
         goto out;
@@ -925,8 +936,10 @@ libxlMigrationSrcStartTunnel(libxlDriverPrivatePtr driver,
     arg->srcFD = tc->dataFD[0];
     /* Write to dest stream */
     arg->st = st;
-    if (virThreadCreate(&tc->thread, true,
-                        libxlTunnel3MigrationSrcFunc, arg) < 0) {
+    name = g_strdup_printf("mig-%s", vm->def->name);
+    if (virThreadCreateFull(&tc->thread, true,
+                            libxlTunnel3MigrationSrcFunc,
+                            name, false, arg) < 0) {
         virReportError(errno, "%s",
                        _("Unable to create tunnel migration thread"));
         goto out;
index 0da5295cdba2493f77110686a70b5df10d0a947d..e73b4d06901ba2495ddeda15040e1f5b47aa0e62 100644 (file)
@@ -335,8 +335,8 @@ int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def)
 
 int lxcStartFuse(virLXCFusePtr fuse)
 {
-    if (virThreadCreate(&fuse->thread, false, lxcFuseRun,
-                        (void *)fuse) < 0) {
+    if (virThreadCreateFull(&fuse->thread, false, lxcFuseRun,
+                            "lxc-fuse", false, (void *)fuse) < 0) {
         lxcFuseDestroy(fuse);
         return -1;
     }
index 56d5cb2ee04570ca5290c97c225d28b9568ea069..536cae6c301c8c847ae5ae0b888fb0e9d7331fb9 100644 (file)
@@ -1863,7 +1863,8 @@ nodeStateInitialize(bool privileged,
         udev_monitor_set_receive_buffer_size(priv->udev_monitor,
                                              128 * 1024 * 1024);
 
-    if (virThreadCreate(&priv->th, true, udevEventHandleThread, NULL) < 0) {
+    if (virThreadCreateFull(&priv->th, true, udevEventHandleThread,
+                            "udev-event", false, NULL) < 0) {
         virReportSystemError(errno, "%s",
                              _("failed to create udev handler thread"));
         goto unlock;
@@ -1889,8 +1890,8 @@ nodeStateInitialize(bool privileged,
     if (udevSetupSystemDev() != 0)
         goto cleanup;
 
-    if (virThreadCreate(&enumThread, false, nodeStateInitializeEnumerate,
-                        udev) < 0) {
+    if (virThreadCreateFull(&enumThread, false, nodeStateInitializeEnumerate,
+                            "nodedev-init", false, udev) < 0) {
         virReportSystemError(errno, "%s",
                              _("failed to create udev enumerate thread"));
         goto cleanup;
index e7f5b511ae7311aa3daef9bb87dea0061cb4a8af..953d8936a49e87799095a7f47544a7d84871b040 100644 (file)
@@ -1366,9 +1366,10 @@ virNWFilterDHCPSnoopThread(void *req0)
         }
         tmp = virNetDevGetIndex(req->binding->portdevname, &ifindex);
         threadkey = g_strdup(req->threadkey);
-        worker = virThreadPoolNew(1, 1, 0,
-                                  virNWFilterDHCPDecodeWorker,
-                                  req);
+        worker = virThreadPoolNewFull(1, 1, 0,
+                                      virNWFilterDHCPDecodeWorker,
+                                      "dhcp-decode",
+                                      req);
     }
 
     /* let creator know how well we initialized */
@@ -1638,8 +1639,8 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
     /* prevent thread from holding req */
     virNWFilterSnoopReqLock(req);
 
-    if (virThreadCreate(&thread, false, virNWFilterDHCPSnoopThread,
-                        req) != 0) {
+    if (virThreadCreateFull(&thread, false, virNWFilterDHCPSnoopThread,
+                            "dhcp-snoop", false, req) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("virNWFilterDHCPSnoopReq virThreadCreate "
                          "failed on interface '%s'"), binding->portdevname);
index f2d5e60d43d39ceaf384ba546d3999f833e02b51..4ce8d5ba03420b077dc357eab2716beb91925c4b 100644 (file)
@@ -734,10 +734,12 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
     if (rc < 0)
         goto err_free_req;
 
-    if (virThreadCreate(&thread,
-                        false,
-                        learnIPAddressThread,
-                        req) != 0)
+    if (virThreadCreateFull(&thread,
+                            false,
+                            learnIPAddressThread,
+                            "ip-learn",
+                            false,
+                            req) != 0)
         goto err_dereg_req;
 
     return 0;
index 35ade1ef37bd61a657c082521b5a0998e1f8fe88..3707448f499d39fd148f6c908220810a86ea9c11 100644 (file)
@@ -999,7 +999,8 @@ qemuStateInitialize(bool privileged,
     /* must be initialized before trying to reconnect to all the
      * running domains since there might occur some QEMU monitor
      * events that will be dispatched to the worker pool */
-    qemu_driver->workerPool = virThreadPoolNew(0, 1, 0, qemuProcessEventHandler, qemu_driver);
+    qemu_driver->workerPool = virThreadPoolNewFull(0, 1, 0, qemuProcessEventHandler,
+                                                   "qemu-event", qemu_driver);
     if (!qemu_driver->workerPool)
         goto error;
 
index d37a7ec6c79deb38e22de4f8b9eff367e5e73a08..9ee5eb3c29de36b39bc014f9544f6f31dfb345de 100644 (file)
@@ -3309,9 +3309,11 @@ qemuMigrationSrcStartTunnel(virStreamPtr st,
     io->wakeupRecvFD = wakeupFD[0];
     io->wakeupSendFD = wakeupFD[1];
 
-    if (virThreadCreate(&io->thread, true,
-                        qemuMigrationSrcIOFunc,
-                        io) < 0) {
+    if (virThreadCreateFull(&io->thread, true,
+                            qemuMigrationSrcIOFunc,
+                            "qemu-mig-tunnel",
+                            false,
+                            io) < 0) {
         virReportSystemError(errno, "%s",
                              _("Unable to create migration thread"));
         goto error;
index 36fbffd7b8290a4e8feed60ec1261bea13a274bb..bec822a2ae52a1d7dfde6a76c0cad1d6621a146c 100644 (file)
@@ -516,13 +516,16 @@ qemuProcessShutdownOrReboot(virQEMUDriverPtr driver,
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
     if (priv->fakeReboot) {
+        g_autofree char *name = g_strdup_printf("reboot-%s", vm->def->name);
         qemuDomainSetFakeReboot(driver, vm, false);
         virObjectRef(vm);
         virThread th;
-        if (virThreadCreate(&th,
-                            false,
-                            qemuProcessFakeReboot,
-                            vm) < 0) {
+        if (virThreadCreateFull(&th,
+                                false,
+                                qemuProcessFakeReboot,
+                                name,
+                                false,
+                                vm) < 0) {
             VIR_ERROR(_("Failed to create reboot thread, killing domain"));
             ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_NOWAIT));
             priv->pausedShutdown = false;
@@ -8223,6 +8226,7 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
     virThread thread;
     struct qemuProcessReconnectData *src = opaque;
     struct qemuProcessReconnectData *data;
+    g_autofree char *name = NULL;
 
     /* If the VM was inactive, we don't need to reconnect */
     if (!obj->pid)
@@ -8242,7 +8246,10 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
     virObjectLock(obj);
     virObjectRef(obj);
 
-    if (virThreadCreate(&thread, false, qemuProcessReconnect, data) < 0) {
+    name = g_strdup_printf("init-%s", obj->def->name);
+
+    if (virThreadCreateFull(&thread, false, qemuProcessReconnect,
+                            name, false, data) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Could not create thread. QEMU initialization "
                          "might be incomplete"));
index 7082460bae5e76456d0b07c222bf52a09f054c59..37e53a87cc3fac2def878517a2381104288042aa 100644 (file)
@@ -713,7 +713,8 @@ static void daemonReloadHandler(virNetDaemonPtr dmn G_GNUC_UNUSED,
         return;
     }
 
-    if (virThreadCreate(&thr, false, daemonReloadHandlerThread, NULL) < 0) {
+    if (virThreadCreateFull(&thr, false, daemonReloadHandlerThread,
+                            "daemon-reload", false, NULL) < 0) {
         /*
          * Not much we can do on error here except log it.
          */
@@ -770,7 +771,8 @@ static void daemonStop(virNetDaemonPtr dmn)
 {
     virThread thr;
     virObjectRef(dmn);
-    if (virThreadCreate(&thr, false, daemonStopWorker, dmn) < 0)
+    if (virThreadCreateFull(&thr, false, daemonStopWorker,
+                            "daemon-stop", false, dmn) < 0)
         virObjectUnref(dmn);
 }
 
@@ -876,7 +878,8 @@ static int daemonStateInit(virNetDaemonPtr dmn)
 {
     virThread thr;
     virObjectRef(dmn);
-    if (virThreadCreate(&thr, false, daemonRunStateInit, dmn) < 0) {
+    if (virThreadCreateFull(&thr, false, daemonRunStateInit,
+                            "daemon-init", false, dmn) < 0) {
         virObjectUnref(dmn);
         return -1;
     }
index a5998801dec50095969dec0197648120a4dcb358..072ffdf5a303daad472b4a970b97e44e91ff04b5 100644 (file)
@@ -367,10 +367,11 @@ virNetServerPtr virNetServerNew(const char *name,
     if (!(srv = virObjectLockableNew(virNetServerClass)))
         return NULL;
 
-    if (!(srv->workers = virThreadPoolNew(min_workers, max_workers,
-                                          priority_workers,
-                                          virNetServerHandleJob,
-                                          srv)))
+    if (!(srv->workers = virThreadPoolNewFull(min_workers, max_workers,
+                                              priority_workers,
+                                              virNetServerHandleJob,
+                                              "rpc-worker",
+                                              srv)))
         goto error;
 
     srv->name = g_strdup(name);
index 9c0f041616af61e5fea36cadb8319ae55d2f3b64..37ae4325ca360e34af3b62917a249aa60db2ae50 100644 (file)
@@ -334,8 +334,8 @@ createVport(virStoragePoolDefPtr def,
         memcpy(cbdata->pool_uuid, def->uuid, VIR_UUID_BUFLEN);
         cbdata->fchost_name = g_steal_pointer(&name);
 
-        if (virThreadCreate(&thread, false, virStoragePoolFCRefreshThread,
-                            cbdata) < 0) {
+        if (virThreadCreateFull(&thread, false, virStoragePoolFCRefreshThread,
+                                "scsi-refresh", false, cbdata) < 0) {
             /* Oh well - at least someone can still refresh afterwards */
             VIR_DEBUG("Failed to create FC Pool Refresh Thread");
             virStoragePoolFCRefreshDataFree(cbdata);
index 7e593359a8e614d7f5e5b09fd72cc195a11a45ff..1c56527e38dfb00ebe850d6813669a90065d1238 100644 (file)
@@ -2367,8 +2367,8 @@ virStorageVolFDStreamCloseCb(virStreamPtr st G_GNUC_UNUSED,
 {
     virThread thread;
 
-    if (virThreadCreate(&thread, false, virStorageVolPoolRefreshThread,
-                        opaque) < 0) {
+    if (virThreadCreateFull(&thread, false, virStorageVolPoolRefreshThread,
+                            "vol-refresh", false, opaque) < 0) {
         /* Not much else can be done */
         VIR_ERROR(_("Failed to create thread to handle pool refresh"));
         goto error;
index 4a87f7c281788542f1405645e97a61b00afb45b9..c150d994529c31b2648f48ee32825b2a74d51d19 100644 (file)
@@ -2620,8 +2620,9 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
         /* clear any error so we can catch if the helper thread reports one */
         cmd->has_error = 0;
         if (VIR_ALLOC(cmd->asyncioThread) < 0 ||
-            virThreadCreate(cmd->asyncioThread, true,
-                            virCommandDoAsyncIOHelper, cmd) < 0) {
+            virThreadCreateFull(cmd->asyncioThread, true,
+                                virCommandDoAsyncIOHelper,
+                                "cmd-async-io", false, cmd) < 0) {
             virReportSystemError(errno, "%s",
                                  _("Unable to create thread "
                                    "to process command's IO"));
index 3337fc20607edd5467c2c46617346e3fc094cf0f..111e451f8c9d38dccd9e5d5dc189508a361f0de9 100644 (file)
@@ -1134,10 +1134,12 @@ static int virFDStreamOpenInternal(virStreamPtr st,
             goto error;
         }
 
-        if (virThreadCreate(fdst->thread,
-                            true,
-                            virFDStreamThread,
-                            threadData) < 0)
+        if (virThreadCreateFull(fdst->thread,
+                                true,
+                                virFDStreamThread,
+                                "fd-stream",
+                                false,
+                                threadData) < 0)
             goto error;
     }
 
index f81ea1ce02271810d33c926647e018461b0199dd..544a29783c9124db70cde5e364ba2417d58ae11b 100644 (file)
@@ -220,9 +220,11 @@ int virNodeSuspend(unsigned int target,
     if (virNodeSuspendSetNodeWakeup(duration) < 0)
         goto cleanup;
 
-    if (virThreadCreate(&thread, false,
-                        virNodeSuspendHelper,
-                        (void *)cmdString) < 0) {
+    if (virThreadCreateFull(&thread, false,
+                            virNodeSuspendHelper,
+                            "node-suspend",
+                            false,
+                            (void *)cmdString) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Failed to create thread to suspend the host"));
         goto cleanup;
index ff5f34a946b9a2ac6659bb276f8b0208019ba0a0..379d2369ade821d8526f2569bf47bb61e87ae9da 100644 (file)
@@ -54,7 +54,7 @@ struct _virThreadPool {
     bool quit;
 
     virThreadPoolJobFunc jobFunc;
-    const char *jobFuncName;
+    const char *jobName;
     void *jobOpaque;
     virThreadPoolJobList jobList;
     size_t jobQueueDepth;
@@ -187,6 +187,7 @@ virThreadPoolExpand(virThreadPoolPtr pool, size_t gain, bool priority)
         return -1;
 
     for (i = 0; i < gain; i++) {
+        g_autofree char *name = NULL;
         if (VIR_ALLOC(data) < 0)
             goto error;
 
@@ -194,10 +195,15 @@ virThreadPoolExpand(virThreadPoolPtr pool, size_t gain, bool priority)
         data->cond = priority ? &pool->prioCond : &pool->cond;
         data->priority = priority;
 
+        if (priority)
+            name = g_strdup_printf("prio-%s", pool->jobName);
+        else
+            name = g_strdup(pool->jobName);
+
         if (virThreadCreateFull(&(*workers)[i],
                                 false,
                                 virThreadPoolWorker,
-                                pool->jobFuncName,
+                                name,
                                 true,
                                 data) < 0) {
             VIR_FREE(data);
@@ -218,7 +224,7 @@ virThreadPoolNewFull(size_t minWorkers,
                      size_t maxWorkers,
                      size_t prioWorkers,
                      virThreadPoolJobFunc func,
-                     const char *funcName,
+                     const char *name,
                      void *opaque)
 {
     virThreadPoolPtr pool;
@@ -232,7 +238,7 @@ virThreadPoolNewFull(size_t minWorkers,
     pool->jobList.tail = pool->jobList.head = NULL;
 
     pool->jobFunc = func;
-    pool->jobFuncName = funcName;
+    pool->jobName = name;
     pool->jobOpaque = opaque;
 
     if (virMutexInit(&pool->mutex) < 0)
index 5a55e22489b3d94a1a7d7bc355030decb373c55e..c97d9b39196a140fea1d762ddda77de622284671 100644 (file)
@@ -35,7 +35,7 @@ virThreadPoolPtr virThreadPoolNewFull(size_t minWorkers,
                                       size_t maxWorkers,
                                       size_t prioWorkers,
                                       virThreadPoolJobFunc func,
-                                      const char *funcName,
+                                      const char *name,
                                       void *opaque) ATTRIBUTE_NONNULL(4);
 
 size_t virThreadPoolGetMinWorkers(virThreadPoolPtr pool);