[libvirt] [PATCH] tests: Don't touch /dev/vhost-net in qemuxml2argvtest

Martin Kletzander posted 1 patch 6 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/c67aca00a2066d254d8a01e468d6c29601a4485e.1523957406.git.mkletzan@redhat.com
Test syntax-check passed
tests/qemuxml2argvmock.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
[libvirt] [PATCH] tests: Don't touch /dev/vhost-net in qemuxml2argvtest
Posted by Martin Kletzander 6 years ago
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
Re: [libvirt] [PATCH] tests: Don't touch /dev/vhost-net in qemuxml2argvtest
Posted by Jiri Denemark 6 years ago
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
Re: [libvirt] [PATCH] tests: Don't touch /dev/vhost-net in qemuxml2argvtest
Posted by Martin Kletzander 6 years ago
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
Re: [libvirt] [PATCH] tests: Don't touch /dev/vhost-net in qemuxml2argvtest
Posted by Ján Tomko 6 years ago
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
Re: [libvirt] [PATCH] tests: Don't touch /dev/vhost-net in qemuxml2argvtest
Posted by Martin Kletzander 6 years ago
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