Print this page
XXXX adding PID information to netstat output

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/sockfs/sockcommon.c
          +++ new/usr/src/uts/common/fs/sockfs/sockcommon.c
↓ open down ↓ 467 lines elided ↑ open up ↑
 468  468          so->so_rcv_last_head    = NULL;
 469  469          so->so_rcv_wanted       = 0;
 470  470          so->so_rcv_timer_interval = SOCKET_NO_RCVTIMER;
 471  471          so->so_rcv_timer_tid    = 0;
 472  472          so->so_rcv_thresh       = 0;
 473  473  
 474  474          list_create(&so->so_acceptq_list, sizeof (struct sonode),
 475  475              offsetof(struct sonode, so_acceptq_node));
 476  476          list_create(&so->so_acceptq_defer, sizeof (struct sonode),
 477  477              offsetof(struct sonode, so_acceptq_node));
      478 +        avl_create(&so->so_pid_tree, pid_node_comparator, sizeof (pid_node_t),
      479 +            offsetof(pid_node_t, pn_ref_link));
 478  480          list_link_init(&so->so_acceptq_node);
 479  481          so->so_acceptq_len      = 0;
 480  482          so->so_backlog          = 0;
 481  483          so->so_listener         = NULL;
 482  484  
 483  485          so->so_snd_qfull        = B_FALSE;
 484  486  
 485  487          so->so_filter_active    = 0;
 486  488          so->so_filter_tx        = 0;
 487  489          so->so_filter_defertime = 0;
 488  490          so->so_filter_top       = NULL;
 489  491          so->so_filter_bottom    = NULL;
 490  492  
 491  493          mutex_init(&so->so_lock, NULL, MUTEX_DEFAULT, NULL);
 492  494          mutex_init(&so->so_acceptq_lock, NULL, MUTEX_DEFAULT, NULL);
      495 +        mutex_init(&so->so_pid_tree_lock, NULL, MUTEX_DEFAULT, NULL);
 493  496          rw_init(&so->so_fallback_rwlock, NULL, RW_DEFAULT, NULL);
 494  497          cv_init(&so->so_state_cv, NULL, CV_DEFAULT, NULL);
 495  498          cv_init(&so->so_single_cv, NULL, CV_DEFAULT, NULL);
 496  499          cv_init(&so->so_read_cv, NULL, CV_DEFAULT, NULL);
 497  500  
 498  501          cv_init(&so->so_acceptq_cv, NULL, CV_DEFAULT, NULL);
 499  502          cv_init(&so->so_snd_cv, NULL, CV_DEFAULT, NULL);
 500  503          cv_init(&so->so_rcv_cv, NULL, CV_DEFAULT, NULL);
 501  504          cv_init(&so->so_copy_cv, NULL, CV_DEFAULT, NULL);
 502  505          cv_init(&so->so_closing_cv, NULL, CV_DEFAULT, NULL);
↓ open down ↓ 10 lines elided ↑ open up ↑
 513  516  
 514  517          ASSERT(so->so_priv == NULL);
 515  518          ASSERT(so->so_peercred == NULL);
 516  519  
 517  520          ASSERT(so->so_oobmsg == NULL);
 518  521  
 519  522          ASSERT(so->so_rcv_q_head == NULL);
 520  523  
 521  524          list_destroy(&so->so_acceptq_list);
 522  525          list_destroy(&so->so_acceptq_defer);
      526 +        avl_destroy(&so->so_pid_tree);
 523  527          ASSERT(!list_link_active(&so->so_acceptq_node));
 524  528          ASSERT(so->so_listener == NULL);
 525  529  
 526  530          ASSERT(so->so_filter_active == 0);
 527  531          ASSERT(so->so_filter_tx == 0);
 528  532          ASSERT(so->so_filter_top == NULL);
 529  533          ASSERT(so->so_filter_bottom == NULL);
 530  534  
 531  535          ASSERT(vp->v_data == so);
 532  536          ASSERT(vn_matchops(vp, socket_vnodeops));
 533  537  
 534  538          vn_free(vp);
 535  539  
 536  540          mutex_destroy(&so->so_lock);
 537  541          mutex_destroy(&so->so_acceptq_lock);
      542 +        mutex_destroy(&so->so_pid_tree_lock);
 538  543          rw_destroy(&so->so_fallback_rwlock);
 539  544  
 540  545          cv_destroy(&so->so_state_cv);
 541  546          cv_destroy(&so->so_single_cv);
 542  547          cv_destroy(&so->so_read_cv);
 543  548          cv_destroy(&so->so_acceptq_cv);
 544  549          cv_destroy(&so->so_snd_cv);
 545  550          cv_destroy(&so->so_rcv_cv);
 546  551          cv_destroy(&so->so_closing_cv);
 547  552  }
↓ open down ↓ 71 lines elided ↑ open up ↑
 619  624  
 620  625          so->so_direct = NULL;
 621  626  
 622  627          vn_exists(vp);
 623  628  }
 624  629  
 625  630  void
 626  631  sonode_fini(struct sonode *so)
 627  632  {
 628  633          vnode_t *vp;
      634 +        pid_node_t *pn;
 629  635  
 630  636          ASSERT(so->so_count == 0);
 631  637  
 632  638          if (so->so_rcv_timer_tid) {
 633  639                  ASSERT(MUTEX_NOT_HELD(&so->so_lock));
 634  640                  (void) untimeout(so->so_rcv_timer_tid);
 635  641                  so->so_rcv_timer_tid = 0;
 636  642          }
 637  643  
 638  644          if (so->so_poll_list.ph_list != NULL) {
↓ open down ↓ 8 lines elided ↑ open up ↑
 647  653          vn_invalid(vp);
 648  654  
 649  655          if (so->so_peercred != NULL) {
 650  656                  crfree(so->so_peercred);
 651  657                  so->so_peercred = NULL;
 652  658          }
 653  659          /* Detach and destroy filters */
 654  660          if (so->so_filter_top != NULL)
 655  661                  sof_sonode_cleanup(so);
 656  662  
      663 +        mutex_enter(&so->so_pid_tree_lock);
      664 +        while ((pn = avl_first(&so->so_pid_tree)) != NULL) {
      665 +                avl_remove(&so->so_pid_tree, pn);
      666 +                kmem_free(pn, sizeof (*pn));
      667 +        }
      668 +        mutex_exit(&so->so_pid_tree_lock);
      669 +
 657  670          ASSERT(list_is_empty(&so->so_acceptq_list));
 658  671          ASSERT(list_is_empty(&so->so_acceptq_defer));
 659  672          ASSERT(!list_link_active(&so->so_acceptq_node));
 660  673  
 661  674          ASSERT(so->so_rcv_queued == 0);
 662  675          ASSERT(so->so_rcv_q_head == NULL);
 663  676          ASSERT(so->so_rcv_q_last_head == NULL);
 664  677          ASSERT(so->so_rcv_head == NULL);
 665  678          ASSERT(so->so_rcv_last_head == NULL);
      679 +}
      680 +
      681 +void
      682 +sonode_insert_pid(struct sonode *so, pid_t pid)
      683 +{
      684 +        pid_node_t      *pn, lookup_pn;
      685 +        avl_index_t     idx_pn;
      686 +
      687 +        lookup_pn.pn_pid = pid;
      688 +        mutex_enter(&so->so_pid_tree_lock);
      689 +        pn = avl_find(&so->so_pid_tree, &lookup_pn, &idx_pn);
      690 +
      691 +        if (pn != NULL) {
      692 +                pn->pn_count++;
      693 +        } else {
      694 +                pn = kmem_zalloc(sizeof (*pn), KM_SLEEP);
      695 +                pn->pn_pid = pid;
      696 +                pn->pn_count = 1;
      697 +                avl_insert(&so->so_pid_tree, pn, idx_pn);
      698 +        }
      699 +        mutex_exit(&so->so_pid_tree_lock);
      700 +}
      701 +
      702 +void
      703 +sonode_remove_pid(struct sonode *so, pid_t pid)
      704 +{
      705 +        pid_node_t *pn, lookup_pn;
      706 +
      707 +        lookup_pn.pn_pid = pid;
      708 +        mutex_enter(&so->so_pid_tree_lock);
      709 +        pn = avl_find(&so->so_pid_tree, &lookup_pn, NULL);
      710 +
      711 +        if (pn != NULL) {
      712 +                if (pn->pn_count > 1) {
      713 +                                pn->pn_count--;
      714 +                } else {
      715 +                        avl_remove(&so->so_pid_tree, pn);
      716 +                        kmem_free(pn, sizeof (*pn));
      717 +                }
      718 +        }
      719 +        mutex_exit(&so->so_pid_tree_lock);
 666  720  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX