From: Nuno Antunes Date: Wed, 4 Jul 2012 08:48:55 +0000 (+0100) Subject: netgraph7: Welcome ng_tty. X-Git-Tag: v3.2.0~678 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/e71e017b9af2a5fa00b7d90617fdf2a46102566b netgraph7: Welcome ng_tty. --- diff --git a/etc/mtree/BSD.include.dist b/etc/mtree/BSD.include.dist index 6538934cfb..3a52ee9345 100644 --- a/etc/mtree/BSD.include.dist +++ b/etc/mtree/BSD.include.dist @@ -254,6 +254,8 @@ .. tee .. + tty + .. vjc .. .. diff --git a/include/Makefile b/include/Makefile index 2f56764211..91eedbde6e 100644 --- a/include/Makefile +++ b/include/Makefile @@ -74,7 +74,7 @@ LSUBDIRS= bus/cam bus/cam/scsi \ netgraph7/iface netgraph7/ksocket netgraph7/l2tp netgraph7/lmi \ netgraph7/mppc netgraph7/one2many netgraph7/ppp netgraph7/pppoe \ netgraph7/pptpgre netgraph7/rfc1490 netgraph7/socket \ - netgraph7/tcpmss netgraph7/tee netgraph7/vjc \ + netgraph7/tcpmss netgraph7/tee netgraph7/tty netgraph7/vjc \ bus/cam bus/usb bus/pccard bus/pci bus/isa bus/ppbus bus/smbus \ netproto/atm netproto/ipsec netproto/ipx \ netproto/key netproto/natm netproto/ncp netproto/smb \ diff --git a/lib/libnetgraph7/debug.c b/lib/libnetgraph7/debug.c index b4bde1adbe..b57e18cf87 100644 --- a/lib/libnetgraph7/debug.c +++ b/lib/libnetgraph7/debug.c @@ -95,9 +95,7 @@ */ #include #include -/* #include -*/ #include #ifdef WHISTLE #include @@ -168,9 +166,7 @@ static const struct ng_cookie cookies[] = { */ COOKIE(TCPMSS), COOKIE(TEE), -/* COOKIE(TTY), -*/ COOKIE(VJC), #ifdef WHISTLE COOKIE(DF), diff --git a/sys/conf/files b/sys/conf/files index c58587348a..2ac11dc2e2 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1285,7 +1285,7 @@ netgraph7/ng_sppp.c optional netgraph7_sppp netgraph7/ng_tag.c optional netgraph7_tag netgraph7/tcpmss/ng_tcpmss.c optional netgraph7_tcpmss netgraph7/tee/ng_tee.c optional netgraph7_tee -netgraph7/ng_tty.c optional netgraph7_tty +netgraph7/tty/ng_tty.c optional netgraph7_tty netgraph7/vjc/ng_vjc.c optional netgraph7_vjc netinet/libalias/alias.c optional netgraph7_nat diff --git a/sys/netgraph7/Makefile b/sys/netgraph7/Makefile index d48bab91c3..7146ef629f 100644 --- a/sys/netgraph7/Makefile +++ b/sys/netgraph7/Makefile @@ -28,6 +28,7 @@ SUBDIR= UI \ socket \ tcpmss \ tee \ + tty \ vjc # eiface \ # fec \ @@ -35,7 +36,6 @@ SUBDIR= UI \ # socket \ # sync_ar \ # sync_sr \ -# tty \ .if !defined(NO_CRYPT) && exists(${.CURDIR}/../crypto/rc4/rc4.c) #SUBDIR+= mppc diff --git a/sys/netgraph7/netgraph.h b/sys/netgraph7/netgraph.h index 95a370712b..9668ef66d3 100644 --- a/sys/netgraph7/netgraph.h +++ b/sys/netgraph7/netgraph.h @@ -53,6 +53,7 @@ #include #include #include +#include /* NG_HOOKSIZ, NG_NODESIZ */ #include "dragonfly.h" #ifdef HAVE_KERNEL_OPTION_HEADERS diff --git a/sys/netgraph7/tty/Makefile b/sys/netgraph7/tty/Makefile new file mode 100644 index 0000000000..b8458c364c --- /dev/null +++ b/sys/netgraph7/tty/Makefile @@ -0,0 +1,5 @@ +MOD= ng_tty +SRCS= ng_tty.c +KMODDEPS= netgraph + +.include diff --git a/sys/netgraph7/ng_tty.c b/sys/netgraph7/tty/ng_tty.c similarity index 90% rename from sys/netgraph7/ng_tty.c rename to sys/netgraph7/tty/ng_tty.c index 16523f125a..a3ac01a83b 100644 --- a/sys/netgraph7/ng_tty.c +++ b/sys/netgraph7/tty/ng_tty.c @@ -74,8 +74,8 @@ #include #include -#include "ng_message.h" -#include "netgraph.h" +#include +#include #include "ng_tty.h" /* Misc defs */ @@ -105,7 +105,7 @@ static int ngt_close(struct tty *tp, int flag); static int ngt_read(struct tty *tp, struct uio *uio, int flag); static int ngt_write(struct tty *tp, struct uio *uio, int flag); static int ngt_tioctl(struct tty *tp, - u_long cmd, caddr_t data, int flag, struct thread *); + u_long cmd, caddr_t data, int flag, struct ucred *cred); static int ngt_input(int c, struct tty *tp); static int ngt_start(struct tty *tp); @@ -196,20 +196,18 @@ ngt_open(struct cdev *dev, struct tty *tp) /* Initialize private struct */ sc = kmalloc(sizeof(*sc), M_NETGRAPH, M_WAITOK | M_ZERO); + crit_enter(); lwkt_gettoken(&tty_token); sc->tp = tp; - sc->hotchar = tp->t_hotchar = NG_TTY_DFL_HOTCHAR; - mtx_init(&sc->outq.ifq_mtx, "ng_tty node+queue", NULL, MTX_DEF); - IFQ_SET_MAXLEN(&sc->outq, MAX_MBUFQ); - - NGTLOCK(sc); + sc->hotchar = NG_TTY_DFL_HOTCHAR; + sc->outq.ifq_maxlen = MAX_MBUFQ; /* Setup netgraph node */ error = ng_make_node_common(&typestruct, &sc->node); if (error) { - NGTUNLOCK(sc); kfree(sc, M_NETGRAPH); lwkt_reltoken(&tty_token); + crit_exit(); return (error); } @@ -219,18 +217,18 @@ ngt_open(struct cdev *dev, struct tty *tp) /* Assign node its name */ if ((error = ng_name_node(sc->node, name))) { sc->flags |= FLG_DIE; - NGTUNLOCK(sc); NG_NODE_UNREF(sc->node); log(LOG_ERR, "%s: node name exists?\n", name); lwkt_reltoken(&tty_token); + crit_exit(); return (error); } /* Set back pointers */ NG_NODE_SET_PRIVATE(sc->node, sc); - tp->t_lsc = sc; + tp->t_sc = sc; - ng_callout_init_mp(&sc->chand); + callout_init_mp(&sc->chand); /* * Pre-allocate cblocks to the an appropriate amount. @@ -242,10 +240,9 @@ ngt_open(struct cdev *dev, struct tty *tp) clist_alloc_cblocks(&tp->t_outq, MLEN + NGT_HIWATER, MLEN + NGT_HIWATER); - NGTUNLOCK(sc); - lwkt_reltoken(&tty_token); - return (0); + crit_exit(); + return (error); } /* @@ -255,21 +252,21 @@ ngt_open(struct cdev *dev, struct tty *tp) static int ngt_close(struct tty *tp, int flag) { - const sc_p sc = (sc_p) tp->t_lsc; + const sc_p sc = (sc_p) tp->t_sc; + crit_enter(); lwkt_gettoken(&tty_token); ttyflush(tp, FREAD | FWRITE); clist_free_cblocks(&tp->t_outq); if (sc != NULL) { - NGTLOCK(sc); if (callout_pending(&sc->chand)) ng_uncallout(&sc->chand, sc->node); - tp->t_lsc = NULL; + tp->t_sc = NULL; sc->flags |= FLG_DIE; - NGTUNLOCK(sc); ng_rmnode_self(sc->node); } lwkt_reltoken(&tty_token); + crit_exit(); return (0); } @@ -295,14 +292,16 @@ ngt_write(struct tty *tp, struct uio *uio, int flag) * We implement the NGIOCGINFO ioctl() defined in ng_message.h. */ static int -ngt_tioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread *td) +ngt_tioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct ucred *cred) { - const sc_p sc = (sc_p) tp->t_lsc; + const sc_p sc = (sc_p) tp->t_sc; - if (sc == NULL) + if (sc == NULL) { /* No node attached */ return (0); + } + crit_enter(); lwkt_gettoken(&tty_token); switch (cmd) { case NGIOCGINFO: @@ -311,21 +310,21 @@ ngt_tioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread *td const node_p node = sc->node; bzero(ni, sizeof(*ni)); - NGTLOCK(sc); if (NG_NODE_HAS_NAME(node)) strncpy(ni->name, NG_NODE_NAME(node), sizeof(ni->name) - 1); strncpy(ni->type, node->nd_type->name, sizeof(ni->type) - 1); ni->id = (u_int32_t) ng_node2ID(node); ni->hooks = NG_NODE_NUMHOOKS(node); - NGTUNLOCK(sc); break; } default: lwkt_reltoken(&tty_token); + crit_exit(); return (ENOIOCTL); } lwkt_reltoken(&tty_token); + crit_exit(); return (0); } @@ -344,11 +343,13 @@ ngt_input(int c, struct tty *tp) struct mbuf *m; int error = 0; + crit_enter(); lwkt_gettoken(&tty_token); - sc = (sc_p) tp->t_lsc; + sc = (sc_p) tp->t_sc; if (sc == NULL) { /* No node attached */ lwkt_reltoken(&tty_token); + crit_exit(); return (0); } @@ -362,6 +363,7 @@ ngt_input(int c, struct tty *tp) if (sc->flags & FLG_DEBUG) log(LOG_DEBUG, "%s: no carrier\n", NG_NODE_NAME(node)); lwkt_reltoken(&tty_token); + crit_exit(); return (0); } if (c & TTY_ERRORMASK) { @@ -370,6 +372,7 @@ ngt_input(int c, struct tty *tp) log(LOG_DEBUG, "%s: line error %x\n", NG_NODE_NAME(node), c & TTY_ERRORMASK); lwkt_reltoken(&tty_token); + crit_exit(); return (0); } c &= TTY_CHARMASK; @@ -382,6 +385,7 @@ ngt_input(int c, struct tty *tp) log(LOG_ERR, "%s: can't get mbuf\n", NG_NODE_NAME(node)); lwkt_reltoken(&tty_token); + crit_exit(); return (ENOBUFS); } m->m_len = m->m_pkthdr.len = 0; @@ -407,18 +411,17 @@ ngt_input(int c, struct tty *tp) * */ - NGTLOCK(sc); if (sc->hook == NULL) { - NGTUNLOCK(sc); m_freem(m); lwkt_reltoken(&tty_token); + crit_exit(); return (0); /* XXX: original behavior */ } NG_SEND_DATA_ONLY(error, sc->hook, m); /* Will queue */ - NGTUNLOCK(sc); } lwkt_reltoken(&tty_token); + crit_exit(); return (error); } @@ -429,8 +432,9 @@ ngt_input(int c, struct tty *tp) static int ngt_start(struct tty *tp) { - const sc_p sc = (sc_p) tp->t_lsc; + const sc_p sc = (sc_p) tp->t_sc; + crit_enter(); lwkt_gettoken(&tty_token); while (tp->t_outq.c_cc < NGT_HIWATER) { /* XXX 2.2 specific ? */ struct mbuf *m; @@ -462,15 +466,17 @@ ngt_start(struct tty *tp) /* Call output process whether or not there is any output. We are * being called in lieu of ttstart and must do what it would. */ - tt_oproc(tp); + if (tp->t_oproc != NULL) + (*tp->t_oproc) (tp); /* This timeout is needed for operation on a pseudo-tty, because the * pty code doesn't call pppstart after it has drained the t_outq. */ /* XXX: outq not locked */ - if (!IFQ_IS_EMPTY(&sc->outq) && !callout_pending(&sc->chand)) + if (!IF_QEMPTY(&sc->outq) && !callout_pending(&sc->chand)) ng_callout(&sc->chand, sc->node, NULL, 1, ngt_timeout, NULL, 0); lwkt_reltoken(&tty_token); + crit_exit(); return (0); } @@ -482,9 +488,11 @@ ngt_timeout(node_p node, hook_p hook, void *arg1, int arg2) { const sc_p sc = NG_NODE_PRIVATE(node); - mtx_lock(&Giant); + crit_enter(); + lwkt_gettoken(&tty_token); ngt_start(sc->tp); - mtx_unlock(&Giant); + lwkt_reltoken(&tty_token); + crit_exit(); } /****************************************************************** @@ -513,14 +521,16 @@ ngt_newhook(node_p node, hook_p hook, const char *name) if (strcmp(name, NG_TTY_HOOK)) return (EINVAL); - - if (sc->hook) + crit_enter(); + lwkt_gettoken(&tty_token); + if (sc->hook) { + lwkt_reltoken(&tty_token); + crit_exit(); return (EISCONN); - - NGTLOCK(sc); + } sc->hook = hook; - NGTUNLOCK(sc); - + lwkt_reltoken(&tty_token); + crit_exit(); return (0); } @@ -550,13 +560,13 @@ ngt_disconnect(hook_p hook) { const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); + crit_enter(); + lwkt_gettoken(&tty_token); if (hook != sc->hook) panic(__func__); - - NGTLOCK(sc); sc->hook = NULL; - NGTUNLOCK(sc); - + lwkt_reltoken(&tty_token); + crit_exit(); return (0); } @@ -572,20 +582,20 @@ ngt_shutdown(node_p node) { const sc_p sc = NG_NODE_PRIVATE(node); - NGTLOCK(sc); + crit_enter(); + lwkt_gettoken(&tty_token); if (!(sc->flags & FLG_DIE)) { - NGTUNLOCK(sc); + lwkt_reltoken(&tty_token); + crit_exit(); return (EOPNOTSUPP); } - NGTUNLOCK(sc); /* Free resources */ - _IF_DRAIN(&sc->outq); - mtx_destroy(&(sc)->outq.ifq_mtx); + IF_DRAIN(&sc->outq); m_freem(sc->m); - NG_NODE_UNREF(sc->node); kfree(sc, M_NETGRAPH); - + lwkt_reltoken(&tty_token); + crit_exit(); return (0); } @@ -606,25 +616,25 @@ ngt_rcvdata(hook_p hook, item_p item) NGI_GET_M(item, m); NG_FREE_ITEM(item); - IF_LOCK(&sc->outq); - if (_IF_QFULL(&sc->outq)) { - _IF_DROP(&sc->outq); - IF_UNLOCK(&sc->outq); + crit_enter(); + if (IF_QFULL(&sc->outq)) { + IF_DROP(&sc->outq); + crit_exit(); NG_FREE_M(m); return (ENOBUFS); } - _IF_ENQUEUE(&sc->outq, m); + IF_ENQUEUE(&sc->outq, m); qlen = sc->outq.ifq_len; - IF_UNLOCK(&sc->outq); + crit_exit(); /* * If qlen > 1, then we should already have a scheduled callout. */ if (qlen == 1) { - mtx_lock(&Giant); + lwkt_gettoken(&tty_token); ngt_start(sc->tp); - mtx_unlock(&Giant); + lwkt_reltoken(&tty_token); } return (0); @@ -688,31 +698,33 @@ ngt_mod_event(module_t mod, int event, void *data) { int error = 0; + lwkt_gettoken(&tty_token); switch (event) { case MOD_LOAD: - /* Register line discipline */ - mtx_lock(&Giant); + crit_enter(); if ((ngt_ldisc = ldisc_register(NETGRAPHDISC, &ngt_disc)) < 0) { - mtx_unlock(&Giant); + crit_exit(); log(LOG_ERR, "%s: can't register line discipline", __func__); + lwkt_reltoken(&tty_token); return (EIO); } - mtx_unlock(&Giant); + crit_exit(); break; case MOD_UNLOAD: /* Unregister line discipline */ - mtx_lock(&Giant); + crit_enter(); ldisc_deregister(ngt_ldisc); - mtx_unlock(&Giant); + crit_exit(); break; default: error = EOPNOTSUPP; break; } + lwkt_reltoken(&tty_token); return (error); } diff --git a/sys/netgraph7/ng_tty.h b/sys/netgraph7/tty/ng_tty.h similarity index 100% rename from sys/netgraph7/ng_tty.h rename to sys/netgraph7/tty/ng_tty.h