[libvirt] [PATCHv3 0/2] network: bandwidth tuning in session mode revert patch

Erik Skultety (2): qemu: revert patch - bandwidth tuning in session mode Iface: disallow network tuning in session mode globally src/qemu/qemu_command.c | 11 ----------- src/qemu/qemu_driver.c | 9 --------- src/util/virnetdevbandwidth.c | 8 ++++++++ tests/Makefile.am | 26 +++++++++++++++++++------- tests/virnetdevbandwidthmock.c | 28 ++++++++++++++++++++++++++++ tests/virnetdevbandwidthtest.c | 2 +- 6 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 tests/virnetdevbandwidthmock.c -- 1.9.3

Since there was a valid note to patch 43b67f2e about the best spot to check for bandwidth set call while having libvirt daemon run in session mode, this patch reverts previous changes dealing with bandwith (also reverts adding variable @cfg in qemuDomainGetNumaParameters which does not have any use at the moment, but getting and unreferencing driver's config) in qemu_driver.c and qemu_command.c. There will be another patch in the series which introduces the fix itself. --- src/qemu/qemu_command.c | 11 ----------- src/qemu/qemu_driver.c | 9 --------- 2 files changed, 20 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 917639e..956bb14 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7841,17 +7841,6 @@ qemuBuildCommandLine(virConnectPtr conn, _("CPU tuning is not available in session mode")); goto error; } - - virDomainNetDefPtr *nets = def->nets; - virNetDevBandwidthPtr bandwidth = NULL; - size_t nnets = def->nnets; - for (i = 0; i < nnets; i++) { - if ((bandwidth = virDomainNetGetActualBandwidth(nets[i])) != NULL) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Network bandwidth tuning is not available in session mode")); - goto error; - } - } } for (i = 0; i < def->ngraphics; ++i) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6acaea8..edd82c1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9383,7 +9383,6 @@ qemuDomainGetNumaParameters(virDomainPtr dom, size_t i; virDomainObjPtr vm = NULL; virDomainDefPtr persistentDef = NULL; - virQEMUDriverConfigPtr cfg = NULL; char *nodeset = NULL; int ret = -1; virCapsPtr caps = NULL; @@ -9402,7 +9401,6 @@ qemuDomainGetNumaParameters(virDomainPtr dom, return -1; priv = vm->privateData; - cfg = virQEMUDriverGetConfig(driver); if (virDomainGetNumaParametersEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -9476,7 +9474,6 @@ qemuDomainGetNumaParameters(virDomainPtr dom, if (vm) virObjectUnlock(vm); virObjectUnref(caps); - virObjectUnref(cfg); return ret; } @@ -10447,12 +10444,6 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, if (virDomainSetInterfaceParametersEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup; - if (!cfg->privileged) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("Network bandwidth tuning is not available in session mode")); - goto cleanup; - } - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; -- 1.9.3

Patch 43b67f2e disallowed network tuning only with qemu driver, however this patch moved the check for root privileges into virNetDevBandwidthSet function, so the call should now fail in all possible cases. A mock function was created so that the test suite doesn't fail because of unsufficient privileges. --- src/util/virnetdevbandwidth.c | 8 ++++++++ tests/Makefile.am | 26 +++++++++++++++++++------- tests/virnetdevbandwidthmock.c | 28 ++++++++++++++++++++++++++++ tests/virnetdevbandwidthtest.c | 2 +- 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 tests/virnetdevbandwidthmock.c diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 5fa231a..9f2a159 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -21,6 +21,7 @@ */ #include <config.h> +#include <unistd.h> #include "virnetdevbandwidth.h" #include "vircommand.h" @@ -74,6 +75,13 @@ virNetDevBandwidthSet(const char *ifname, goto cleanup; } + if (geteuid() != 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("Network bandwidth tuning is not available" + " in session mode")); + return -1; + } + virNetDevBandwidthClear(ifname); if (bandwidth->in && bandwidth->in->average) { diff --git a/tests/Makefile.am b/tests/Makefile.am index 7b22f90..a3e3ab3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -167,7 +167,6 @@ test_programs = virshtest sockettest \ virstringtest \ virportallocatortest \ sysinfotest \ - virnetdevbandwidthtest \ virkmodtest \ vircapstest \ domaincapstest \ @@ -318,7 +317,9 @@ test_programs += metadatatest test_programs += secretxml2xmltest if WITH_LINUX -test_programs += virusbtest +test_programs += virusbtest \ + virnetdevbandwidthtest \ + $(NULL) endif WITH_LINUX test_scripts = \ @@ -409,7 +410,9 @@ test_libraries += \ endif WITH_DBUS if WITH_LINUX -test_libraries += virusbmock.la +test_libraries += virusbmock.la \ + virnetdevbandwidthmock.la \ + $(NULL) endif WITH_LINUX if WITH_TESTS @@ -825,9 +828,6 @@ commandhelper_LDADD = \ commandhelper_LDFLAGS = -static -virnetdevbandwidthtest_SOURCES = \ - virnetdevbandwidthtest.c testutils.h testutils.c -virnetdevbandwidthtest_LDADD = $(LDADDS) $(LIBXML_LIBS) virkmodtest_SOURCES = \ virkmodtest.c testutils.h testutils.c @@ -994,12 +994,24 @@ virusbtest_SOURCES = \ virusbtest.c testutils.h testutils.c virusbtest_LDADD = $(LDADDS) +virnetdevbandwidthtest_SOURCES = \ + virnetdevbandwidthtest.c testutils.h testutils.c +virnetdevbandwidthtest_LDADD = $(LDADDS) $(LIBXML_LIBS) + virusbmock_la_SOURCES = virusbmock.c virusbmock_la_CFLAGS = $(AM_CFLAGS) virusbmock_la_LDFLAGS = -module -avoid-version \ -rpath /evil/libtool/hack/to/force/shared/lib/creation + +virnetdevbandwidthmock_la_SOURCES = \ + virnetdevbandwidthmock.c +virnetdevbandwidthmock_la_CFLAGS = $(AM_CFLAGS) +virnetdevbandwidthmock_la_LDFLAGS = -module -avoid-version \ + -rpath /evil/libtool/hack/to/force/shared/lib/creation + else ! WITH_LINUX - EXTRA_DIST += virusbtest.c virusbmock.c + EXTRA_DIST += virusbtest.c virusbmock.c \ + virnetdevbandwidthtest.c virnetdevbandwidthmock.c endif ! WITH_LINUX if WITH_DBUS diff --git a/tests/virnetdevbandwidthmock.c b/tests/virnetdevbandwidthmock.c new file mode 100644 index 0000000..e8edead --- /dev/null +++ b/tests/virnetdevbandwidthmock.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2013 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Erik Skultety <eskultet@redhat.com> + */ + +#include <config.h> +#include <unistd.h> +#include <sys/types.h> + +uid_t geteuid(void) +{ + return 0; +} diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c index 384991e..cd24442 100644 --- a/tests/virnetdevbandwidthtest.c +++ b/tests/virnetdevbandwidthtest.c @@ -167,4 +167,4 @@ mymain(void) return ret; } -VIRT_TEST_MAIN(mymain); +VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virnetdevbandwidthmock.so") -- 1.9.3

On 06.11.2014 12:38, Erik Skultety wrote:
Patch 43b67f2e disallowed network tuning only with qemu driver, however this patch moved the check for root privileges into virNetDevBandwidthSet function, so the call should now fail in all possible cases. A mock function was created so that the test suite doesn't fail because of unsufficient privileges. --- src/util/virnetdevbandwidth.c | 8 ++++++++ tests/Makefile.am | 26 +++++++++++++++++++------- tests/virnetdevbandwidthmock.c | 28 ++++++++++++++++++++++++++++ tests/virnetdevbandwidthtest.c | 2 +- 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 tests/virnetdevbandwidthmock.c
diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 5fa231a..9f2a159 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -21,6 +21,7 @@ */
#include <config.h> +#include <unistd.h>
#include "virnetdevbandwidth.h" #include "vircommand.h" @@ -74,6 +75,13 @@ virNetDevBandwidthSet(const char *ifname, goto cleanup; }
+ if (geteuid() != 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("Network bandwidth tuning is not available" + " in session mode")); + return -1; + } +
I wonder if we should have the same check in virNetDevBandwidthClear() since it's often used in pair with Set() and in fact it's called before the Set() function.
virNetDevBandwidthClear(ifname);
if (bandwidth->in && bandwidth->in->average) { diff --git a/tests/Makefile.am b/tests/Makefile.am index 7b22f90..a3e3ab3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -167,7 +167,6 @@ test_programs = virshtest sockettest \ virstringtest \ virportallocatortest \ sysinfotest \ - virnetdevbandwidthtest \ virkmodtest \ vircapstest \ domaincapstest \ @@ -318,7 +317,9 @@ test_programs += metadatatest test_programs += secretxml2xmltest
if WITH_LINUX -test_programs += virusbtest +test_programs += virusbtest \ + virnetdevbandwidthtest \ + $(NULL) endif WITH_LINUX
test_scripts = \ @@ -409,7 +410,9 @@ test_libraries += \ endif WITH_DBUS
if WITH_LINUX -test_libraries += virusbmock.la +test_libraries += virusbmock.la \ + virnetdevbandwidthmock.la \ + $(NULL) endif WITH_LINUX
if WITH_TESTS @@ -825,9 +828,6 @@ commandhelper_LDADD = \
commandhelper_LDFLAGS = -static
-virnetdevbandwidthtest_SOURCES = \ - virnetdevbandwidthtest.c testutils.h testutils.c -virnetdevbandwidthtest_LDADD = $(LDADDS) $(LIBXML_LIBS)
virkmodtest_SOURCES = \ virkmodtest.c testutils.h testutils.c @@ -994,12 +994,24 @@ virusbtest_SOURCES = \ virusbtest.c testutils.h testutils.c virusbtest_LDADD = $(LDADDS)
+virnetdevbandwidthtest_SOURCES = \ + virnetdevbandwidthtest.c testutils.h testutils.c +virnetdevbandwidthtest_LDADD = $(LDADDS) $(LIBXML_LIBS) + virusbmock_la_SOURCES = virusbmock.c virusbmock_la_CFLAGS = $(AM_CFLAGS) virusbmock_la_LDFLAGS = -module -avoid-version \ -rpath /evil/libtool/hack/to/force/shared/lib/creation + +virnetdevbandwidthmock_la_SOURCES = \ + virnetdevbandwidthmock.c +virnetdevbandwidthmock_la_CFLAGS = $(AM_CFLAGS) +virnetdevbandwidthmock_la_LDFLAGS = -module -avoid-version \ + -rpath /evil/libtool/hack/to/force/shared/lib/creation + else ! WITH_LINUX - EXTRA_DIST += virusbtest.c virusbmock.c + EXTRA_DIST += virusbtest.c virusbmock.c \ + virnetdevbandwidthtest.c virnetdevbandwidthmock.c endif ! WITH_LINUX
if WITH_DBUS diff --git a/tests/virnetdevbandwidthmock.c b/tests/virnetdevbandwidthmock.c new file mode 100644 index 0000000..e8edead --- /dev/null +++ b/tests/virnetdevbandwidthmock.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2013 Red Hat, Inc.
Looking at calendar reveals it 2014 :-P
+ * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Erik Skultety <eskultet@redhat.com> + */ +
Michal

On 06.11.2014 12:38, Erik Skultety wrote:
Erik Skultety (2): qemu: revert patch - bandwidth tuning in session mode Iface: disallow network tuning in session mode globally
src/qemu/qemu_command.c | 11 ----------- src/qemu/qemu_driver.c | 9 --------- src/util/virnetdevbandwidth.c | 8 ++++++++ tests/Makefile.am | 26 +++++++++++++++++++------- tests/virnetdevbandwidthmock.c | 28 ++++++++++++++++++++++++++++ tests/virnetdevbandwidthtest.c | 2 +- 6 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 tests/virnetdevbandwidthmock.c
ACKed and pushed. Michal

On 11/06/2014 02:30 PM, Michal Privoznik wrote:
On 06.11.2014 12:38, Erik Skultety wrote:
Erik Skultety (2): qemu: revert patch - bandwidth tuning in session mode Iface: disallow network tuning in session mode globally
src/qemu/qemu_command.c | 11 ----------- src/qemu/qemu_driver.c | 9 --------- src/util/virnetdevbandwidth.c | 8 ++++++++ tests/Makefile.am | 26 +++++++++++++++++++------- tests/virnetdevbandwidthmock.c | 28 ++++++++++++++++++++++++++++ tests/virnetdevbandwidthtest.c | 2 +- 6 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 tests/virnetdevbandwidthmock.c
ACKed and pushed.
Michal
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list Thanks, Michal.
participants (2)
-
Erik Skultety
-
Michal Privoznik