"158",
"sev");
-static bool quiet;
-
-void virHostMsgSetQuiet(bool quietFlag)
-{
- quiet = quietFlag;
-}
-
-void virHostMsgCheck(const char *prefix,
- const char *format,
- ...)
-{
- va_list args;
- g_autofree char *msg = NULL;
-
- if (quiet)
- return;
-
- va_start(args, format);
- msg = g_strdup_vprintf(format, args);
- va_end(args);
-
- fprintf(stdout, "%1$6s: %2$-69s: ", prefix, msg);
-}
-
-static bool virHostMsgWantEscape(void)
-{
- static bool detectTty = true;
- static bool wantEscape;
- if (detectTty) {
- if (isatty(STDOUT_FILENO))
- wantEscape = true;
- detectTty = false;
- }
- return wantEscape;
-}
-
-void virHostMsgPass(void)
-{
- if (quiet)
- return;
-
- if (virHostMsgWantEscape())
- fprintf(stdout, "\033[32m%s\033[0m\n", _("PASS"));
- else
- fprintf(stdout, "%s\n", _("PASS"));
-}
-
-
-static const char * failMessages[] = {
- N_("FAIL"),
- N_("WARN"),
- N_("NOTE"),
-};
-
-G_STATIC_ASSERT(G_N_ELEMENTS(failMessages) == VIR_HOST_VALIDATE_LAST);
-
-static const char *failEscapeCodes[] = {
- "\033[31m",
- "\033[33m",
- "\033[34m",
-};
-
-G_STATIC_ASSERT(G_N_ELEMENTS(failEscapeCodes) == VIR_HOST_VALIDATE_LAST);
-
-void virHostMsgFail(virHostValidateLevel level,
- const char *format,
- ...)
-{
- va_list args;
- g_autofree char *msg = NULL;
-
- if (quiet)
- return;
-
- va_start(args, format);
- msg = g_strdup_vprintf(format, args);
- va_end(args);
-
- if (virHostMsgWantEscape())
- fprintf(stdout, "%s%s\033[0m (%s)\n",
- failEscapeCodes[level], _(failMessages[level]), msg);
- else
- fprintf(stdout, "%s (%s)\n",
- _(failMessages[level]), msg);
-}
-
int virHostValidateDeviceExists(const char *hvname,
const char *dev_name,
- virHostValidateLevel level,
+ virValidateLevel level,
const char *hint)
{
- virHostMsgCheck(hvname, _("Checking if device '%1$s' exists"), dev_name);
+ virValidateCheck(hvname, _("Checking if device '%1$s' exists"), dev_name);
if (access(dev_name, F_OK) < 0) {
- virHostMsgFail(level, "%s", hint);
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "%s", hint);
+ return VIR_VALIDATE_FAILURE(level);
}
- virHostMsgPass();
+ virValidatePass();
return 0;
}
int virHostValidateDeviceAccessible(const char *hvname,
const char *dev_name,
- virHostValidateLevel level,
+ virValidateLevel level,
const char *hint)
{
- virHostMsgCheck(hvname, _("Checking if device '%1$s' is accessible"), dev_name);
+ virValidateCheck(hvname, _("Checking if device '%1$s' is accessible"), dev_name);
if (access(dev_name, R_OK|W_OK) < 0) {
- virHostMsgFail(level, "%s", hint);
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "%s", hint);
+ return VIR_VALIDATE_FAILURE(level);
}
- virHostMsgPass();
+ virValidatePass();
return 0;
}
int virHostValidateNamespace(const char *hvname,
const char *ns_name,
- virHostValidateLevel level,
+ virValidateLevel level,
const char *hint)
{
char nspath[100];
- virHostMsgCheck(hvname, _("Checking for namespace '%1$s'"), ns_name);
+ virValidateCheck(hvname, _("Checking for namespace '%1$s'"), ns_name);
g_snprintf(nspath, sizeof(nspath), "/proc/self/ns/%s", ns_name);
if (access(nspath, F_OK) < 0) {
- virHostMsgFail(level, "%s", hint);
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "%s", hint);
+ return VIR_VALIDATE_FAILURE(level);
}
- virHostMsgPass();
+ virValidatePass();
return 0;
}
int virHostValidateLinuxKernel(const char *hvname,
int version,
- virHostValidateLevel level,
+ virValidateLevel level,
const char *hint)
{
struct utsname uts;
uname(&uts);
- virHostMsgCheck(hvname, _("Checking for Linux >= %1$d.%2$d.%3$d"),
- ((version >> 16) & 0xff),
- ((version >> 8) & 0xff),
- (version & 0xff));
+ virValidateCheck(hvname, _("Checking for Linux >= %1$d.%2$d.%3$d"),
+ ((version >> 16) & 0xff),
+ ((version >> 8) & 0xff),
+ (version & 0xff));
if (STRNEQ(uts.sysname, "Linux")) {
- virHostMsgFail(level, "%s", hint);
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "%s", hint);
+ return VIR_VALIDATE_FAILURE(level);
}
if (virStringParseVersion(&thisversion, uts.release, true) < 0) {
- virHostMsgFail(level, "%s", hint);
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "%s", hint);
+ return VIR_VALIDATE_FAILURE(level);
}
if (thisversion < version) {
- virHostMsgFail(level, "%s", hint);
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "%s", hint);
+ return VIR_VALIDATE_FAILURE(level);
} else {
- virHostMsgPass();
+ virValidatePass();
return 0;
}
}
#ifdef __linux__
int virHostValidateCGroupControllers(const char *hvname,
int controllers,
- virHostValidateLevel level)
+ virValidateLevel level)
{
g_autoptr(virCgroup) group = NULL;
int ret = 0;
if (virCgroupNew("/", -1, &group) < 0) {
fprintf(stderr, "Unable to initialize cgroups: %s\n",
virGetLastErrorMessage());
- return VIR_HOST_VALIDATE_FAILURE(level);
+ return VIR_VALIDATE_FAILURE(level);
}
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
if (!(controllers & flag))
continue;
- virHostMsgCheck(hvname, _("Checking for cgroup '%1$s' controller support"), cg_name);
+ virValidateCheck(hvname, _("Checking for cgroup '%1$s' controller support"), cg_name);
if (!virCgroupHasController(group, i)) {
- ret = VIR_HOST_VALIDATE_FAILURE(level);
- virHostMsgFail(level, "Enable '%s' in kernel Kconfig file or "
- "mount/enable cgroup controller in your system",
- cg_name);
+ ret = VIR_VALIDATE_FAILURE(level);
+ virValidateFail(level, "Enable '%s' in kernel Kconfig file or "
+ "mount/enable cgroup controller in your system",
+ cg_name);
} else {
- virHostMsgPass();
+ virValidatePass();
}
}
#else /* !__linux__ */
int virHostValidateCGroupControllers(const char *hvname G_GNUC_UNUSED,
int controllers G_GNUC_UNUSED,
- virHostValidateLevel level)
+ virValidateLevel level)
{
- virHostMsgFail(level, "%s", "This platform does not support cgroups");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "%s", "This platform does not support cgroups");
+ return VIR_VALIDATE_FAILURE(level);
}
#endif /* !__linux__ */
int virHostValidateIOMMU(const char *hvname,
- virHostValidateLevel level)
+ virValidateLevel level)
{
g_autoptr(virBitmap) flags = NULL;
struct stat sb;
struct dirent *dent;
int rc;
- virHostMsgCheck(hvname, "%s", _("Checking for device assignment IOMMU support"));
+ virValidateCheck(hvname, "%s", _("Checking for device assignment IOMMU support"));
flags = virHostValidateGetCPUFlags();
if (isIntel) {
if (access("/sys/firmware/acpi/tables/DMAR", F_OK) == 0) {
- virHostMsgPass();
+ virValidatePass();
bootarg = "intel_iommu=on";
} else {
- virHostMsgFail(level,
- "No ACPI DMAR table found, IOMMU either "
- "disabled in BIOS or not supported by this "
- "hardware platform");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "No ACPI DMAR table found, IOMMU either "
+ "disabled in BIOS or not supported by this "
+ "hardware platform");
+ return VIR_VALIDATE_FAILURE(level);
}
} else if (isAMD) {
if (access("/sys/firmware/acpi/tables/IVRS", F_OK) == 0) {
- virHostMsgPass();
+ virValidatePass();
bootarg = "iommu=pt iommu=1";
} else {
- virHostMsgFail(level,
- "No ACPI IVRS table found, IOMMU either "
- "disabled in BIOS or not supported by this "
- "hardware platform");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "No ACPI IVRS table found, IOMMU either "
+ "disabled in BIOS or not supported by this "
+ "hardware platform");
+ return VIR_VALIDATE_FAILURE(level);
}
} else if (ARCH_IS_PPC64(arch)) {
- virHostMsgPass();
+ virValidatePass();
} else if (ARCH_IS_S390(arch)) {
g_autoptr(DIR) dir = NULL;
* no PCI devices the directory is still there but is
* empty. */
if (!virDirOpen(&dir, "/sys/bus/pci/devices")) {
- virHostMsgFail(VIR_HOST_VALIDATE_NOTE,
- "Skipped - PCI support disabled");
- return VIR_HOST_VALIDATE_FAILURE(VIR_HOST_VALIDATE_NOTE);
+ virValidateFail(VIR_VALIDATE_NOTE,
+ "Skipped - PCI support disabled");
+ return VIR_VALIDATE_FAILURE(VIR_VALIDATE_NOTE);
}
rc = virDirRead(dir, &dent, NULL);
if (rc <= 0) {
- virHostMsgFail(VIR_HOST_VALIDATE_NOTE,
- "Skipped - No PCI devices are online");
- return VIR_HOST_VALIDATE_FAILURE(VIR_HOST_VALIDATE_NOTE);
+ virValidateFail(VIR_VALIDATE_NOTE,
+ "Skipped - No PCI devices are online");
+ return VIR_VALIDATE_FAILURE(VIR_VALIDATE_NOTE);
}
- virHostMsgPass();
+ virValidatePass();
} else if (ARCH_IS_ARM(arch)) {
if (access("/sys/firmware/acpi/tables/IORT", F_OK) != 0) {
- virHostMsgFail(level,
- "No ACPI IORT table found, IOMMU not "
- "supported by this hardware platform");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "No ACPI IORT table found, IOMMU not "
+ "supported by this hardware platform");
+ return VIR_VALIDATE_FAILURE(level);
} else {
rc = virAcpiHasSMMU();
if (rc < 0) {
- virHostMsgFail(level,
- "Failed to parse ACPI IORT table");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "Failed to parse ACPI IORT table");
+ return VIR_VALIDATE_FAILURE(level);
} else if (rc == 0) {
- virHostMsgFail(level,
- "No SMMU found");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "No SMMU found");
+ return VIR_VALIDATE_FAILURE(level);
} else {
- virHostMsgPass();
+ virValidatePass();
}
}
} else {
- virHostMsgFail(level,
- "Unknown if this platform has IOMMU support");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "Unknown if this platform has IOMMU support");
+ return VIR_VALIDATE_FAILURE(level);
}
if (!S_ISDIR(sb.st_mode))
return 0;
- virHostMsgCheck(hvname, "%s", _("Checking if IOMMU is enabled by kernel"));
+ virValidateCheck(hvname, "%s", _("Checking if IOMMU is enabled by kernel"));
if (sb.st_nlink <= 2) {
if (bootarg)
- virHostMsgFail(level,
- "IOMMU appears to be disabled in kernel. "
- "Add %s to kernel cmdline arguments", bootarg);
+ virValidateFail(level,
+ "IOMMU appears to be disabled in kernel. "
+ "Add %s to kernel cmdline arguments", bootarg);
else
- virHostMsgFail(level, "IOMMU capability not compiled into kernel.");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "IOMMU capability not compiled into kernel.");
+ return VIR_VALIDATE_FAILURE(level);
}
- virHostMsgPass();
+ virValidatePass();
return 0;
}
int virHostValidateSecureGuests(const char *hvname,
- virHostValidateLevel level)
+ virValidateLevel level)
{
g_autoptr(virBitmap) flags = NULL;
bool hasFac158 = false;
else if (flags && virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SEV))
hasAMDSev = true;
- virHostMsgCheck(hvname, "%s", _("Checking for secure guest support"));
+ virValidateCheck(hvname, "%s", _("Checking for secure guest support"));
if (ARCH_IS_S390(arch)) {
if (hasFac158) {
if (!virFileIsDir("/sys/firmware/uv")) {
- virHostMsgFail(level, "IBM Secure Execution not supported by "
- "the currently used kernel");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "IBM Secure Execution not supported by "
+ "the currently used kernel");
+ return VIR_VALIDATE_FAILURE(level);
}
/* we're prefix matching rather than equality matching here, because
G_N_ELEMENTS(kIBMValues),
VIR_KERNEL_CMDLINE_FLAGS_SEARCH_FIRST |
VIR_KERNEL_CMDLINE_FLAGS_CMP_PREFIX)) {
- virHostMsgPass();
+ virValidatePass();
return 1;
} else {
- virHostMsgFail(level,
- "IBM Secure Execution appears to be disabled "
- "in kernel. Add prot_virt=1 to kernel cmdline "
- "arguments");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "IBM Secure Execution appears to be disabled "
+ "in kernel. Add prot_virt=1 to kernel cmdline "
+ "arguments");
+ return VIR_VALIDATE_FAILURE(level);
}
} else {
- virHostMsgFail(level, "Hardware or firmware does not provide "
- "support for IBM Secure Execution");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "Hardware or firmware does not provide "
+ "support for IBM Secure Execution");
+ return VIR_VALIDATE_FAILURE(level);
}
} else if (hasAMDSev) {
if (virFileReadValueString(&mod_value, "/sys/module/kvm_amd/parameters/sev") < 0) {
- virHostMsgFail(level, "AMD Secure Encrypted Virtualization not "
- "supported by the currently used kernel");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level, "AMD Secure Encrypted Virtualization not "
+ "supported by the currently used kernel");
+ return VIR_VALIDATE_FAILURE(level);
}
if (mod_value[0] != '1' && mod_value[0] != 'Y' && mod_value[0] != 'y') {
- virHostMsgFail(level,
- "AMD Secure Encrypted Virtualization appears to be "
- "disabled in kernel. Add kvm_amd.sev=1 "
- "to the kernel cmdline arguments");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "AMD Secure Encrypted Virtualization appears to be "
+ "disabled in kernel. Add kvm_amd.sev=1 "
+ "to the kernel cmdline arguments");
+ return VIR_VALIDATE_FAILURE(level);
}
if (virFileExists("/dev/sev")) {
- virHostMsgPass();
+ virValidatePass();
return 1;
} else {
- virHostMsgFail(level,
- "AMD Secure Encrypted Virtualization appears to be "
- "disabled in firmware.");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "AMD Secure Encrypted Virtualization appears to be "
+ "disabled in firmware.");
+ return VIR_VALIDATE_FAILURE(level);
}
}
- virHostMsgFail(level,
- "Unknown if this platform has Secure Guest support");
- return VIR_HOST_VALIDATE_FAILURE(level);
+ virValidateFail(level,
+ "Unknown if this platform has Secure Guest support");
+ return VIR_VALIDATE_FAILURE(level);
}