Print this page
XXXX adding PID information to netstat output

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/strsubr.c
          +++ new/usr/src/uts/common/os/strsubr.c
↓ open down ↓ 643 lines elided ↑ open up ↑
 644  644   */
 645  645  /* ARGSUSED */
 646  646  static int
 647  647  stream_head_constructor(void *buf, void *cdrarg, int kmflags)
 648  648  {
 649  649          stdata_t *stp = buf;
 650  650  
 651  651          mutex_init(&stp->sd_lock, NULL, MUTEX_DEFAULT, NULL);
 652  652          mutex_init(&stp->sd_reflock, NULL, MUTEX_DEFAULT, NULL);
 653  653          mutex_init(&stp->sd_qlock, NULL, MUTEX_DEFAULT, NULL);
      654 +        mutex_init(&stp->sd_pid_tree_lock, NULL, MUTEX_DEFAULT, NULL);
 654  655          cv_init(&stp->sd_monitor, NULL, CV_DEFAULT, NULL);
 655  656          cv_init(&stp->sd_iocmonitor, NULL, CV_DEFAULT, NULL);
 656  657          cv_init(&stp->sd_refmonitor, NULL, CV_DEFAULT, NULL);
 657  658          cv_init(&stp->sd_qcv, NULL, CV_DEFAULT, NULL);
 658  659          cv_init(&stp->sd_zcopy_wait, NULL, CV_DEFAULT, NULL);
      660 +        avl_create(&stp->sd_pid_tree, pid_node_comparator, sizeof (pid_node_t),
      661 +            offsetof(pid_node_t, pn_ref_link));
 659  662          stp->sd_wrq = NULL;
 660  663  
 661  664          return (0);
 662  665  }
 663  666  
 664  667  /* ARGSUSED */
 665  668  static void
 666  669  stream_head_destructor(void *buf, void *cdrarg)
 667  670  {
 668  671          stdata_t *stp = buf;
 669  672  
 670  673          mutex_destroy(&stp->sd_lock);
 671  674          mutex_destroy(&stp->sd_reflock);
 672  675          mutex_destroy(&stp->sd_qlock);
      676 +        mutex_destroy(&stp->sd_pid_tree_lock);
 673  677          cv_destroy(&stp->sd_monitor);
 674  678          cv_destroy(&stp->sd_iocmonitor);
 675  679          cv_destroy(&stp->sd_refmonitor);
 676  680          cv_destroy(&stp->sd_qcv);
 677  681          cv_destroy(&stp->sd_zcopy_wait);
      682 +        avl_destroy(&stp->sd_pid_tree);
 678  683  }
 679  684  
 680  685  /*
 681  686   * Constructor/destructor routines for the queue cache
 682  687   */
 683  688  /* ARGSUSED */
 684  689  static int
 685  690  queue_constructor(void *buf, void *cdrarg, int kmflags)
 686  691  {
 687  692          queinfo_t *qip = buf;
↓ open down ↓ 254 lines elided ↑ open up ↑
 942  947  }
 943  948  
 944  949  /*
 945  950   * Send the "sevent" set of signals to a process.
 946  951   * This might send more than one signal if the process is registered
 947  952   * for multiple events. The caller should pass in an sevent that only
 948  953   * includes the events for which the process has registered.
 949  954   */
 950  955  static void
 951  956  dosendsig(proc_t *proc, int events, int sevent, k_siginfo_t *info,
 952      -        uchar_t band, int error)
      957 +    uchar_t band, int error)
 953  958  {
 954  959          ASSERT(MUTEX_HELD(&proc->p_lock));
 955  960  
 956  961          info->si_band = 0;
 957  962          info->si_errno = 0;
 958  963  
 959  964          if (sevent & S_ERROR) {
 960  965                  sevent &= ~S_ERROR;
 961  966                  info->si_code = POLL_ERR;
 962  967                  info->si_errno = error;
↓ open down ↓ 1379 lines elided ↑ open up ↑
2342 2347          }
2343 2348          ASSERT(0);      /* should not reach here */
2344 2349  }
2345 2350  
2346 2351  /*
2347 2352   * Translate the device flags (from conf.h) to the corresponding
2348 2353   * qflag and sq_flag (type) values.
2349 2354   */
2350 2355  int
2351 2356  devflg_to_qflag(struct streamtab *stp, uint32_t devflag, uint32_t *qflagp,
2352      -        uint32_t *sqtypep)
     2357 +    uint32_t *sqtypep)
2353 2358  {
2354 2359          uint32_t qflag = 0;
2355 2360          uint32_t sqtype = 0;
2356 2361  
2357 2362          if (devflag & _D_OLD)
2358 2363                  goto bad;
2359 2364  
2360 2365          /* Inner perimeter presence and scope */
2361 2366          switch (devflag & D_MTINNER_MASK) {
2362 2367          case D_MP:
↓ open down ↓ 946 lines elided ↑ open up ↑
3309 3314  
3310 3315          return (stp);
3311 3316  }
3312 3317  
3313 3318  /*
3314 3319   * Free a stream head.
3315 3320   */
3316 3321  void
3317 3322  shfree(stdata_t *stp)
3318 3323  {
     3324 +        pid_node_t *pn;
     3325 +
3319 3326          ASSERT(MUTEX_NOT_HELD(&stp->sd_lock));
3320 3327  
3321 3328          stp->sd_wrq = NULL;
3322 3329  
3323 3330          mutex_enter(&stp->sd_qlock);
3324 3331          while (stp->sd_svcflags & STRS_SCHEDULED) {
3325 3332                  STRSTAT(strwaits);
3326 3333                  cv_wait(&stp->sd_qcv, &stp->sd_qlock);
3327 3334          }
3328 3335          mutex_exit(&stp->sd_qlock);
↓ open down ↓ 3 lines elided ↑ open up ↑
3332 3339                  SUMCHECK_CIPUTCTRL_COUNTS(stp->sd_ciputctrl,
3333 3340                      stp->sd_nciputctrl, 0);
3334 3341                  ASSERT(ciputctrl_cache != NULL);
3335 3342                  kmem_cache_free(ciputctrl_cache, stp->sd_ciputctrl);
3336 3343                  stp->sd_ciputctrl = NULL;
3337 3344                  stp->sd_nciputctrl = 0;
3338 3345          }
3339 3346          ASSERT(stp->sd_qhead == NULL);
3340 3347          ASSERT(stp->sd_qtail == NULL);
3341 3348          ASSERT(stp->sd_nqueues == 0);
     3349 +
     3350 +        mutex_enter(&stp->sd_pid_tree_lock);
     3351 +        while ((pn = avl_first(&stp->sd_pid_tree)) != NULL) {
     3352 +                avl_remove(&stp->sd_pid_tree, pn);
     3353 +                kmem_free(pn, sizeof (*pn));
     3354 +        }
     3355 +        mutex_exit(&stp->sd_pid_tree_lock);
     3356 +
3342 3357          kmem_cache_free(stream_head_cache, stp);
3343 3358  }
3344 3359  
     3360 +void
     3361 +sh_insert_pid(struct stdata *stp, pid_t pid)
     3362 +{
     3363 +        pid_node_t *pn, lookup_pn;
     3364 +        avl_index_t idx_pn;
     3365 +
     3366 +        lookup_pn.pn_pid = pid;
     3367 +        mutex_enter(&stp->sd_pid_tree_lock);
     3368 +        pn = avl_find(&stp->sd_pid_tree, &lookup_pn, &idx_pn);
     3369 +
     3370 +        if (pn != NULL) {
     3371 +                pn->pn_count++;
     3372 +        } else {
     3373 +                pn = kmem_zalloc(sizeof (*pn), KM_SLEEP);
     3374 +                pn->pn_pid = pid;
     3375 +                pn->pn_count = 1;
     3376 +                avl_insert(&stp->sd_pid_tree, pn, idx_pn);
     3377 +        }
     3378 +        mutex_exit(&stp->sd_pid_tree_lock);
     3379 +}
     3380 +
     3381 +void
     3382 +sh_remove_pid(struct stdata *stp, pid_t pid)
     3383 +{
     3384 +        pid_node_t *pn, lookup_pn;
     3385 +
     3386 +        lookup_pn.pn_pid = pid;
     3387 +        mutex_enter(&stp->sd_pid_tree_lock);
     3388 +        pn = avl_find(&stp->sd_pid_tree, &lookup_pn, NULL);
     3389 +
     3390 +        if (pn != NULL) {
     3391 +                if (pn->pn_count > 1) {
     3392 +                        pn->pn_count--;
     3393 +                } else {
     3394 +                        avl_remove(&stp->sd_pid_tree, pn);
     3395 +                        kmem_free(pn, sizeof (*pn));
     3396 +                }
     3397 +        }
     3398 +        mutex_exit(&stp->sd_pid_tree_lock);
     3399 +}
     3400 +
     3401 +mblk_t *
     3402 +sh_get_pid_mblk(struct stdata *stp)
     3403 +{
     3404 +        mblk_t *mblk;
     3405 +        ulong_t sz, n;
     3406 +        pid_t *pids;
     3407 +        pid_node_t *pn;
     3408 +        conn_pid_info_t *cpi;
     3409 +
     3410 +        mutex_enter(&stp->sd_pid_tree_lock);
     3411 +
     3412 +        n = avl_numnodes(&stp->sd_pid_tree);
     3413 +        sz = sizeof (conn_pid_info_t);
     3414 +        sz += (n > 1) ? ((n - 1) * sizeof (pid_t)) : 0;
     3415 +        if ((mblk = allocb(sz, BPRI_HI)) == NULL) {
     3416 +                mutex_exit(&stp->sd_pid_tree_lock);
     3417 +                return (NULL);
     3418 +        }
     3419 +        mblk->b_wptr += sz;
     3420 +        cpi = (conn_pid_info_t *)mblk->b_datap->db_base;
     3421 +        cpi->cpi_magic = CONN_PID_INFO_MGC;
     3422 +        cpi->cpi_contents = CONN_PID_INFO_XTI;
     3423 +        cpi->cpi_pids_cnt = n;
     3424 +        cpi->cpi_tot_size = sz;
     3425 +        cpi->cpi_pids[0] = 0;
     3426 +
     3427 +        if (cpi->cpi_pids_cnt > 0) {
     3428 +                pids = cpi->cpi_pids;
     3429 +                for (pn = avl_first(&stp->sd_pid_tree); pn != NULL;
     3430 +                    pids++, pn = AVL_NEXT(&stp->sd_pid_tree, pn))
     3431 +                        *pids = pn->pn_pid;
     3432 +        }
     3433 +        mutex_exit(&stp->sd_pid_tree_lock);
     3434 +        return (mblk);
     3435 +}
     3436 +
3345 3437  /*
3346 3438   * Allocate a pair of queues and a syncq for the pair
3347 3439   */
3348 3440  queue_t *
3349 3441  allocq(void)
3350 3442  {
3351 3443          queinfo_t *qip;
3352 3444          queue_t *qp, *wqp;
3353 3445          syncq_t *sq;
3354 3446  
↓ open down ↓ 4723 lines elided ↑ open up ↑
8078 8170  strflushrq(vnode_t *vp, int flag)
8079 8171  {
8080 8172          struct stdata *stp = vp->v_stream;
8081 8173  
8082 8174          mutex_enter(&stp->sd_lock);
8083 8175          flushq(_RD(stp->sd_wrq), flag);
8084 8176          mutex_exit(&stp->sd_lock);
8085 8177  }
8086 8178  
8087 8179  void
8088      -strsetrputhooks(vnode_t *vp, uint_t flags,
8089      -                msgfunc_t protofunc, msgfunc_t miscfunc)
     8180 +strsetrputhooks(vnode_t *vp, uint_t flags, msgfunc_t protofunc,
     8181 +    msgfunc_t miscfunc)
8090 8182  {
8091 8183          struct stdata *stp = vp->v_stream;
8092 8184  
8093 8185          mutex_enter(&stp->sd_lock);
8094 8186  
8095 8187          if (protofunc == NULL)
8096 8188                  stp->sd_rprotofunc = strrput_proto;
8097 8189          else
8098 8190                  stp->sd_rprotofunc = protofunc;
8099 8191  
↓ open down ↓ 697 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX