MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sysctl_vmm_create

Function sysctl_vmm_create

freebsd/amd64/vmm/vmm_dev.c:1054–1123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1052};
1053
1054static int
1055sysctl_vmm_create(SYSCTL_HANDLER_ARGS)
1056{
1057 struct vm *vm;
1058 struct cdev *cdev;
1059 struct vmmdev_softc *sc, *sc2;
1060 char *buf;
1061 int error, buflen;
1062
1063 error = vmm_priv_check(req->td->td_ucred);
1064 if (error)
1065 return (error);
1066
1067 buflen = VM_MAX_NAMELEN + 1;
1068 buf = malloc(buflen, M_VMMDEV, M_WAITOK | M_ZERO);
1069 strlcpy(buf, "beavis", buflen);
1070 error = sysctl_handle_string(oidp, buf, buflen, req);
1071 if (error != 0 || req->newptr == NULL)
1072 goto out;
1073
1074 mtx_lock(&vmmdev_mtx);
1075 sc = vmmdev_lookup(buf);
1076 mtx_unlock(&vmmdev_mtx);
1077 if (sc != NULL) {
1078 error = EEXIST;
1079 goto out;
1080 }
1081
1082 error = vm_create(buf, &vm);
1083 if (error != 0)
1084 goto out;
1085
1086 sc = malloc(sizeof(struct vmmdev_softc), M_VMMDEV, M_WAITOK | M_ZERO);
1087 sc->vm = vm;
1088 SLIST_INIT(&sc->devmem);
1089
1090 /*
1091 * Lookup the name again just in case somebody sneaked in when we
1092 * dropped the lock.
1093 */
1094 mtx_lock(&vmmdev_mtx);
1095 sc2 = vmmdev_lookup(buf);
1096 if (sc2 == NULL) {
1097 SLIST_INSERT_HEAD(&head, sc, link);
1098 sc->flags |= VSC_LINKED;
1099 }
1100 mtx_unlock(&vmmdev_mtx);
1101
1102 if (sc2 != NULL) {
1103 vmmdev_destroy(sc);
1104 error = EEXIST;
1105 goto out;
1106 }
1107
1108 error = make_dev_p(MAKEDEV_CHECKNAME, &cdev, &vmmdevsw, NULL,
1109 UID_ROOT, GID_WHEEL, 0600, "vmm/%s", buf);
1110 if (error != 0) {
1111 vmmdev_destroy(sc);

Callers

nothing calls this directly

Calls 10

mallocFunction · 0.85
sysctl_handle_stringFunction · 0.85
vmmdev_lookupFunction · 0.85
vm_createFunction · 0.85
vmmdev_destroyFunction · 0.85
make_dev_pFunction · 0.85
strlcpyFunction · 0.50
mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected