1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-17 10:26:15 +00:00

Continue the crusade towards a dev_clone()-free kernel, removing its

usage from dtrace. The dtrace code already uses cdevpriv(9) since FreeBSD
8, so this change should be quite harmless.

Reviewed by:	markj
Approved by:	markj
MFC after:	never
This commit is contained in:
Davide Italiano 2014-06-25 03:54:02 +00:00
parent eaaf9f7fce
commit a99098e2ba
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=267851
5 changed files with 2 additions and 155 deletions

View File

@ -15716,10 +15716,8 @@ dtrace_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
#endif
#if !defined(sun)
#if __FreeBSD_version >= 800039
static void dtrace_dtr(void *);
#endif
#endif
/*ARGSUSED*/
static int
@ -15745,27 +15743,7 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
ASSERT(getminor(*devp) == DTRACEMNRN_DTRACE);
#else
cred_t *cred_p = NULL;
#if __FreeBSD_version < 800039
/*
* The first minor device is the one that is cloned so there is
* nothing more to do here.
*/
if (dev2unit(dev) == 0)
return 0;
/*
* Devices are cloned, so if the DTrace state has already
* been allocated, that means this device belongs to a
* different client. Each client should open '/dev/dtrace'
* to get a cloned device.
*/
if (dev->si_drv1 != NULL)
return (EBUSY);
#endif
cred_p = dev->si_cred;
#endif
/*
* If no DTRACE_PRIV_* bits are set in the credential, then the
@ -15773,11 +15751,6 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
*/
dtrace_cred2priv(cred_p, &priv, &uid, &zoneid);
if (priv == DTRACE_PRIV_NONE) {
#if !defined(sun)
#if __FreeBSD_version < 800039
/* Destroy the cloned device. */
destroy_dev(dev);
#endif
#endif
return (EACCES);
@ -15810,11 +15783,7 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
state = dtrace_state_create(devp, cred_p);
#else
state = dtrace_state_create(dev);
#if __FreeBSD_version < 800039
dev->si_drv1 = state;
#else
devfs_set_cdevpriv(state, dtrace_dtr);
#endif
#endif
mutex_exit(&cpu_lock);
@ -15827,12 +15796,6 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
--dtrace_opens;
#endif
mutex_exit(&dtrace_lock);
#if !defined(sun)
#if __FreeBSD_version < 800039
/* Destroy the cloned device. */
destroy_dev(dev);
#endif
#endif
return (EAGAIN);
}
@ -15845,9 +15808,6 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
#if defined(sun)
static int
dtrace_close(dev_t dev, int flag, int otyp, cred_t *cred_p)
#elif __FreeBSD_version < 800039
static int
dtrace_close(struct cdev *dev, int flags, int fmt __unused, struct thread *td)
#else
static void
dtrace_dtr(void *data)
@ -15861,17 +15821,8 @@ dtrace_dtr(void *data)
return (0);
state = ddi_get_soft_state(dtrace_softstate, minor);
#else
#if __FreeBSD_version < 800039
dtrace_state_t *state = dev->si_drv1;
/* Check if this is not a cloned device. */
if (dev2unit(dev) == 0)
return (0);
#else
dtrace_state_t *state = data;
#endif
#endif
mutex_enter(&cpu_lock);
@ -15890,9 +15841,6 @@ dtrace_dtr(void *data)
#if !defined(sun)
kmem_free(state, 0);
#if __FreeBSD_version < 800039
dev->si_drv1 = NULL;
#endif
#endif
}
@ -15907,12 +15855,7 @@ dtrace_dtr(void *data)
mutex_exit(&dtrace_lock);
mutex_exit(&cpu_lock);
#if __FreeBSD_version < 800039
/* Schedule this cloned device to be destroyed. */
destroy_dev_sched(dev);
#endif
#if defined(sun) || __FreeBSD_version < 800039
#if defined(sun)
return (0);
#endif
}
@ -16949,24 +16892,14 @@ static d_ioctl_t dtrace_ioctl;
static d_ioctl_t dtrace_ioctl_helper;
static void dtrace_load(void *);
static int dtrace_unload(void);
#if __FreeBSD_version < 800039
static void dtrace_clone(void *, struct ucred *, char *, int , struct cdev **);
static struct clonedevs *dtrace_clones; /* Ptr to the array of cloned devices. */
static eventhandler_tag eh_tag; /* Event handler tag. */
#else
static struct cdev *dtrace_dev;
static struct cdev *helper_dev;
#endif
void dtrace_invop_init(void);
void dtrace_invop_uninit(void);
static struct cdevsw dtrace_cdevsw = {
.d_version = D_VERSION,
#if __FreeBSD_version < 800039
.d_flags = D_TRACKCLOSE | D_NEEDMINOR,
.d_close = dtrace_close,
#endif
.d_ioctl = dtrace_ioctl,
.d_open = dtrace_open,
.d_name = "dtrace",
@ -16979,9 +16912,6 @@ static struct cdevsw helper_cdevsw = {
};
#include <dtrace_anon.c>
#if __FreeBSD_version < 800039
#include <dtrace_clone.c>
#endif
#include <dtrace_ioctl.c>
#include <dtrace_load.c>
#include <dtrace_modevent.c>

View File

@ -1,57 +0,0 @@
/*-
* Copyright (C) 2006 John Birrell <jb@freebsd.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice(s), this list of conditions and the following disclaimer as
* the first lines of this file unmodified other than the possible
* addition of one or more copyright notices.
* 2. Redistributions in binary form must reproduce the above copyright
* notice(s), this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* $FreeBSD$
*
*/
static void
dtrace_clone(void *arg, struct ucred *cred, char *name, int namelen, struct cdev **dev)
{
int u = -1;
size_t len;
if (*dev != NULL)
return;
len = strlen(name);
if (len != 6 && len != 13)
return;
if (bcmp(name,"dtrace",6) != 0)
return;
if (len == 13 && bcmp(name,"dtrace/dtrace",13) != 0)
return;
/* Clone the device to the new minor number. */
if (clone_create(&dtrace_clones, &dtrace_cdevsw, &u, dev, 0) != 0)
/* Create the /dev/dtrace/dtraceNN entry. */
*dev = make_dev_credf(MAKEDEV_REF, &dtrace_cdevsw, u, cred,
UID_ROOT, GID_WHEEL, 0600, "dtrace/dtrace%d", u);
}

View File

@ -78,12 +78,9 @@ static int
dtrace_ioctl(struct cdev *dev, u_long cmd, caddr_t addr,
int flags __unused, struct thread *td)
{
#if __FreeBSD_version < 800039
dtrace_state_t *state = dev->si_drv1;
#else
dtrace_state_t *state;
devfs_get_cdevpriv((void **) &state);
#endif
int error = 0;
if (state == NULL)
return (EINVAL);

View File

@ -158,18 +158,10 @@ dtrace_load(void *dummy)
mutex_exit(&cpu_lock);
#if __FreeBSD_version < 800039
/* Enable device cloning. */
clone_setup(&dtrace_clones);
/* Setup device cloning events. */
eh_tag = EVENTHANDLER_REGISTER(dev_clone, dtrace_clone, 0, 1000);
#else
dtrace_dev = make_dev(&dtrace_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
"dtrace/dtrace");
helper_dev = make_dev(&helper_cdevsw, 0, UID_ROOT, GID_WHEEL, 0660,
"dtrace/helper");
#endif
return;
}

View File

@ -28,23 +28,8 @@ dtrace_unload()
dtrace_state_t *state;
int error = 0;
#if __FreeBSD_version < 800039
/*
* Check if there is still an event handler callback
* registered.
*/
if (eh_tag != 0) {
/* De-register the device cloning event handler. */
EVENTHANDLER_DEREGISTER(dev_clone, eh_tag);
eh_tag = 0;
/* Stop device cloning. */
clone_cleanup(&dtrace_clones);
}
#else
destroy_dev(dtrace_dev);
destroy_dev(helper_dev);
#endif
mutex_enter(&dtrace_provider_lock);
mutex_enter(&dtrace_lock);