From nobody Wed Aug 28 19:12:42 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WvDZL444Tz5MZRJ; Wed, 28 Aug 2024 19:12:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WvDZL36YZz4ppv; Wed, 28 Aug 2024 19:12:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724872362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rXzwUJ3B073p+5XdpZL7rBXbR3gV3vMdQ2n+lfhRooY=; b=Vi2rCi9BUbmC7pa2NMNVpGgohnkDY3wnIaA1wXwONoluBUzfZPCjezBS1lhcjztYJq+v+e 16oHX3MhBeqk5NyA6OeQHEAdcucU5ozQEd6aXipFCo0Gy9hR0pdvNbuxm28QsI91r60lBL VXmlaIm7x7+WxySt8wlv4UygXCq+6oCOdEWCA9Vsfg1dg/oKLXZaGS7x5YdprFmtzVZulr NJk6HZrM798MMoacJem2n2teiFqfeYMjYrHKNCf3Or1zvXwbcBMUVQ3GtguvGVqCtmtpp8 9WPC4xdXNwNgTb0EyElHNU5ajksNM//m9GwzYscTPv9JQr9ey0UlsAx/OHmleA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724872362; a=rsa-sha256; cv=none; b=vsYeijW5pBf1XcrRvldJsSJVho0y3Hw0clg3w0+8Ts39hhxuyDtaNUJuPz07joQii79xBq L0mCdEVtpde/u9/dfw7rYO0nhDv2yBdwndzbaDY3lTGVgBXgbRW91OkdFnviiQ2IsYBbsp JUDr7ABJDcyOaEV6dWjiuN0NL14q1LNJ3D+p5jsAk3/k4ReXboqyBZMvKdCdQogFJ3xNae MHBtEEahd7IHG944ni3WU7BLsT3YPwIQoHj9+oOIjdl9I0qCSm0toGboG/tlwJ7tM5IL35 6k6Y0nKAouMmsjpXBdZdjiBnAOxIi0MtVTkNdq0Y12oIL81/i7A9QtljVeyWXQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724872362; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rXzwUJ3B073p+5XdpZL7rBXbR3gV3vMdQ2n+lfhRooY=; b=SRuj7bIZ18mmojE/q9yBliCHvCmJ2cJYsTxV8HeAXuhIsDUDOFnzf2LFbXwfREjwBuL8f5 WHt3sU3LrNx0dd0/Azz8YYtGpD8rd4tDfobpq1Vj6RKeaR67JjuI1QmKQCjFdnBqsfz0I+ Kd4ZH9FiPzLRS/GMzHVnD/Se/9bHFYTwLtXm2h3ILP7WJGTbY6QF8qfazkAr3gsYaPOrxV ht7bFgP950IJ4rqOtoCznLWmM7HkRyBUwXMc7vHNN6/Ua15kGj/Zd/g5ynbr48OWHLMOUP BDVuGqGq9sA/XVJsL/3o/H2OJP5b1JrTCwj/AGO8Q4YdS0R62yJYwTx5gz71jg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WvDZL2jM6zldM; Wed, 28 Aug 2024 19:12:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47SJCgDw058950; Wed, 28 Aug 2024 19:12:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47SJCgfx058947; Wed, 28 Aug 2024 19:12:42 GMT (envelope-from git) Date: Wed, 28 Aug 2024 19:12:42 GMT Message-Id: <202408281912.47SJCgfx058947@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: d58197097610 - main - vmm: Factor most of sysctl_vmm_create() out into a separate function List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d581970976101e1bcbfc23823b97696b172f118c Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d581970976101e1bcbfc23823b97696b172f118c commit d581970976101e1bcbfc23823b97696b172f118c Author: Mark Johnston AuthorDate: 2024-08-28 18:57:03 +0000 Commit: Mark Johnston CommitDate: 2024-08-28 18:57:03 +0000 vmm: Factor most of sysctl_vmm_create() out into a separate function This will make it easy to share code with an ioctl handler which creates VMs. No functional change intended. Reviewed by: corvink, jhb Differential Revision: https://reviews.freebsd.org/D46444 --- sys/dev/vmm/vmm_dev.c | 86 ++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/sys/dev/vmm/vmm_dev.c b/sys/dev/vmm/vmm_dev.c index db3e2c992f3b..94546efd03c9 100644 --- a/sys/dev/vmm/vmm_dev.c +++ b/sys/dev/vmm/vmm_dev.c @@ -838,66 +838,58 @@ static struct cdevsw vmmdevsw = { .d_write = vmmdev_rw, }; +static struct vmmdev_softc * +vmmdev_alloc(struct vm *vm, struct ucred *cred) +{ + struct vmmdev_softc *sc; + + sc = malloc(sizeof(*sc), M_VMMDEV, M_WAITOK | M_ZERO); + SLIST_INIT(&sc->devmem); + sc->vm = vm; + sc->ucred = crhold(cred); + return (sc); +} + static int -sysctl_vmm_create(SYSCTL_HANDLER_ARGS) +vmmdev_create(const char *name, struct ucred *cred) { - struct vm *vm; struct cdev *cdev; struct vmmdev_softc *sc, *sc2; - char *buf; - int error, buflen; - - error = vmm_priv_check(req->td->td_ucred); - if (error) - return (error); - - buflen = VM_MAX_NAMELEN + 1; - buf = malloc(buflen, M_VMMDEV, M_WAITOK | M_ZERO); - strlcpy(buf, "beavis", buflen); - error = sysctl_handle_string(oidp, buf, buflen, req); - if (error != 0 || req->newptr == NULL) - goto out; + struct vm *vm; + int error; mtx_lock(&vmmdev_mtx); - sc = vmmdev_lookup(buf); + sc = vmmdev_lookup(name); mtx_unlock(&vmmdev_mtx); - if (sc != NULL) { - error = EEXIST; - goto out; - } + if (sc != NULL) + return (EEXIST); - error = vm_create(buf, &vm); + error = vm_create(name, &vm); if (error != 0) - goto out; + return (error); - sc = malloc(sizeof(struct vmmdev_softc), M_VMMDEV, M_WAITOK | M_ZERO); - sc->ucred = crhold(curthread->td_ucred); - sc->vm = vm; - SLIST_INIT(&sc->devmem); + sc = vmmdev_alloc(vm, cred); /* * Lookup the name again just in case somebody sneaked in when we * dropped the lock. */ mtx_lock(&vmmdev_mtx); - sc2 = vmmdev_lookup(buf); - if (sc2 == NULL) { - SLIST_INSERT_HEAD(&head, sc, link); - sc->flags |= VSC_LINKED; - } - mtx_unlock(&vmmdev_mtx); - + sc2 = vmmdev_lookup(name); if (sc2 != NULL) { + mtx_unlock(&vmmdev_mtx); vmmdev_destroy(sc); - error = EEXIST; - goto out; + return (EEXIST); } + sc->flags |= VSC_LINKED; + SLIST_INSERT_HEAD(&head, sc, link); + mtx_unlock(&vmmdev_mtx); error = make_dev_p(MAKEDEV_CHECKNAME, &cdev, &vmmdevsw, sc->ucred, - UID_ROOT, GID_WHEEL, 0600, "vmm/%s", buf); + UID_ROOT, GID_WHEEL, 0600, "vmm/%s", name); if (error != 0) { vmmdev_destroy(sc); - goto out; + return (error); } mtx_lock(&vmmdev_mtx); @@ -905,7 +897,25 @@ sysctl_vmm_create(SYSCTL_HANDLER_ARGS) sc->cdev->si_drv1 = sc; mtx_unlock(&vmmdev_mtx); -out: + return (0); +} + +static int +sysctl_vmm_create(SYSCTL_HANDLER_ARGS) +{ + char *buf; + int error, buflen; + + error = vmm_priv_check(req->td->td_ucred); + if (error != 0) + return (error); + + buflen = VM_MAX_NAMELEN + 1; + buf = malloc(buflen, M_VMMDEV, M_WAITOK | M_ZERO); + strlcpy(buf, "beavis", buflen); + error = sysctl_handle_string(oidp, buf, buflen, req); + if (error == 0 && req->newptr != NULL) + error = vmmdev_create(buf, req->td->td_ucred); free(buf, M_VMMDEV); return (error); }