提交 07518f77 编写于 作者: D Daniel P. Berrange 提交者: Cole Robinson

virt-host-validate: distinguish exists vs accessible for devices

Currently we just check that various devices are accessible.
This leads to inaccurate errors reported for /dev/kvm and
/dev/vhost-net if they exist but an unprivileged user lacks
access. Switch existing checks to look for file existance,
and add a separate check for accessibility of /dev/kvm
since some distros don't grant users access by default.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
(cherry picked from commit fd6d506c)
上级 26295a0e
...@@ -115,12 +115,29 @@ void virHostMsgFail(virHostValidateLevel level, ...@@ -115,12 +115,29 @@ void virHostMsgFail(virHostValidateLevel level,
} }
int virHostValidateDevice(const char *hvname, int virHostValidateDeviceExists(const char *hvname,
const char *dev_name, const char *dev_name,
virHostValidateLevel level, virHostValidateLevel level,
const char *hint) const char *hint)
{ {
virHostMsgCheck(hvname, "for device %s", dev_name); virHostMsgCheck(hvname, "if device %s exists", dev_name);
if (access(dev_name, F_OK) < 0) {
virHostMsgFail(level, hint);
return -1;
}
virHostMsgPass();
return 0;
}
int virHostValidateDeviceAccessible(const char *hvname,
const char *dev_name,
virHostValidateLevel level,
const char *hint)
{
virHostMsgCheck(hvname, "if device %s is accessible", dev_name);
if (access(dev_name, R_OK|W_OK) < 0) { if (access(dev_name, R_OK|W_OK) < 0) {
virHostMsgFail(level, hint); virHostMsgFail(level, hint);
......
...@@ -42,7 +42,12 @@ extern void virHostMsgPass(void); ...@@ -42,7 +42,12 @@ extern void virHostMsgPass(void);
extern void virHostMsgFail(virHostValidateLevel level, extern void virHostMsgFail(virHostValidateLevel level,
const char *hint); const char *hint);
extern int virHostValidateDevice(const char *hvname, extern int virHostValidateDeviceExists(const char *hvname,
const char *dev_name,
virHostValidateLevel level,
const char *hint);
extern int virHostValidateDeviceAccessible(const char *hvname,
const char *dev_name, const char *dev_name,
virHostValidateLevel level, virHostValidateLevel level,
const char *hint); const char *hint);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
*/ */
#include <config.h> #include <config.h>
#include "virt-host-validate-qemu.h" #include "virt-host-validate-qemu.h"
#include "virt-host-validate-common.h" #include "virt-host-validate-common.h"
...@@ -32,23 +31,28 @@ int virHostValidateQEMU(void) ...@@ -32,23 +31,28 @@ int virHostValidateQEMU(void)
if (virHostValidateHasCPUFlag("svm") || if (virHostValidateHasCPUFlag("svm") ||
virHostValidateHasCPUFlag("vmx")) { virHostValidateHasCPUFlag("vmx")) {
virHostMsgPass(); virHostMsgPass();
if (virHostValidateDevice("QEMU", "/dev/kvm", if (virHostValidateDeviceExists("QEMU", "/dev/kvm",
VIR_HOST_VALIDATE_FAIL, VIR_HOST_VALIDATE_FAIL,
_("Check that the 'kvm-intel' or 'kvm-amd' modules are " _("Check that the 'kvm-intel' or 'kvm-amd' modules are "
"loaded & the BIOS has enabled virtualization")) < 0) "loaded & the BIOS has enabled virtualization")) < 0)
ret = -1; ret = -1;
else if (virHostValidateDeviceAccessible("QEMU", "/dev/kvm",
VIR_HOST_VALIDATE_FAIL,
_("Check /dev/kvm is world writable or you are in "
"a group that is allowed to access it")) < 0)
ret = -1;
} else { } else {
virHostMsgFail(VIR_HOST_VALIDATE_WARN, virHostMsgFail(VIR_HOST_VALIDATE_WARN,
_("Only emulated CPUs are available, performance will be significantly limited")); _("Only emulated CPUs are available, performance will be significantly limited"));
} }
if (virHostValidateDevice("QEMU", "/dev/vhost-net", if (virHostValidateDeviceExists("QEMU", "/dev/vhost-net",
VIR_HOST_VALIDATE_WARN, VIR_HOST_VALIDATE_WARN,
_("Load the 'vhost_net' module to improve performance " _("Load the 'vhost_net' module to improve performance "
"of virtio networking")) < 0) "of virtio networking")) < 0)
ret = -1; ret = -1;
if (virHostValidateDevice("QEMU", "/dev/net/tun", if (virHostValidateDeviceExists("QEMU", "/dev/net/tun",
VIR_HOST_VALIDATE_FAIL, VIR_HOST_VALIDATE_FAIL,
_("Load the 'tun' module to enable networking for QEMU guests")) < 0) _("Load the 'tun' module to enable networking for QEMU guests")) < 0)
ret = -1; ret = -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册