tests/qemuxml2argvmock.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
The code is trying to open /dev/vhost-net from the host machine and if the
current user has access to it, the command line will end up having two more
options for an interface (,vhost=on,vhostfd=X where X is next free file
descriptor).
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
tests/qemuxml2argvmock.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c
index 177b24e0a953..11626e2794c1 100644
--- a/tests/qemuxml2argvmock.c
+++ b/tests/qemuxml2argvmock.c
@@ -20,6 +20,10 @@
#include <config.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#include "internal.h"
#include "viralloc.h"
#include "vircommand.h"
@@ -188,3 +192,35 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path ATTRIBUTE_UNUSED,
{
return VIR_STRDUP(*ifname, "vhost-user0");
}
+
+static int (*real_open)(const char *path, int flags, ...);
+
+static void init_syms(void)
+{
+ if (real_open)
+ return;
+
+ VIR_MOCK_REAL_INIT(open);
+}
+
+int open(const char *path, int flags, ...)
+{
+ va_list ap;
+ mode_t mode = 0;
+
+ init_syms();
+
+ if (STREQ(path, "/dev/vhost-net"))
+ return -1;
+
+ /* The mode argument is mandatory when O_CREAT is set in flags,
+ * otherwise the argument is ignored.
+ */
+ if (flags & O_CREAT) {
+ va_start(ap, flags);
+ mode = (mode_t) va_arg(ap, int);
+ va_end(ap);
+ }
+
+ return real_open(path, flags, mode);
+}
--
2.17.0
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Tue, Apr 17, 2018 at 11:30:06 +0200, Martin Kletzander wrote: > The code is trying to open /dev/vhost-net from the host machine and if the > current user has access to it, the command line will end up having two more > options for an interface (,vhost=on,vhostfd=X where X is next free file > descriptor). > > Signed-off-by: Martin Kletzander <mkletzan@redhat.com> > --- > tests/qemuxml2argvmock.c | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) Reviewed-by: Jiri Denemark <jdenemar@redhat.com> -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
On Tue, Apr 17, 2018 at 11:52:00AM +0200, Jiri Denemark wrote: >On Tue, Apr 17, 2018 at 11:30:06 +0200, Martin Kletzander wrote: >> The code is trying to open /dev/vhost-net from the host machine and if the >> current user has access to it, the command line will end up having two more >> options for an interface (,vhost=on,vhostfd=X where X is next free file >> descriptor). >> >> Signed-off-by: Martin Kletzander <mkletzan@redhat.com> >> --- >> tests/qemuxml2argvmock.c | 36 ++++++++++++++++++++++++++++++++++++ >> 1 file changed, 36 insertions(+) > >Reviewed-by: Jiri Denemark <jdenemar@redhat.com> I'll leave Jano push his.-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
On Tue, Apr 17, 2018 at 11:30:06AM +0200, Martin Kletzander wrote: >The code is trying to open /dev/vhost-net from the host machine and if the >current user has access to it, the command line will end up having two more >options for an interface (,vhost=on,vhostfd=X where X is next free file >descriptor). > Alternate proposal which mocks qemuInterfaceOpenVhostNet instead of doing this per-path: https://www.redhat.com/archives/libvir-list/2018-April/msg01433.html (Even if we start testing the custom path to the vhost-net device, we don't want to access the host) Jano >Signed-off-by: Martin Kletzander <mkletzan@redhat.com> >--- > tests/qemuxml2argvmock.c | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
On Tue, Apr 17, 2018 at 12:44:13PM +0200, Ján Tomko wrote: >On Tue, Apr 17, 2018 at 11:30:06AM +0200, Martin Kletzander wrote: >>The code is trying to open /dev/vhost-net from the host machine and if the >>current user has access to it, the command line will end up having two more >>options for an interface (,vhost=on,vhostfd=X where X is next free file >>descriptor). >> > >Alternate proposal which mocks qemuInterfaceOpenVhostNet instead of >doing this per-path: >https://www.redhat.com/archives/libvir-list/2018-April/msg01433.html >(Even if we start testing the custom path to the vhost-net device, >we don't want to access the host) > Sure, I've no preference. >Jano > >>Signed-off-by: Martin Kletzander <mkletzan@redhat.com> >>--- >> tests/qemuxml2argvmock.c | 36 ++++++++++++++++++++++++++++++++++++ >> 1 file changed, 36 insertions(+) >> -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2025 Red Hat, Inc.