mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Keep pidfile path in qemuDomainObjPrivate struct
Avoid re-formatting the pidfile path everytime we need it. Create it once when starting the guest, and preserve it until the guest is shutdown. * src/libvirt_private.syms, src/util/util.c, src/util/util.h: Add virFileReadPidPath * src/qemu/qemu_domain.h: Add pidfile field * src/qemu/qemu_process.c: Store pidfile path in qemuDomainObjPrivate
This commit is contained in:
parent
eb7be6a606
commit
accfe952eb
@ -1003,6 +1003,7 @@ virFilePid;
|
|||||||
virFileReadAll;
|
virFileReadAll;
|
||||||
virFileReadLimFD;
|
virFileReadLimFD;
|
||||||
virFileReadPid;
|
virFileReadPid;
|
||||||
|
virFileReadPidPath;
|
||||||
virFileResolveLink;
|
virFileResolveLink;
|
||||||
virFileSanitizePath;
|
virFileSanitizePath;
|
||||||
virFileStripSuffix;
|
virFileStripSuffix;
|
||||||
|
@ -88,6 +88,7 @@ struct _qemuDomainObjPrivate {
|
|||||||
bool monError;
|
bool monError;
|
||||||
unsigned long long monStart;
|
unsigned long long monStart;
|
||||||
bool gotShutdown;
|
bool gotShutdown;
|
||||||
|
char *pidfile;
|
||||||
|
|
||||||
int nvcpupids;
|
int nvcpupids;
|
||||||
int *vcpupids;
|
int *vcpupids;
|
||||||
|
@ -76,6 +76,7 @@ qemuProcessRemoveDomainStatus(struct qemud_driver *driver,
|
|||||||
{
|
{
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
char *file = NULL;
|
char *file = NULL;
|
||||||
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
|
||||||
if (virAsprintf(&file, "%s/%s.xml", driver->stateDir, vm->def->name) < 0) {
|
if (virAsprintf(&file, "%s/%s.xml", driver->stateDir, vm->def->name) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
@ -87,11 +88,12 @@ qemuProcessRemoveDomainStatus(struct qemud_driver *driver,
|
|||||||
vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
|
vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||||
VIR_FREE(file);
|
VIR_FREE(file);
|
||||||
|
|
||||||
if (virFileDeletePid(driver->stateDir, vm->def->name) != 0)
|
if (priv->pidfile &&
|
||||||
|
unlink(priv->pidfile) < 0 &&
|
||||||
|
errno != ENOENT)
|
||||||
VIR_WARN("Failed to remove PID file for %s: %s",
|
VIR_WARN("Failed to remove PID file for %s: %s",
|
||||||
vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
|
vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2339,7 +2341,6 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
int ret;
|
int ret;
|
||||||
off_t pos = -1;
|
off_t pos = -1;
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
char *pidfile = NULL;
|
|
||||||
int logfile = -1;
|
int logfile = -1;
|
||||||
char *timestamp;
|
char *timestamp;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
@ -2491,16 +2492,18 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
priv->monStart = 0;
|
priv->monStart = 0;
|
||||||
priv->gotShutdown = false;
|
priv->gotShutdown = false;
|
||||||
|
|
||||||
if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
|
VIR_FREE(priv->pidfile);
|
||||||
virReportSystemError(ret,
|
if (!(priv->pidfile = virFilePid(driver->stateDir, vm->def->name))) {
|
||||||
_("Cannot remove stale PID file for %s"),
|
virReportSystemError(errno,
|
||||||
vm->def->name);
|
"%s", _("Failed to build pidfile path."));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(pidfile = virFilePid(driver->stateDir, vm->def->name))) {
|
if (unlink(priv->pidfile) < 0 &&
|
||||||
|
errno != ENOENT) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
"%s", _("Failed to build pidfile path."));
|
_("Cannot remove stale PID file %s"),
|
||||||
|
priv->pidfile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2591,16 +2594,15 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
virCommandSetOutputFD(cmd, &logfile);
|
virCommandSetOutputFD(cmd, &logfile);
|
||||||
virCommandSetErrorFD(cmd, &logfile);
|
virCommandSetErrorFD(cmd, &logfile);
|
||||||
virCommandNonblockingFDs(cmd);
|
virCommandNonblockingFDs(cmd);
|
||||||
virCommandSetPidFile(cmd, pidfile);
|
virCommandSetPidFile(cmd, priv->pidfile);
|
||||||
virCommandDaemonize(cmd);
|
virCommandDaemonize(cmd);
|
||||||
virCommandRequireHandshake(cmd);
|
virCommandRequireHandshake(cmd);
|
||||||
|
|
||||||
ret = virCommandRun(cmd, NULL);
|
ret = virCommandRun(cmd, NULL);
|
||||||
VIR_FREE(pidfile);
|
|
||||||
|
|
||||||
/* wait for qemu process to show up */
|
/* wait for qemu process to show up */
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
if (virFileReadPid(driver->stateDir, vm->def->name, &vm->pid)) {
|
if (virFileReadPidPath(priv->pidfile, &vm->pid)) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Domain %s didn't show up"), vm->def->name);
|
_("Domain %s didn't show up"), vm->def->name);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -2946,6 +2948,7 @@ retry:
|
|||||||
priv->nvcpupids = 0;
|
priv->nvcpupids = 0;
|
||||||
qemuCapsFree(priv->qemuCaps);
|
qemuCapsFree(priv->qemuCaps);
|
||||||
priv->qemuCaps = NULL;
|
priv->qemuCaps = NULL;
|
||||||
|
VIR_FREE(priv->pidfile);
|
||||||
|
|
||||||
/* The "release" hook cleans up additional resources */
|
/* The "release" hook cleans up additional resources */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
|
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
|
||||||
|
@ -1236,26 +1236,16 @@ cleanup:
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int virFileReadPid(const char *dir,
|
|
||||||
const char *name,
|
int virFileReadPidPath(const char *path,
|
||||||
pid_t *pid)
|
pid_t *pid)
|
||||||
{
|
{
|
||||||
int rc;
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *pidfile = NULL;
|
int rc;
|
||||||
|
|
||||||
*pid = 0;
|
*pid = 0;
|
||||||
|
|
||||||
if (name == NULL || dir == NULL) {
|
if (!(file = fopen(path, "r"))) {
|
||||||
rc = EINVAL;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(pidfile = virFilePid(dir, name))) {
|
|
||||||
rc = ENOMEM;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(file = fopen(pidfile, "r"))) {
|
|
||||||
rc = errno;
|
rc = errno;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1273,6 +1263,31 @@ int virFileReadPid(const char *dir,
|
|||||||
|
|
||||||
rc = 0;
|
rc = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int virFileReadPid(const char *dir,
|
||||||
|
const char *name,
|
||||||
|
pid_t *pid)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
char *pidfile = NULL;
|
||||||
|
*pid = 0;
|
||||||
|
|
||||||
|
if (name == NULL || dir == NULL) {
|
||||||
|
rc = EINVAL;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(pidfile = virFilePid(dir, name))) {
|
||||||
|
rc = ENOMEM;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = virFileReadPidPath(pidfile, pid);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(pidfile);
|
VIR_FREE(pidfile);
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -125,6 +125,8 @@ int virFileWritePidPath(const char *path,
|
|||||||
int virFileWritePid(const char *dir,
|
int virFileWritePid(const char *dir,
|
||||||
const char *name,
|
const char *name,
|
||||||
pid_t pid) ATTRIBUTE_RETURN_CHECK;
|
pid_t pid) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int virFileReadPidPath(const char *path,
|
||||||
|
pid_t *pid) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virFileReadPid(const char *dir,
|
int virFileReadPid(const char *dir,
|
||||||
const char *name,
|
const char *name,
|
||||||
pid_t *pid) ATTRIBUTE_RETURN_CHECK;
|
pid_t *pid) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user