Print this page
9042 multiples of tty streams modules cause weirdness
Reviewed by: Randy Fishel <randyf@sibernet.com>
Reviewed by: Carlos Neira <cneirabustos@gmail.com>
Approved by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
re #13613 rb4516 Tunables needs volatile keyword


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  22 /*        All Rights Reserved   */
  23 
  24 
  25 /*
  26  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  * Copyright (c) 2016 by Delphix. All rights reserved.

  29  */



  30 
  31 #include <sys/types.h>
  32 #include <sys/sysmacros.h>
  33 #include <sys/param.h>
  34 #include <sys/errno.h>
  35 #include <sys/signal.h>
  36 #include <sys/proc.h>
  37 #include <sys/conf.h>
  38 #include <sys/cred.h>
  39 #include <sys/user.h>
  40 #include <sys/vnode.h>
  41 #include <sys/file.h>
  42 #include <sys/session.h>
  43 #include <sys/stream.h>
  44 #include <sys/strsubr.h>
  45 #include <sys/stropts.h>
  46 #include <sys/poll.h>
  47 #include <sys/systm.h>
  48 #include <sys/cpuvar.h>
  49 #include <sys/uio.h>


 203 kmutex_t        muxifier;       /* single-threads multiplexor creation */
 204 
 205 static void     *str_stack_init(netstackid_t stackid, netstack_t *ns);
 206 static void     str_stack_shutdown(netstackid_t stackid, void *arg);
 207 static void     str_stack_fini(netstackid_t stackid, void *arg);
 208 
 209 /*
 210  * run_queues is no longer used, but is kept in case some 3rd party
 211  * module/driver decides to use it.
 212  */
 213 int run_queues = 0;
 214 
 215 /*
 216  * sq_max_size is the depth of the syncq (in number of messages) before
 217  * qfill_syncq() starts QFULL'ing destination queues. As its primary
 218  * consumer - IP is no longer D_MTPERMOD, but there may be other
 219  * modules/drivers depend on this syncq flow control, we prefer to
 220  * choose a large number as the default value. For potential
 221  * performance gain, this value is tunable in /etc/system.
 222  */
 223 int sq_max_size = 10000;
 224 
 225 /*
 226  * The number of ciputctrl structures per syncq and stream we create when
 227  * needed.
 228  */
 229 int n_ciputctrl;
 230 int max_n_ciputctrl = 16;
 231 /*
 232  * If n_ciputctrl is < min_n_ciputctrl don't even create ciputctrl_cache.
 233  */
 234 int min_n_ciputctrl = 2;
 235 
 236 /*
 237  * Per-driver/module syncqs
 238  * ========================
 239  *
 240  * For drivers/modules that use PERMOD or outer syncqs we keep a list of
 241  * perdm structures, new entries being added (and new syncqs allocated) when
 242  * setq() encounters a module/driver with a streamtab that it hasn't seen
 243  * before.


2447                 }
2448                 sqtype &= ~SQ_COOC;
2449         }
2450 
2451         /* Synchronous Streams extended qinit structure */
2452         if (devflag & D_SYNCSTR)
2453                 qflag |= QSYNCSTR;
2454 
2455         /*
2456          * Private flag used by a transport module to indicate
2457          * to sockfs that it supports direct-access mode without
2458          * having to go through STREAMS.
2459          */
2460         if (devflag & _D_DIRECT) {
2461                 /* Reject unless the module is fully-MT (no perimeter) */
2462                 if ((qflag & QMT_TYPEMASK) != QMTSAFE)
2463                         goto bad;
2464                 qflag |= _QDIRECT;
2465         }
2466 











2467         *qflagp = qflag;
2468         *sqtypep = sqtype;
2469         return (0);
2470 
2471 bad:
2472         cmn_err(CE_WARN,
2473             "stropen: bad MT flags (0x%x) in driver '%s'",
2474             (int)(qflag & D_MTSAFETY_MASK),
2475             stp->st_rdinit->qi_minfo->mi_idname);
2476 
2477         return (EINVAL);
2478 }
2479 
2480 /*
2481  * Set the interface values for a pair of queues (qinit structure,
2482  * packet sizes, water marks).
2483  * setq assumes that the caller does not have a claim (entersq or claimq)
2484  * on the queue.
2485  */
2486 void




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  22 /*        All Rights Reserved   */
  23 

  24 /*
  25  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  * Copyright (c) 2016 by Delphix. All rights reserved.
  28  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
  29  */
  30 /*
  31  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  32  */
  33 
  34 #include <sys/types.h>
  35 #include <sys/sysmacros.h>
  36 #include <sys/param.h>
  37 #include <sys/errno.h>
  38 #include <sys/signal.h>
  39 #include <sys/proc.h>
  40 #include <sys/conf.h>
  41 #include <sys/cred.h>
  42 #include <sys/user.h>
  43 #include <sys/vnode.h>
  44 #include <sys/file.h>
  45 #include <sys/session.h>
  46 #include <sys/stream.h>
  47 #include <sys/strsubr.h>
  48 #include <sys/stropts.h>
  49 #include <sys/poll.h>
  50 #include <sys/systm.h>
  51 #include <sys/cpuvar.h>
  52 #include <sys/uio.h>


 206 kmutex_t        muxifier;       /* single-threads multiplexor creation */
 207 
 208 static void     *str_stack_init(netstackid_t stackid, netstack_t *ns);
 209 static void     str_stack_shutdown(netstackid_t stackid, void *arg);
 210 static void     str_stack_fini(netstackid_t stackid, void *arg);
 211 
 212 /*
 213  * run_queues is no longer used, but is kept in case some 3rd party
 214  * module/driver decides to use it.
 215  */
 216 int run_queues = 0;
 217 
 218 /*
 219  * sq_max_size is the depth of the syncq (in number of messages) before
 220  * qfill_syncq() starts QFULL'ing destination queues. As its primary
 221  * consumer - IP is no longer D_MTPERMOD, but there may be other
 222  * modules/drivers depend on this syncq flow control, we prefer to
 223  * choose a large number as the default value. For potential
 224  * performance gain, this value is tunable in /etc/system.
 225  */
 226 volatile int sq_max_size = 10000;
 227 
 228 /*
 229  * The number of ciputctrl structures per syncq and stream we create when
 230  * needed.
 231  */
 232 int n_ciputctrl;
 233 int max_n_ciputctrl = 16;
 234 /*
 235  * If n_ciputctrl is < min_n_ciputctrl don't even create ciputctrl_cache.
 236  */
 237 int min_n_ciputctrl = 2;
 238 
 239 /*
 240  * Per-driver/module syncqs
 241  * ========================
 242  *
 243  * For drivers/modules that use PERMOD or outer syncqs we keep a list of
 244  * perdm structures, new entries being added (and new syncqs allocated) when
 245  * setq() encounters a module/driver with a streamtab that it hasn't seen
 246  * before.


2450                 }
2451                 sqtype &= ~SQ_COOC;
2452         }
2453 
2454         /* Synchronous Streams extended qinit structure */
2455         if (devflag & D_SYNCSTR)
2456                 qflag |= QSYNCSTR;
2457 
2458         /*
2459          * Private flag used by a transport module to indicate
2460          * to sockfs that it supports direct-access mode without
2461          * having to go through STREAMS.
2462          */
2463         if (devflag & _D_DIRECT) {
2464                 /* Reject unless the module is fully-MT (no perimeter) */
2465                 if ((qflag & QMT_TYPEMASK) != QMTSAFE)
2466                         goto bad;
2467                 qflag |= _QDIRECT;
2468         }
2469 
2470         /*
2471          * Private flag used to indicate that a streams module should only
2472          * be pushed once. The TTY streams modules have this flag since if
2473          * libc believes itself to be an xpg4 process then it will
2474          * automatically and unconditionally push them when a PTS device is
2475          * opened. If an application is not aware of this then without this
2476          * flag we would end up with duplicate modules.
2477          */
2478         if (devflag & _D_SINGLE_INSTANCE)
2479                 qflag |= _QSINGLE_INSTANCE;
2480 
2481         *qflagp = qflag;
2482         *sqtypep = sqtype;
2483         return (0);
2484 
2485 bad:
2486         cmn_err(CE_WARN,
2487             "stropen: bad MT flags (0x%x) in driver '%s'",
2488             (int)(qflag & D_MTSAFETY_MASK),
2489             stp->st_rdinit->qi_minfo->mi_idname);
2490 
2491         return (EINVAL);
2492 }
2493 
2494 /*
2495  * Set the interface values for a pair of queues (qinit structure,
2496  * packet sizes, water marks).
2497  * setq assumes that the caller does not have a claim (entersq or claimq)
2498  * on the queue.
2499  */
2500 void