Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Nov 2011 18:33:54 +0100
From:      Ed Schouten <ed@80386.nl>
To:        Marco Steinbach <coco@executive-computing.de>
Cc:        Bernhard Froehlich <decke@FreeBSD.org>, Vladimir Kushnir <vkushnir@bigmir.net>, freebsd-ports <freebsd-ports@freebsd.org>
Subject:   Re: VirtualBox-kmod fails to build on -CURRENT
Message-ID:  <20111101173354.GW2258@hoeg.nl>
In-Reply-To: <alpine.BSF.2.00.1111011748170.4120@s560x.c0c0.intra>
References:  <alpine.BSF.2.00.1110261224240.14451@kushnir1.kiev.ua> <4EAE690D.1070609@executive-computing.de> <01c0ad0f006967454da602c2812981ce@bluelife.at> <20111031102602.GI2258@hoeg.nl> <20111031110711.GJ2258@hoeg.nl> <20111031111634.GK2258@hoeg.nl> <4EAE905A.9020901@executive-computing.de> <20111031121511.GL2258@hoeg.nl> <alpine.BSF.2.00.1111011748170.4120@s560x.c0c0.intra>

next in thread | previous in thread | raw e-mail | index | archive | help

--XaepPZQT0uxAV0NY
Content-Type: multipart/mixed; boundary="G9m07da55tKJni3T"
Content-Disposition: inline


--G9m07da55tKJni3T
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* Marco Steinbach <coco@executive-computing.de>, 20111101 18:18:
> You were right about the device naming, I had to create a symlink.

Okay. I've attached a new version of the patch that:

- Adds a symbolic link from /dev/vboxdrv0 to /dev/vboxdrv automatically,
- Changes the code to use /dev/vboxdrv.

This means the kernel module is backwards compatible, but VirtualBox
itself isn't. This is probably a good compromise.

I trust that the warnings and traces you are seeing are in no way
related to my patch, so I suppose you're better off reporting those to
the VirtualBox developers.

decke@, (or who else maintains VirtualBox), will you do the honour of
getting the patch upstreamed/applied locally? The patch probably has to
be used by both the virtualbox-ose and the virtualbox-ose-kmod port.
Thanks!

--=20
 Ed Schouten <ed@80386.nl>
 WWW: http://80386.nl/

--G9m07da55tKJni3T
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch-cdev-fixes
Content-Transfer-Encoding: quoted-printable

--- src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c
+++ src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c
@@ -69,10 +69,9 @@
 static int VBoxDrvFreeBSDModuleEvent(struct module *pMod, int enmEventType=
, void *pvArg);
 static int VBoxDrvFreeBSDLoad(void);
 static int VBoxDrvFreeBSDUnload(void);
-static void VBoxDrvFreeBSDClone(void *pvArg, struct ucred *pCred, char *pa=
chName, int cchName, struct cdev **ppDev);
=20
-static d_fdopen_t   VBoxDrvFreeBSDOpen;
-static d_close_t    VBoxDrvFreeBSDClose;
+static d_open_t     VBoxDrvFreeBSDOpen;
+static void         VBoxDrvFreeBSDDtr(void *pData);
 static d_ioctl_t    VBoxDrvFreeBSDIOCtl;
 static int          VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSession, u_lon=
g ulCmd, caddr_t pvData, struct thread *pTd);
=20
@@ -100,21 +99,13 @@
 static struct cdevsw        g_VBoxDrvFreeBSDChrDevSW =3D
 {
     .d_version =3D        D_VERSION,
-#if __FreeBSD_version > 800061
-    .d_flags =3D          D_PSEUDO | D_TRACKCLOSE | D_NEEDMINOR,
-#else
-    .d_flags =3D          D_PSEUDO | D_TRACKCLOSE,
-#endif
-    .d_fdopen =3D         VBoxDrvFreeBSDOpen,
-    .d_close =3D          VBoxDrvFreeBSDClose,
+    .d_open =3D           VBoxDrvFreeBSDOpen,
     .d_ioctl =3D          VBoxDrvFreeBSDIOCtl,
     .d_name =3D           "vboxdrv"
 };
=20
-/** List of cloned device. Managed by the kernel. */
-static struct clonedevs    *g_pVBoxDrvFreeBSDClones;
-/** The dev_clone event handler tag. */
-static eventhandler_tag     g_VBoxDrvFreeBSDEHTag;
+/** The /dev/vboxdrv character device. */
+static struct cdev         *g_pVBoxDrvFreeBSDChrDev;
 /** Reference counter. */
 static volatile uint32_t    g_cUsers;
=20
@@ -176,20 +167,11 @@
         if (RT_SUCCESS(rc))
         {
             /*
-             * Configure device cloning.
+             * Configure character device. Add symbolic link for compatibi=
lity.
              */
-            clone_setup(&g_pVBoxDrvFreeBSDClones);
-            g_VBoxDrvFreeBSDEHTag =3D EVENTHANDLER_REGISTER(dev_clone, VBo=
xDrvFreeBSDClone, 0, 1000);
-            if (g_VBoxDrvFreeBSDEHTag)
-            {
-                Log(("VBoxDrvFreeBSDLoad: returns successfully\n"));
-                return VINF_SUCCESS;
-            }
-
-            printf("vboxdrv: EVENTHANDLER_REGISTER(dev_clone,,,) failed\n"=
);
-            clone_cleanup(&g_pVBoxDrvFreeBSDClones);
-            rc =3D VERR_ALREADY_LOADED;
-            supdrvDeleteDevExt(&g_VBoxDrvFreeBSDDevExt);
+            g_pVBoxDrvFreeBSDChrDev =3D make_dev(&g_VBoxDrvFreeBSDChrDevSW=
, 0, UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv");
+            make_dev_alias(g_pVBoxDrvFreeBSDChrDev, "vboxdrv0");
+            return VINF_SUCCESS;
         }
         else
             printf("vboxdrv: supdrvInitDevExt failed, rc=3D%d\n", rc);
@@ -210,8 +192,7 @@
     /*
      * Reserve what we did in VBoxDrvFreeBSDInit.
      */
-    EVENTHANDLER_DEREGISTER(dev_clone, g_VBoxDrvFreeBSDEHTag);
-    clone_cleanup(&g_pVBoxDrvFreeBSDClones);
+    destroy_dev(g_pVBoxDrvFreeBSDChrDev);
=20
     supdrvDeleteDevExt(&g_VBoxDrvFreeBSDDevExt);
=20
@@ -225,59 +206,6 @@
=20
=20
 /**
- * DEVFS event handler.
- */
-static void VBoxDrvFreeBSDClone(void *pvArg, struct ucred *pCred, char *ps=
zName, int cchName, struct cdev **ppDev)
-{
-    int iUnit;
-    int rc;
-
-    Log(("VBoxDrvFreeBSDClone: pszName=3D%s ppDev=3D%p\n", pszName, ppDev)=
);
-
-    /*
-     * One device node per user, si_drv1 points to the session.
-     * /dev/vboxdrv<N> where N =3D {0...255}.
-     */
-    if (!ppDev)
-        return;
-    if (dev_stdclone(pszName, NULL, "vboxdrv", &iUnit) !=3D 1)
-        return;
-    if (iUnit >=3D 256 || iUnit < 0)
-    {
-        Log(("VBoxDrvFreeBSDClone: iUnit=3D%d >=3D 256 - rejected\n", iUni=
t));
-        return;
-    }
-
-    Log(("VBoxDrvFreeBSDClone: pszName=3D%s iUnit=3D%d\n", pszName, iUnit)=
);
-
-    rc =3D clone_create(&g_pVBoxDrvFreeBSDClones, &g_VBoxDrvFreeBSDChrDevS=
W, &iUnit, ppDev, 0);
-    Log(("VBoxDrvFreeBSDClone: clone_create -> %d; iUnit=3D%d\n", rc, iUni=
t));
-    if (rc)
-    {
-#if __FreeBSD_version > 800061
-        *ppDev =3D make_dev(&g_VBoxDrvFreeBSDChrDevSW, iUnit, UID_ROOT, GI=
D_WHEEL, VBOXDRV_PERM, "vboxdrv%d", iUnit);
-#else
-        *ppDev =3D make_dev(&g_VBoxDrvFreeBSDChrDevSW, unit2minor(iUnit), =
UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv%d", iUnit);
-#endif
-        if (*ppDev)
-        {
-            dev_ref(*ppDev);
-            (*ppDev)->si_flags |=3D SI_CHEAPCLONE;
-            Log(("VBoxDrvFreeBSDClone: Created *ppDev=3D%p iUnit=3D%d si_d=
rv1=3D%p si_drv2=3D%p\n",
-                 *ppDev, iUnit, (*ppDev)->si_drv1, (*ppDev)->si_drv2));
-            (*ppDev)->si_drv1 =3D (*ppDev)->si_drv2 =3D NULL;
-        }
-        else
-            OSDBGPRINT(("VBoxDrvFreeBSDClone: make_dev iUnit=3D%d failed\n=
", iUnit));
-    }
-    else
-        Log(("VBoxDrvFreeBSDClone: Existing *ppDev=3D%p iUnit=3D%d si_drv1=
=3D%p si_drv2=3D%p\n",
-             *ppDev, iUnit, (*ppDev)->si_drv1, (*ppDev)->si_drv2));
-}
-
-
-
-/**
  *
  * @returns 0 on success, errno on failure.
  *          EBUSY if the device is used by someone else.
@@ -287,21 +215,11 @@
  * @param   pFd     The file descriptor. FreeBSD 7.0 and later.
  * @param   iFd     The file descriptor index(?). Pre FreeBSD 7.0.
  */
-#if __FreeBSD__ >=3D 7
-static int VBoxDrvFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread =
*pTd, struct file *pFd)
-#else
-static int VBoxDrvFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread =
*pTd, int iFd)
-#endif
+static int VBoxDrvFreeBSDOpen(struct cdev *pDev, int fOpen, int iDevtype, =
struct thread *pTd)
 {
     PSUPDRVSESSION pSession;
     int rc;
=20
-#if __FreeBSD_version < 800062
-    Log(("VBoxDrvFreeBSDOpen: fOpen=3D%#x iUnit=3D%d\n", fOpen, minor2unit=
(minor(pDev))));
-#else
-    Log(("VBoxDrvFreeBSDOpen: fOpen=3D%#x iUnit=3D%d\n", fOpen, minor(dev2=
udev(pDev))));
-#endif
-
     /*
      * Let's be a bit picky about the flags...
      */
@@ -312,12 +230,6 @@
     }
=20
     /*
-     * Try grab it (we don't grab the giant, remember).
-     */
-    if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, (void *)0x42, NULL))
-        return EBUSY;
-
-    /*
      * Create a new session.
      */
     rc =3D supdrvCreateSession(&g_VBoxDrvFreeBSDDevExt, true /* fUser */, =
&pSession);
@@ -326,14 +238,10 @@
         /** @todo get (r)uid and (r)gid.
         pSession->Uid =3D stuff;
         pSession->Gid =3D stuff; */
-        if (ASMAtomicCmpXchgPtr(&pDev->si_drv1, pSession, (void *)0x42))
-        {
-            ASMAtomicIncU32(&g_cUsers);
-            return 0;
-        }
-
-        OSDBGPRINT(("VBoxDrvFreeBSDOpen: si_drv1=3D%p, expected 0x42!\n", =
pDev->si_drv1));
-        supdrvCloseSession(&g_VBoxDrvFreeBSDDevExt, pSession);
+        devfs_set_cdevpriv(pSession, VBoxDrvFreeBSDDtr);
+        Log(("VBoxDrvFreeBSDOpen: pSession=3D%p\n", pSession));
+        ASMAtomicIncU32(&g_cUsers);
+        return 0;
     }
=20
     return RTErrConvertToErrno(rc);
@@ -349,30 +257,16 @@
  * @param   DevType     The device type (CHR.
  * @param   pTd         The calling thread.
  */
-static int VBoxDrvFreeBSDClose(struct cdev *pDev, int fFile, int DevType, =
struct thread *pTd)
+static void VBoxDrvFreeBSDDtr(void *pData)
 {
-    PSUPDRVSESSION pSession =3D (PSUPDRVSESSION)pDev->si_drv1;
-#if __FreeBSD_version < 800062
-    Log(("VBoxDrvFreeBSDClose: fFile=3D%#x iUnit=3D%d pSession=3D%p\n", fF=
ile, minor2unit(minor(pDev)), pSession));
-#else
-    Log(("VBoxDrvFreeBSDClose: fFile=3D%#x iUnit=3D%d pSession=3D%p\n", fF=
ile, minor(dev2udev(pDev)), pSession));
-#endif
+    PSUPDRVSESSION pSession =3D pData;
+    Log(("VBoxDrvFreeBSDDtr: pSession=3D%p\n", pSession));
=20
     /*
-     * Close the session if it's still hanging on to the device...
+     * Close the session.
      */
-    if (VALID_PTR(pSession))
-    {
-        supdrvCloseSession(&g_VBoxDrvFreeBSDDevExt, pSession);
-        if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, NULL, pSession))
-            OSDBGPRINT(("VBoxDrvFreeBSDClose: si_drv1=3D%p expected %p!\n"=
, pDev->si_drv1, pSession));
-        ASMAtomicDecU32(&g_cUsers);
-        /* Don't use destroy_dev here because it may sleep resulting in a =
hanging user process. */
-        destroy_dev_sched(pDev);
-    }
-    else
-        OSDBGPRINT(("VBoxDrvFreeBSDClose: si_drv1=3D%p!\n", pSession));
-    return 0;
+    supdrvCloseSession(&g_VBoxDrvFreeBSDDevExt, pSession);
+    ASMAtomicDecU32(&g_cUsers);
 }
=20
=20
@@ -388,12 +282,8 @@
  */
 static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_long ulCmd, caddr_t pv=
Data, int fFile, struct thread *pTd)
 {
-    /*
-     * Validate the input.
-     */
-    PSUPDRVSESSION pSession =3D (PSUPDRVSESSION)pDev->si_drv1;
-    if (RT_UNLIKELY(!VALID_PTR(pSession)))
-        return EINVAL;
+    PSUPDRVSESSION pSession;
+    devfs_get_cdevpriv((void **)&pSession);
=20
     /*
      * Deal with the fast ioctl path first.
--- src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp
+++ src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp
@@ -76,16 +76,7 @@
     /*
      * Try open the BSD device.
      */
-    int hDevice =3D -1;
-    char szDevice[sizeof(DEVICE_NAME) + 16];
-    for (unsigned iUnit =3D 0; iUnit < 1024; iUnit++)
-    {
-        errno =3D 0;
-        snprintf(szDevice, sizeof(szDevice), DEVICE_NAME "%d", iUnit);
-        hDevice =3D open(szDevice, O_RDWR, 0);
-        if (hDevice >=3D 0 || errno !=3D EBUSY)
-            break;
-    }
+    int hDevice =3D open(DEVICE_NAME, O_RDWR, 0);
     if (hDevice < 0)
     {
         int rc;
@@ -97,7 +88,7 @@
             case ENOENT:    rc =3D VERR_VM_DRIVER_NOT_INSTALLED; break;
             default:        rc =3D VERR_VM_DRIVER_OPEN_ERROR; break;
         }
-        LogRel(("Failed to open \"%s\", errno=3D%d, rc=3D%Rrc\n", szDevice=
, errno, rc));
+        LogRel(("Failed to open \"%s\", errno=3D%d, rc=3D%Rrc\n", DEVICE_N=
AME, errno, rc));
         return rc;
     }
=20

--G9m07da55tKJni3T--

--XaepPZQT0uxAV0NY
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (FreeBSD)

iQIcBAEBAgAGBQJOsC2CAAoJEG5e2P40kaK7ubYP/RbW6tGo0SIdKpp2MEGnsVd0
7xnZ6yugJPMU8/gtDyHEU23zeHSPtbA3Ay0Enf1eZ31aOmMsvo+xfI2uSiq7JhKi
p5RxuHoAz5mPfJ8+hhhQfo0IxOWL6gA1iZTzU0a0FGDlMD5CKQzLP+p60v+oQ4Tn
Zym0nKVJeYn4GE5Ycdm26o2yKoq+TQpz53yTRI/w7GV686KIgzXPgEbqHXNjMJrv
v6O5wB2bRbka0yQyYwGjrBRgsmIMQvtSNM1b1gpC+5SNoFSkx993EKcxrQ6JWv/o
KWakV1tZ0PO3jAj4CoxuZ4GFcJGbYiV5FPMHH3U4B1E5ex/t2cDcARF6LeLTC7XX
JN6sdME3aETAfTBeV2+2Ly/Um3KTKqFRjmM+ylsmi/7RZKNdwXbk1OeCo9DOmyd5
ADWxnWJjPcYBGh9kulxe2GEhPBkM2lXsgjnMeziQ8kK71shKh+/x20ReGkexzkaC
Z8ECfbXy4VlPWNPkJuHKRa7x5CDr/U3eg8DTLUiwoPhokD62Yj4B098KmeozUp8P
jyrKXvhGlKdoqk4PfFbA+43n0GHMrXmnYh4SiTxpMPlPLDGkwGz4XHi5Dzp+feHZ
EGBACr3R4WsgW3GJnveQFA6ObNgRa1AIk9IR0izwF0zwLrFUoZbz9CzLJxxomH1J
v4eLtiSZ620TMlgq3aaO
=bdSp
-----END PGP SIGNATURE-----

--XaepPZQT0uxAV0NY--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111101173354.GW2258>