mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 23:07:44 +00:00
qemu: include libvirt & QEMU versions in QEMU log files
It is often helpful to know which version of libvirt and QEMU was present when a guest was first launched. Ensure this info is written into the QEMU log file for each guest.
This commit is contained in:
parent
490be8c724
commit
95fd6a91c6
@ -299,6 +299,7 @@ struct _virQEMUCaps {
|
||||
|
||||
unsigned int version;
|
||||
unsigned int kvmVersion;
|
||||
char *package;
|
||||
|
||||
virArch arch;
|
||||
|
||||
@ -1941,6 +1942,10 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
|
||||
ret->usedQMP = qemuCaps->usedQMP;
|
||||
ret->version = qemuCaps->version;
|
||||
ret->kvmVersion = qemuCaps->kvmVersion;
|
||||
|
||||
if (VIR_STRDUP(ret->package, qemuCaps->package) < 0)
|
||||
goto error;
|
||||
|
||||
ret->arch = qemuCaps->arch;
|
||||
|
||||
if (VIR_ALLOC_N(ret->cpuDefinitions, qemuCaps->ncpuDefinitions) < 0)
|
||||
@ -1992,6 +1997,7 @@ void virQEMUCapsDispose(void *obj)
|
||||
|
||||
virBitmapFree(qemuCaps->flags);
|
||||
|
||||
VIR_FREE(qemuCaps->package);
|
||||
VIR_FREE(qemuCaps->binary);
|
||||
}
|
||||
|
||||
@ -2116,6 +2122,12 @@ unsigned int virQEMUCapsGetKVMVersion(virQEMUCapsPtr qemuCaps)
|
||||
}
|
||||
|
||||
|
||||
const char *virQEMUCapsGetPackage(virQEMUCapsPtr qemuCaps)
|
||||
{
|
||||
return qemuCaps->package;
|
||||
}
|
||||
|
||||
|
||||
int virQEMUCapsAddCPUDefinition(virQEMUCapsPtr qemuCaps,
|
||||
const char *name)
|
||||
{
|
||||
@ -2672,6 +2684,9 @@ virQEMUCapsLoadCache(virQEMUCapsPtr qemuCaps, const char *filename,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Don't check for NULL, since it is optional and thus may be missing */
|
||||
qemuCaps->package = virXPathString("string(./package)", ctxt);
|
||||
|
||||
if (!(str = virXPathString("string(./arch)", ctxt))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("missing arch in QEMU capabilities cache"));
|
||||
@ -2783,6 +2798,10 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const char *filename)
|
||||
virBufferAsprintf(&buf, "<kvmVersion>%d</kvmVersion>\n",
|
||||
qemuCaps->kvmVersion);
|
||||
|
||||
if (qemuCaps->package)
|
||||
virBufferAsprintf(&buf, "<package>%s</package>\n",
|
||||
qemuCaps->package);
|
||||
|
||||
virBufferAsprintf(&buf, "<arch>%s</arch>\n",
|
||||
virArchToString(qemuCaps->arch));
|
||||
|
||||
@ -2872,6 +2891,7 @@ virQEMUCapsReset(virQEMUCapsPtr qemuCaps)
|
||||
|
||||
virBitmapClearAll(qemuCaps->flags);
|
||||
qemuCaps->version = qemuCaps->kvmVersion = 0;
|
||||
VIR_FREE(qemuCaps->package);
|
||||
qemuCaps->arch = VIR_ARCH_NONE;
|
||||
qemuCaps->usedQMP = false;
|
||||
|
||||
@ -3204,6 +3224,7 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
|
||||
}
|
||||
|
||||
qemuCaps->version = major * 1000000 + minor * 1000 + micro;
|
||||
qemuCaps->package = package;
|
||||
qemuCaps->usedQMP = true;
|
||||
|
||||
virQEMUCapsInitQMPBasic(qemuCaps);
|
||||
@ -3249,7 +3270,6 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(package);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -266,6 +266,7 @@ char *virQEMUCapsFlagsString(virQEMUCapsPtr qemuCaps);
|
||||
const char *virQEMUCapsGetBinary(virQEMUCapsPtr qemuCaps);
|
||||
virArch virQEMUCapsGetArch(virQEMUCapsPtr qemuCaps);
|
||||
unsigned int virQEMUCapsGetVersion(virQEMUCapsPtr qemuCaps);
|
||||
const char *virQEMUCapsGetPackage(virQEMUCapsPtr qemuCaps);
|
||||
unsigned int virQEMUCapsGetKVMVersion(virQEMUCapsPtr qemuCaps);
|
||||
int virQEMUCapsAddCPUDefinition(virQEMUCapsPtr qemuCaps,
|
||||
const char *name);
|
||||
|
@ -76,7 +76,6 @@
|
||||
|
||||
VIR_LOG_INIT("qemu.qemu_process");
|
||||
|
||||
#define START_POSTFIX ": starting up\n"
|
||||
#define ATTACH_POSTFIX ": attaching\n"
|
||||
#define SHUTDOWN_POSTFIX ": shutting down\n"
|
||||
|
||||
@ -4249,6 +4248,45 @@ qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
qemuLogOperation(virDomainObjPtr vm,
|
||||
const char *msg,
|
||||
int logfd,
|
||||
virCommandPtr cmd)
|
||||
{
|
||||
char *timestamp;
|
||||
char *logline;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
int qemuVersion = virQEMUCapsGetVersion(priv->qemuCaps);
|
||||
const char *package = virQEMUCapsGetPackage(priv->qemuCaps);
|
||||
char ebuf[1024];
|
||||
|
||||
if ((timestamp = virTimeStringNow()) == NULL)
|
||||
goto error;
|
||||
|
||||
if (virAsprintf(&logline, "%s: %s %s, qemu version: %d.%d.%d%s\n",
|
||||
timestamp, msg, VIR_LOG_VERSION_STRING,
|
||||
(qemuVersion / 1000000) % 1000, (qemuVersion / 1000) % 1000, qemuVersion % 1000,
|
||||
package ? package : "") < 0)
|
||||
goto error;
|
||||
|
||||
if (safewrite(logfd, logline, strlen(logline)) < 0)
|
||||
goto error;
|
||||
|
||||
if (cmd)
|
||||
virCommandWriteArgLog(cmd, logfd);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(timestamp);
|
||||
VIR_FREE(logline);
|
||||
return;
|
||||
|
||||
error:
|
||||
VIR_WARN("Unable to write banner to logfile: %s",
|
||||
virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
int qemuProcessStart(virConnectPtr conn,
|
||||
virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
@ -4264,7 +4302,6 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
off_t pos = -1;
|
||||
char ebuf[1024];
|
||||
int logfile = -1;
|
||||
char *timestamp;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virCommandPtr cmd = NULL;
|
||||
struct qemuProcessHookData hookData;
|
||||
@ -4620,19 +4657,7 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((timestamp = virTimeStringNow()) == NULL) {
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (safewrite(logfile, timestamp, strlen(timestamp)) < 0 ||
|
||||
safewrite(logfile, START_POSTFIX, strlen(START_POSTFIX)) < 0) {
|
||||
VIR_WARN("Unable to write timestamp to logfile: %s",
|
||||
virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||
}
|
||||
|
||||
VIR_FREE(timestamp);
|
||||
}
|
||||
|
||||
virCommandWriteArgLog(cmd, logfile);
|
||||
qemuLogOperation(vm, "starting up", logfile, cmd);
|
||||
|
||||
qemuDomainObjCheckTaint(driver, vm, logfile);
|
||||
|
||||
|
@ -448,21 +448,8 @@ static int
|
||||
virLogVersionString(const char **rawmsg,
|
||||
char **msg)
|
||||
{
|
||||
#ifdef PACKAGER_VERSION
|
||||
# ifdef PACKAGER
|
||||
# define LOG_VERSION_STRING \
|
||||
"libvirt version: " VERSION ", package: " PACKAGER_VERSION " (" PACKAGER ")"
|
||||
# else
|
||||
# define LOG_VERSION_STRING \
|
||||
"libvirt version: " VERSION ", package: " PACKAGER_VERSION
|
||||
# endif
|
||||
#else
|
||||
# define LOG_VERSION_STRING \
|
||||
"libvirt version: " VERSION
|
||||
#endif
|
||||
|
||||
*rawmsg = LOG_VERSION_STRING;
|
||||
return virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, LOG_VERSION_STRING);
|
||||
*rawmsg = VIR_LOG_VERSION_STRING;
|
||||
return virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, VIR_LOG_VERSION_STRING);
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,19 @@
|
||||
# include "internal.h"
|
||||
# include "virbuffer.h"
|
||||
|
||||
# ifdef PACKAGER_VERSION
|
||||
# ifdef PACKAGER
|
||||
# define VIR_LOG_VERSION_STRING \
|
||||
"libvirt version: " VERSION ", package: " PACKAGER_VERSION " (" PACKAGER ")"
|
||||
# else
|
||||
# define VIR_LOG_VERSION_STRING \
|
||||
"libvirt version: " VERSION ", package: " PACKAGER_VERSION
|
||||
# endif
|
||||
# else
|
||||
# define VIR_LOG_VERSION_STRING \
|
||||
"libvirt version: " VERSION
|
||||
# endif
|
||||
|
||||
/*
|
||||
* To be made public
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user