tty: convert tty_lock_assert to tty_assert_locked to hide lock type
A later change, currently being iterated on in D24459, will in-fact change the lock type to an sx so that TTY drivers can sleep on it if they need to. Committing this ahead of time to make the review in question a little more palatable. tty_lock_assert() is unfortunately still needed for now in two places to make sure that the tty lock has not been recursed upon, for those scenarios where it's supplied by the TTY driver and possibly a mutex that is allowed to recurse. Suggested by: markj
This commit is contained in:
parent
490befd40a
commit
23d5326823
@ -266,7 +266,7 @@ aju_handle_input(struct altera_jtag_uart_softc *sc, struct tty *tp)
|
||||
{
|
||||
int c;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
AJU_LOCK_ASSERT(sc);
|
||||
|
||||
while (aju_readable(sc)) {
|
||||
@ -298,7 +298,7 @@ aju_handle_output(struct altera_jtag_uart_softc *sc, struct tty *tp)
|
||||
uint32_t v;
|
||||
uint8_t ch;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
AJU_LOCK_ASSERT(sc);
|
||||
|
||||
AJU_UNLOCK(sc);
|
||||
@ -364,7 +364,7 @@ aju_outwakeup(struct tty *tp)
|
||||
{
|
||||
struct altera_jtag_uart_softc *sc = tty_softc(tp);
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
AJU_LOCK(sc);
|
||||
aju_handle_output(sc, tp);
|
||||
|
@ -130,7 +130,7 @@ static void
|
||||
bvm_tty_close(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
callout_stop(&bvm_timer);
|
||||
}
|
||||
|
||||
@ -159,7 +159,7 @@ bvm_timeout(void *v)
|
||||
|
||||
tp = (struct tty *)v;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
while ((c = bvm_cngetc(NULL)) != -1)
|
||||
ttydisc_rint(tp, c, 0);
|
||||
ttydisc_rint_done(tp);
|
||||
|
@ -142,7 +142,7 @@ cfe_timeout(void *v)
|
||||
|
||||
tp = (struct tty *)v;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
while ((c = cfe_cngetc(NULL)) != -1)
|
||||
ttydisc_rint(tp, c, 0);
|
||||
ttydisc_rint_done(tp);
|
||||
|
@ -152,7 +152,7 @@ ofw_timeout(void *v)
|
||||
|
||||
tp = (struct tty *)v;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
while ((c = ofw_cngetc(NULL)) != -1)
|
||||
ttydisc_rint(tp, c, 0);
|
||||
ttydisc_rint_done(tp);
|
||||
|
@ -674,7 +674,7 @@ static void rp_do_poll(void *arg)
|
||||
|
||||
rp = arg;
|
||||
tp = rp->rp_tty;
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
ctl = rp->rp_ctlp;
|
||||
CtlMask = ctl->ctlmask(ctl);
|
||||
if (CtlMask & (1 << rp->rp_aiop)) {
|
||||
|
@ -515,7 +515,7 @@ xencons_tx(struct tty *tp)
|
||||
|
||||
cons = tty_softc(tp);
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
/*
|
||||
* Don't transmit any character if the buffer is full. Otherwise,
|
||||
|
@ -228,7 +228,7 @@ static void
|
||||
ttydev_leave(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tty_opened(tp) || tp->t_flags & TF_OPENCLOSE) {
|
||||
/* Device is still opened somewhere. */
|
||||
@ -413,7 +413,7 @@ static __inline int
|
||||
tty_is_ctty(struct tty *tp, struct proc *p)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
return (p->p_session == tp->t_session && p->p_flag & P_CONTROLT);
|
||||
}
|
||||
@ -427,7 +427,7 @@ tty_wait_background(struct tty *tp, struct thread *td, int sig)
|
||||
int error;
|
||||
|
||||
MPASS(sig == SIGTTIN || sig == SIGTTOU);
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
for (;;) {
|
||||
PROC_LOCK(p);
|
||||
@ -697,7 +697,7 @@ tty_kqops_read_event(struct knote *kn, long hint __unused)
|
||||
{
|
||||
struct tty *tp = kn->kn_hook;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tty_gone(tp) || tp->t_flags & TF_ZOMBIE) {
|
||||
kn->kn_flags |= EV_EOF;
|
||||
@ -721,7 +721,7 @@ tty_kqops_write_event(struct knote *kn, long hint __unused)
|
||||
{
|
||||
struct tty *tp = kn->kn_hook;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tty_gone(tp)) {
|
||||
kn->kn_flags |= EV_EOF;
|
||||
@ -1122,7 +1122,7 @@ tty_rel_free(struct tty *tp)
|
||||
{
|
||||
struct cdev *dev;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
#define TF_ACTIVITY (TF_GONE|TF_OPENED|TF_HOOK|TF_OPENCLOSE)
|
||||
if (tp->t_sessioncnt != 0 || (tp->t_flags & TF_ACTIVITY) != TF_GONE) {
|
||||
@ -1153,7 +1153,7 @@ tty_rel_pgrp(struct tty *tp, struct pgrp *pg)
|
||||
{
|
||||
|
||||
MPASS(tp->t_sessioncnt > 0);
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tp->t_pgrp == pg)
|
||||
tp->t_pgrp = NULL;
|
||||
@ -1180,7 +1180,7 @@ void
|
||||
tty_rel_gone(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
/* Simulate carrier removal. */
|
||||
@ -1268,7 +1268,7 @@ static void
|
||||
tty_to_xtty(struct tty *tp, struct xtty *xt)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
xt->xt_size = sizeof(struct xtty);
|
||||
xt->xt_insize = ttyinq_getsize(&tp->t_inq);
|
||||
@ -1460,7 +1460,7 @@ tty_signal_sessleader(struct tty *tp, int sig)
|
||||
{
|
||||
struct proc *p;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(sig >= 1 && sig < NSIG);
|
||||
|
||||
/* Make signals start output again. */
|
||||
@ -1479,7 +1479,7 @@ tty_signal_pgrp(struct tty *tp, int sig)
|
||||
{
|
||||
ksiginfo_t ksi;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(sig >= 1 && sig < NSIG);
|
||||
|
||||
/* Make signals start output again. */
|
||||
@ -1957,7 +1957,7 @@ tty_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tty_gone(tp))
|
||||
return (ENXIO);
|
||||
@ -2124,7 +2124,7 @@ void
|
||||
ttyhook_unregister(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(tp->t_flags & TF_HOOK);
|
||||
|
||||
/* Disconnect the hook. */
|
||||
|
@ -266,7 +266,7 @@ tty_info(struct tty *tp)
|
||||
char comm[MAXCOMLEN + 1];
|
||||
struct rusage ru;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tty_checkoutq(tp) == 0)
|
||||
return;
|
||||
|
@ -326,7 +326,7 @@ ttydisc_read(struct tty *tp, struct uio *uio, int ioflag)
|
||||
{
|
||||
int error;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (uio->uio_resid == 0)
|
||||
return (0);
|
||||
@ -458,7 +458,7 @@ ttydisc_write(struct tty *tp, struct uio *uio, int ioflag)
|
||||
int error = 0;
|
||||
unsigned int oblen = 0;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tp->t_flags & TF_ZOMBIE)
|
||||
return (EIO);
|
||||
@ -573,7 +573,7 @@ done:
|
||||
void
|
||||
ttydisc_optimize(struct tty *tp)
|
||||
{
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (ttyhook_hashook(tp, rint_bypass)) {
|
||||
tp->t_flags |= TF_BYPASS;
|
||||
@ -594,7 +594,7 @@ void
|
||||
ttydisc_modem(struct tty *tp, int open)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (open)
|
||||
cv_broadcast(&tp->t_dcdwait);
|
||||
@ -842,7 +842,7 @@ ttydisc_rint(struct tty *tp, char c, int flags)
|
||||
char ob[3] = { 0xff, 0x00 };
|
||||
size_t ol;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
atomic_add_long(&tty_nin, 1);
|
||||
|
||||
@ -1085,7 +1085,7 @@ ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len)
|
||||
{
|
||||
size_t ret;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
MPASS(tp->t_flags & TF_BYPASS);
|
||||
|
||||
@ -1106,7 +1106,7 @@ void
|
||||
ttydisc_rint_done(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (ttyhook_hashook(tp, rint_done))
|
||||
ttyhook_rint_done(tp);
|
||||
@ -1122,7 +1122,7 @@ ttydisc_rint_poll(struct tty *tp)
|
||||
{
|
||||
size_t l;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (ttyhook_hashook(tp, rint_poll))
|
||||
return ttyhook_rint_poll(tp);
|
||||
@ -1165,7 +1165,7 @@ size_t
|
||||
ttydisc_getc(struct tty *tp, void *buf, size_t len)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tp->t_flags & TF_STOPPED)
|
||||
return (0);
|
||||
@ -1192,7 +1192,7 @@ ttydisc_getc_uio(struct tty *tp, struct uio *uio)
|
||||
size_t len;
|
||||
char buf[TTY_STACKBUF];
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tp->t_flags & TF_STOPPED)
|
||||
return (0);
|
||||
@ -1233,7 +1233,7 @@ size_t
|
||||
ttydisc_getc_poll(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tp->t_flags & TF_STOPPED)
|
||||
return (0);
|
||||
@ -1255,7 +1255,7 @@ tty_putstrn(struct tty *tp, const char *p, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (tty_gone(tp))
|
||||
return (-1);
|
||||
|
@ -412,7 +412,7 @@ ngt_rint_bypass(struct tty *tp, const void *buf, size_t len)
|
||||
size_t total = 0;
|
||||
int error = 0, length;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (sc->hook == NULL)
|
||||
return (0);
|
||||
@ -459,7 +459,7 @@ ngt_rint(struct tty *tp, char c, int flags)
|
||||
struct mbuf *m;
|
||||
int error = 0;
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
if (sc->hook == NULL)
|
||||
return (0);
|
||||
|
@ -173,9 +173,12 @@ void tty_rel_gone(struct tty *tp);
|
||||
#define tty_lock(tp) mtx_lock((tp)->t_mtx)
|
||||
#define tty_unlock(tp) mtx_unlock((tp)->t_mtx)
|
||||
#define tty_lock_owned(tp) mtx_owned((tp)->t_mtx)
|
||||
#define tty_lock_assert(tp,ma) mtx_assert((tp)->t_mtx, (ma))
|
||||
#define tty_assert_locked(tp) mtx_assert((tp)->t_mtx, MA_OWNED)
|
||||
#define tty_getlock(tp) ((tp)->t_mtx)
|
||||
|
||||
/* XXX Should migrate users to tty_assert_locked! */
|
||||
#define tty_lock_assert(tp, ma) mtx_assert((tp)->t_mtx, (ma))
|
||||
|
||||
/* Device node creation. */
|
||||
int tty_makedevf(struct tty *tp, struct ucred *cred, int flags,
|
||||
const char *fmt, ...) __printflike(4, 5);
|
||||
|
@ -86,7 +86,7 @@ static __inline int
|
||||
ttydevsw_open(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
return (tp->t_devsw->tsw_open(tp));
|
||||
@ -96,7 +96,7 @@ static __inline void
|
||||
ttydevsw_close(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
tp->t_devsw->tsw_close(tp);
|
||||
@ -106,7 +106,7 @@ static __inline void
|
||||
ttydevsw_outwakeup(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
/* Prevent spurious wakeups. */
|
||||
@ -120,7 +120,7 @@ static __inline void
|
||||
ttydevsw_inwakeup(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
/* Prevent spurious wakeups. */
|
||||
@ -134,7 +134,7 @@ static __inline int
|
||||
ttydevsw_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
return (tp->t_devsw->tsw_ioctl(tp, cmd, data, td));
|
||||
@ -145,7 +145,7 @@ ttydevsw_cioctl(struct tty *tp, int unit, u_long cmd, caddr_t data,
|
||||
struct thread *td)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
return (tp->t_devsw->tsw_cioctl(tp, unit, cmd, data, td));
|
||||
@ -183,7 +183,7 @@ static __inline void
|
||||
ttydevsw_pktnotify(struct tty *tp, char event)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
tp->t_devsw->tsw_pktnotify(tp, event);
|
||||
@ -202,7 +202,7 @@ static __inline bool
|
||||
ttydevsw_busy(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
return (tp->t_devsw->tsw_busy(tp));
|
||||
|
@ -72,7 +72,7 @@ static __inline size_t
|
||||
ttydisc_read_poll(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
return ttyinq_bytescanonicalized(&tp->t_inq);
|
||||
}
|
||||
@ -81,7 +81,7 @@ static __inline size_t
|
||||
ttydisc_write_poll(struct tty *tp)
|
||||
{
|
||||
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
return ttyoutq_bytesleft(&tp->t_outq);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void ttyhook_unregister(struct tty *);
|
||||
static __inline int
|
||||
ttyhook_rint(struct tty *tp, char c, int flags)
|
||||
{
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
return tp->t_hook->th_rint(tp, c, flags);
|
||||
@ -87,7 +87,7 @@ ttyhook_rint(struct tty *tp, char c, int flags)
|
||||
static __inline size_t
|
||||
ttyhook_rint_bypass(struct tty *tp, const void *buf, size_t len)
|
||||
{
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
return tp->t_hook->th_rint_bypass(tp, buf, len);
|
||||
@ -96,7 +96,7 @@ ttyhook_rint_bypass(struct tty *tp, const void *buf, size_t len)
|
||||
static __inline void
|
||||
ttyhook_rint_done(struct tty *tp)
|
||||
{
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
tp->t_hook->th_rint_done(tp);
|
||||
@ -105,7 +105,7 @@ ttyhook_rint_done(struct tty *tp)
|
||||
static __inline size_t
|
||||
ttyhook_rint_poll(struct tty *tp)
|
||||
{
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
return tp->t_hook->th_rint_poll(tp);
|
||||
@ -114,7 +114,7 @@ ttyhook_rint_poll(struct tty *tp)
|
||||
static __inline size_t
|
||||
ttyhook_getc_inject(struct tty *tp, void *buf, size_t len)
|
||||
{
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
return tp->t_hook->th_getc_inject(tp, buf, len);
|
||||
@ -123,7 +123,7 @@ ttyhook_getc_inject(struct tty *tp, void *buf, size_t len)
|
||||
static __inline void
|
||||
ttyhook_getc_capture(struct tty *tp, const void *buf, size_t len)
|
||||
{
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
tp->t_hook->th_getc_capture(tp, buf, len);
|
||||
@ -132,7 +132,7 @@ ttyhook_getc_capture(struct tty *tp, const void *buf, size_t len)
|
||||
static __inline size_t
|
||||
ttyhook_getc_poll(struct tty *tp)
|
||||
{
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
MPASS(!tty_gone(tp));
|
||||
|
||||
return tp->t_hook->th_getc_poll(tp);
|
||||
@ -141,7 +141,7 @@ ttyhook_getc_poll(struct tty *tp)
|
||||
static __inline void
|
||||
ttyhook_close(struct tty *tp)
|
||||
{
|
||||
tty_lock_assert(tp, MA_OWNED);
|
||||
tty_assert_locked(tp);
|
||||
|
||||
tp->t_hook->th_close(tp);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user