summaryrefslogtreecommitdiff
path: root/usr.sbin/vmd/vmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/vmd/vmd.c')
-rw-r--r--usr.sbin/vmd/vmd.c113
1 files changed, 1 insertions, 112 deletions
diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c
index 2f3ac1a76f2..bd0d8580ffc 100644
--- a/usr.sbin/vmd/vmd.c
+++ b/usr.sbin/vmd/vmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmd.c,v 1.132 2022/09/13 10:28:19 martijn Exp $ */
+/* $OpenBSD: vmd.c,v 1.133 2022/10/31 14:02:11 dv Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -1188,9 +1188,6 @@ vm_stop(struct vmd_vm *vm, int keeptty, const char *caller)
vm->vm_state &= ~(VM_STATE_RECEIVED | VM_STATE_RUNNING
| VM_STATE_SHUTDOWN);
- user_inc(&vm->vm_params.vmc_params, vm->vm_user, 0);
- user_put(vm->vm_user);
-
if (vm->vm_iev.ibuf.fd != -1) {
event_del(&vm->vm_iev.ev);
close(vm->vm_iev.ibuf.fd);
@@ -1243,7 +1240,6 @@ vm_remove(struct vmd_vm *vm, const char *caller)
TAILQ_REMOVE(env->vmd_vms, vm, vm_entry);
- user_put(vm->vm_user);
vm_stop(vm, 0, caller);
free(vm);
}
@@ -1286,7 +1282,6 @@ vm_register(struct privsep *ps, struct vmop_create_params *vmc,
struct vmd_vm *vm = NULL, *vm_parent = NULL;
struct vm_create_params *vcp = &vmc->vmc_params;
struct vmop_owner *vmo = NULL;
- struct vmd_user *usr = NULL;
uint32_t nid, rng;
unsigned int i, j;
struct vmd_switch *sw;
@@ -1362,13 +1357,6 @@ vm_register(struct privsep *ps, struct vmop_create_params *vmc,
}
}
- /* track active users */
- if (uid != 0 && env->vmd_users != NULL &&
- (usr = user_get(uid)) == NULL) {
- log_warnx("could not add user");
- goto fail;
- }
-
if ((vm = calloc(1, sizeof(*vm))) == NULL)
goto fail;
@@ -1379,7 +1367,6 @@ vm_register(struct privsep *ps, struct vmop_create_params *vmc,
vm->vm_tty = -1;
vm->vm_receive_fd = -1;
vm->vm_state &= ~VM_STATE_PAUSED;
- vm->vm_user = usr;
for (i = 0; i < VMM_MAX_DISKS_PER_VM; i++)
for (j = 0; j < VM_MAX_BASE_PER_DISK; j++)
@@ -1903,104 +1890,6 @@ switch_getbyname(const char *name)
return (NULL);
}
-struct vmd_user *
-user_get(uid_t uid)
-{
- struct vmd_user *usr;
-
- if (uid == 0)
- return (NULL);
-
- /* first try to find an existing user */
- TAILQ_FOREACH(usr, env->vmd_users, usr_entry) {
- if (usr->usr_id.uid == uid)
- goto done;
- }
-
- if ((usr = calloc(1, sizeof(*usr))) == NULL) {
- log_warn("could not allocate user");
- return (NULL);
- }
-
- usr->usr_id.uid = uid;
- usr->usr_id.gid = -1;
- TAILQ_INSERT_TAIL(env->vmd_users, usr, usr_entry);
-
- done:
- DPRINTF("%s: uid %d #%d +",
- __func__, usr->usr_id.uid, usr->usr_refcnt + 1);
- usr->usr_refcnt++;
-
- return (usr);
-}
-
-void
-user_put(struct vmd_user *usr)
-{
- if (usr == NULL)
- return;
-
- DPRINTF("%s: uid %d #%d -",
- __func__, usr->usr_id.uid, usr->usr_refcnt - 1);
-
- if (--usr->usr_refcnt > 0)
- return;
-
- TAILQ_REMOVE(env->vmd_users, usr, usr_entry);
- free(usr);
-}
-
-void
-user_inc(struct vm_create_params *vcp, struct vmd_user *usr, int inc)
-{
- char mem[FMT_SCALED_STRSIZE];
-
- if (usr == NULL)
- return;
-
- /* increment or decrement counters */
- inc = inc ? 1 : -1;
-
- usr->usr_maxcpu += vcp->vcp_ncpus * inc;
- usr->usr_maxmem += vcp->vcp_memranges[0].vmr_size * inc;
- usr->usr_maxifs += vcp->vcp_nnics * inc;
-
- if (log_getverbose() > 1) {
- (void)fmt_scaled(usr->usr_maxmem * 1024 * 1024, mem);
- log_debug("%s: %c uid %d ref %d cpu %llu mem %s ifs %llu",
- __func__, inc == 1 ? '+' : '-',
- usr->usr_id.uid, usr->usr_refcnt,
- usr->usr_maxcpu, mem, usr->usr_maxifs);
- }
-}
-
-int
-user_checklimit(struct vmd_user *usr, struct vm_create_params *vcp)
-{
- const char *limit = "";
-
- /* XXX make the limits configurable */
- if (usr->usr_maxcpu > VM_DEFAULT_USER_MAXCPU) {
- limit = "cpu ";
- goto fail;
- }
- if (usr->usr_maxmem > VM_DEFAULT_USER_MAXMEM) {
- limit = "memory ";
- goto fail;
- }
- if (usr->usr_maxifs > VM_DEFAULT_USER_MAXIFS) {
- limit = "interface ";
- goto fail;
- }
-
- return (0);
-
- fail:
- log_warnx("%s: user %d %slimit reached", vcp->vcp_name,
- usr->usr_id.uid, limit);
- return (-1);
-}
-
char *
get_string(uint8_t *ptr, size_t len)
{