Factor out all rctl(8) execution code to bhyve_rctl.c.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
#include "bhyve_firmware.h"
#include "bhyve_monitor.h"
#include "bhyve_process.h"
+#include "bhyve_rctl.h"
#include "datatypes.h"
#include "virerror.h"
#include "virhook.h"
#include "virlog.h"
#include "virfile.h"
#include "viralloc.h"
-#include "vircommand.h"
#include "virstring.h"
#include "virpidfile.h"
#include "virprocess.h"
return -1;
}
-#define BHYVE_APPLY_RCTL_RULE(field, type, action, format) \
- do { \
- if ((field)) { \
- g_autofree char *rule = NULL; \
- g_autoptr(virCommand) cmd = virCommandNewArgList("rctl", "-a", NULL); \
- virCommandAddArgFormat(cmd, "process:%d:" type ":" action "=" format, \
- vm->pid, (field)); \
- if (virCommandRun(cmd, NULL) < 0) \
- return -1; \
- } \
- } while (0)
-
if (vm->def->blkio.ndevices == 1) {
device = &vm->def->blkio.devices[0];
- BHYVE_APPLY_RCTL_RULE(device->riops, "readiops", "throttle", "%u");
- BHYVE_APPLY_RCTL_RULE(device->wiops, "writeiops", "throttle", "%u");
- BHYVE_APPLY_RCTL_RULE(device->rbps, "readbps", "throttle", "%llu");
- BHYVE_APPLY_RCTL_RULE(device->wbps, "writebps", "throttle", "%llu");
+ bhyveRctlSetIoLimits(vm->pid, device);
}
/* rctl(8) uses bytes for these values and def->mem.* uses kibibytes */
if (virMemoryLimitIsSet(vm->def->mem.hard_limit))
- BHYVE_APPLY_RCTL_RULE(vm->def->mem.hard_limit * 1024, "memoryuse", "deny", "%llu");
-
-#undef BHYVE_APPLY_RCTL_RULE
+ if (bhyveRctlSetMemoryHardLimit(vm->pid, vm->def->mem.hard_limit) < 0)
+ return -1;
return 0;
}
return -1;
}
+
+#define BHYVE_APPLY_RCTL_RULE(pid, field, type, action, format) \
+ do { \
+ if ((field)) { \
+ g_autofree char *rule = NULL; \
+ g_autoptr(virCommand) cmd = virCommandNewArgList("rctl", "-a", NULL); \
+ virCommandAddArgFormat(cmd, "process:%d:" type ":" action "=" format, \
+ pid, (field)); \
+ if (virCommandRun(cmd, NULL) < 0) \
+ return -1; \
+ } \
+ } while (0)
+
+int
+bhyveRctlSetMemoryHardLimit(pid_t pid, unsigned long long kb)
+{
+ /* rctl(8) uses bytes for these values and def->mem.* uses kibibytes */
+ BHYVE_APPLY_RCTL_RULE(pid, kb * 1024, "memoryuse", "deny", "%llu");
+
+ return 0;
+}
+
+int
+bhyveRctlSetIoLimits(pid_t pid, const virBlkioDevice *device)
+{
+ BHYVE_APPLY_RCTL_RULE(pid, device->riops, "readiops", "throttle", "%u");
+ BHYVE_APPLY_RCTL_RULE(pid, device->wiops, "writeiops", "throttle", "%u");
+ BHYVE_APPLY_RCTL_RULE(pid, device->rbps, "readbps", "throttle", "%llu");
+ BHYVE_APPLY_RCTL_RULE(pid, device->wbps, "writebps", "throttle", "%llu");
+
+ return 0;
+}
+
+#undef BHYVE_APPLY_RCTL_RULE
#pragma once
+#include "domain_conf.h"
+
int
bhyveRctlGetMemoryHardLimit(pid_t pid, unsigned long long *kb);
+
+int
+bhyveRctlSetMemoryHardLimit(pid_t pid, unsigned long long kb);
+
+int
+bhyveRctlSetIoLimits(pid_t pid, const virBlkioDevice *device);