mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
@@ -115,12 +115,29 @@ void virHostMsgFail(virHostValidateLevel level,
|
||||
}
|
||||
|
||||
|
||||
int virHostValidateDevice(const char *hvname,
|
||||
const char *dev_name,
|
||||
virHostValidateLevel level,
|
||||
const char *hint)
|
||||
int virHostValidateDeviceExists(const char *hvname,
|
||||
const char *dev_name,
|
||||
virHostValidateLevel level,
|
||||
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) {
|
||||
virHostMsgFail(level, hint);
|
||||
|
||||
Reference in New Issue
Block a user