static int virLogFormatString(char **msg, int linenr, const char *funcname, virLogPriority priority, const char *str) { int ret; /* * Be careful when changing the following log message formatting, we rely * on it when stripping libvirt debug messages from qemu log files. So when * changing this, you might also need to change the code there. * virLogFormatString() function name is mentioned there so it's sufficient * to just grep for it to find the right place. */ if ((funcname != NULL)) { ret = virAsprintfQuiet(msg, "%llu: %s : %s:%d : %s\n", virThreadSelfID(), virLogPriorityString(priority), funcname, linenr, str); } else { ret = virAsprintfQuiet(msg, "%llu: %s : %s\n", virThreadSelfID(), virLogPriorityString(priority), str); } return ret; }
void virThreadJobSet(const char *caller) { const char *worker; if (!caller || virThreadJobInitialize() < 0) return; if (virThreadLocalSet(&virThreadJobName, (void *) caller) < 0) virReportSystemError(errno, _("cannot set current job to %s"), caller); if ((worker = virThreadLocalGet(&virThreadJobWorker))) { VIR_DEBUG("Thread %llu (%s) is now running job %s", virThreadSelfID(), worker, caller); } else { VIR_DEBUG("Thread %llu is now running job %s", virThreadSelfID(), caller); } }
void virThreadJobSetWorker(const char *worker) { if (!worker || virThreadJobInitialize() < 0) return; if (virThreadLocalSet(&virThreadJobWorker, (void *) worker) < 0) virReportSystemError(errno, _("cannot set worker name to %s"), worker); VIR_DEBUG("Thread %llu is running worker %s", virThreadSelfID(), worker); }
void virThreadJobClear(int rv) { const char *old; const char *worker; if (virThreadJobInitialize() < 0) return; if (!(old = virThreadLocalGet(&virThreadJobName))) return; if (virThreadLocalSet(&virThreadJobName, NULL) < 0) virReportSystemError(errno, "%s", _("cannot reset current job")); if ((worker = virThreadLocalGet(&virThreadJobWorker))) { VIR_DEBUG("Thread %llu (%s) finished job %s with ret=%d", virThreadSelfID(), worker, old, rv); } else { VIR_DEBUG("Thread %llu finished job %s with ret=%d", virThreadSelfID(), old, rv); } }
/* * obj must be locked before calling, libxlDriverPrivatePtr must NOT be locked * * This must be called by anything that will change the VM state * in any way * * Upon successful return, the object will have its ref count increased, * successful calls must be followed by EndJob eventually */ int libxlDomainObjBeginJob(libxlDriverPrivatePtr driver ATTRIBUTE_UNUSED, virDomainObjPtr obj, enum libxlDomainJob job) { libxlDomainObjPrivatePtr priv = obj->privateData; unsigned long long now; unsigned long long then; if (virTimeMillisNow(&now) < 0) return -1; then = now + LIBXL_JOB_WAIT_TIME; virObjectRef(obj); while (priv->job.active) { VIR_DEBUG("Wait normal job condition for starting job: %s", libxlDomainJobTypeToString(job)); if (virCondWaitUntil(&priv->job.cond, &obj->parent.lock, then) < 0) goto error; } libxlDomainObjResetJob(priv); VIR_DEBUG("Starting job: %s", libxlDomainJobTypeToString(job)); priv->job.active = job; priv->job.owner = virThreadSelfID(); priv->job.started = now; priv->job.current->type = VIR_DOMAIN_JOB_UNBOUNDED; return 0; error: VIR_WARN("Cannot start job (%s) for domain %s;" " current job is (%s) owned by (%d)", libxlDomainJobTypeToString(job), obj->def->name, libxlDomainJobTypeToString(priv->job.active), priv->job.owner); if (errno == ETIMEDOUT) virReportError(VIR_ERR_OPERATION_TIMEOUT, "%s", _("cannot acquire state change lock")); else virReportSystemError(errno, "%s", _("cannot acquire job mutex")); virObjectUnref(obj); return -1; }