mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-31 18:33:11 +00:00
f1704e61c3
There is duplicated code between virt drivers that needs to be moved to avoid code repetition. In the case of duplicated code between lxc_cgroup.c and qemu_cgroup.c a common place would be utils/vircgroup.c. The problem is that this would introduce /conf related definitions that shouldn't be imported to vircgroup.c, which is supposed to be a place for utilitary cgroups functions only. And syntax-check would forbid it anyway due to cross-directory includes being used. An alternative would be to overload domain_conf.c, which already contains all the definitions required. But that file is already crowded with XML handling code and we wouldn't do any favors to it by putting more utilitary, non-XML parsing/formatting code there. In [1], Cole suggested a 'domain_cgroup' file to host common code between lxc_cgroup and qemu_cgroup, and Daniel suggested a 'src/hypervisor' dir to host these type of files. This patch introduces src/hypervisor/domain_cgroup.c and, to get started, introduces a new virDomainCgroupSetupBlkio() function to host shared code between virLXCCgroupSetupBlkioTune() and qemuSetupBlkioCgroup(). [1] https://www.redhat.com/archives/libvir-list/2019-December/msg00817.html Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
68 lines
2.1 KiB
C
68 lines
2.1 KiB
C
/*
|
|
* domain_cgroup.c: cgroup functions shared between hypervisor drivers
|
|
*
|
|
* Copyright IBM Corp. 2020
|
|
*
|
|
* 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/>.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "domain_cgroup.h"
|
|
|
|
|
|
int
|
|
virDomainCgroupSetupBlkio(virCgroupPtr cgroup, virDomainBlkiotune blkio)
|
|
{
|
|
size_t i;
|
|
|
|
if (blkio.weight != 0 &&
|
|
virCgroupSetBlkioWeight(cgroup, blkio.weight) < 0)
|
|
return -1;
|
|
|
|
if (blkio.ndevices) {
|
|
for (i = 0; i < blkio.ndevices; i++) {
|
|
virBlkioDevicePtr dev = &blkio.devices[i];
|
|
|
|
if (dev->weight &&
|
|
virCgroupSetupBlkioDeviceWeight(cgroup, dev->path,
|
|
&dev->weight) < 0)
|
|
return -1;
|
|
|
|
if (dev->riops &&
|
|
virCgroupSetupBlkioDeviceReadIops(cgroup, dev->path,
|
|
&dev->riops) < 0)
|
|
return -1;
|
|
|
|
if (dev->wiops &&
|
|
virCgroupSetupBlkioDeviceWriteIops(cgroup, dev->path,
|
|
&dev->wiops) < 0)
|
|
return -1;
|
|
|
|
if (dev->rbps &&
|
|
virCgroupSetupBlkioDeviceReadBps(cgroup, dev->path,
|
|
&dev->rbps) < 0)
|
|
return -1;
|
|
|
|
if (dev->wbps &&
|
|
virCgroupSetupBlkioDeviceWriteBps(cgroup, dev->path,
|
|
&dev->wbps) < 0)
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|