/dev/vhost-vsock is usable only if the module is loaded. Let's load the module
just like in other places where kernel module is required (nbd, pci stub
driver).
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
---
src/qemu/qemu_process.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ec6ca14..5aaa77c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -92,6 +92,7 @@
#include "viridentity.h"
#include "virthreadjob.h"
#include "virutil.h"
+#include "virkmod.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -6414,6 +6415,7 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr driver,
return 0;
}
+#define VHOST_VSOCK_MODULE "vhost-vsock"
int
qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock)
@@ -6422,6 +6424,22 @@ qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock)
const char *vsock_path = "/dev/vhost-vsock";
int fd;
+ if (virKModIsProhibited(VHOST_VSOCK_MODULE)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Failed to load vhost-vsock module: "
+ "administratively prohibited"));
+ return -1;
+ } else {
+ g_autofree char *errbuf = NULL;
+
+ if ((errbuf = virKModLoad(VHOST_VSOCK_MODULE))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to load vhost-vsock module: %s"),
+ errbuf);
+ return -1;
+ }
+ }
+
if ((fd = open(vsock_path, O_RDWR)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("unable to open vhost-vsock device"));
--
1.8.3.1
On Tue, Jul 28, 2020 at 12:58:07PM +0300, Nikolay Shirokovskiy wrote:
> /dev/vhost-vsock is usable only if the module is loaded. Let's load the module
> just like in other places where kernel module is required (nbd, pci stub
> driver).
Just a note, starting from Linux 4.13 (f4660cc994e1 ("vhost/vsock: use static
minor number")) the kernel module should be automatically loaded when an
application try to open /dev/vhost-vsock.
Did you find a case where that doesn't happen?
Thanks,
Stefano
>
> Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
> ---
> src/qemu/qemu_process.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index ec6ca14..5aaa77c 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -92,6 +92,7 @@
> #include "viridentity.h"
> #include "virthreadjob.h"
> #include "virutil.h"
> +#include "virkmod.h"
>
> #define VIR_FROM_THIS VIR_FROM_QEMU
>
> @@ -6414,6 +6415,7 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr driver,
> return 0;
> }
>
> +#define VHOST_VSOCK_MODULE "vhost-vsock"
>
> int
> qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock)
> @@ -6422,6 +6424,22 @@ qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock)
> const char *vsock_path = "/dev/vhost-vsock";
> int fd;
>
> + if (virKModIsProhibited(VHOST_VSOCK_MODULE)) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("Failed to load vhost-vsock module: "
> + "administratively prohibited"));
> + return -1;
> + } else {
> + g_autofree char *errbuf = NULL;
> +
> + if ((errbuf = virKModLoad(VHOST_VSOCK_MODULE))) {
> + virReportError(VIR_ERR_INTERNAL_ERROR,
> + _("Failed to load vhost-vsock module: %s"),
> + errbuf);
> + return -1;
> + }
> + }
> +
> if ((fd = open(vsock_path, O_RDWR)) < 0) {
> virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> "%s", _("unable to open vhost-vsock device"));
> --
> 1.8.3.1
>
On 28.07.2020 13:12, Stefano Garzarella wrote:
> On Tue, Jul 28, 2020 at 12:58:07PM +0300, Nikolay Shirokovskiy wrote:
>> /dev/vhost-vsock is usable only if the module is loaded. Let's load the module
>> just like in other places where kernel module is required (nbd, pci stub
>> driver).
>
> Just a note, starting from Linux 4.13 (f4660cc994e1 ("vhost/vsock: use static
> minor number")) the kernel module should be automatically loaded when an
> application try to open /dev/vhost-vsock.
>
> Did you find a case where that doesn't happen?
>
Nope, it is just older kernel.
Nikolay
>
>>
>> Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
>> ---
>> src/qemu/qemu_process.c | 18 ++++++++++++++++++
>> 1 file changed, 18 insertions(+)
>>
>> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
>> index ec6ca14..5aaa77c 100644
>> --- a/src/qemu/qemu_process.c
>> +++ b/src/qemu/qemu_process.c
>> @@ -92,6 +92,7 @@
>> #include "viridentity.h"
>> #include "virthreadjob.h"
>> #include "virutil.h"
>> +#include "virkmod.h"
>>
>> #define VIR_FROM_THIS VIR_FROM_QEMU
>>
>> @@ -6414,6 +6415,7 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr driver,
>> return 0;
>> }
>>
>> +#define VHOST_VSOCK_MODULE "vhost-vsock"
>>
>> int
>> qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock)
>> @@ -6422,6 +6424,22 @@ qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock)
>> const char *vsock_path = "/dev/vhost-vsock";
>> int fd;
>>
>> + if (virKModIsProhibited(VHOST_VSOCK_MODULE)) {
>> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
>> + _("Failed to load vhost-vsock module: "
>> + "administratively prohibited"));
>> + return -1;
>> + } else {
>> + g_autofree char *errbuf = NULL;
>> +
>> + if ((errbuf = virKModLoad(VHOST_VSOCK_MODULE))) {
>> + virReportError(VIR_ERR_INTERNAL_ERROR,
>> + _("Failed to load vhost-vsock module: %s"),
>> + errbuf);
>> + return -1;
>> + }
>> + }
>> +
>> if ((fd = open(vsock_path, O_RDWR)) < 0) {
>> virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>> "%s", _("unable to open vhost-vsock device"));
>> --
>> 1.8.3.1
>>
>
© 2016 - 2026 Red Hat, Inc.