Print this page
Spencer's first if/else try

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/vnode.c
          +++ new/usr/src/uts/common/fs/vnode.c
↓ open down ↓ 835 lines elided ↑ open up ↑
 836  836   * To avoid race conditions, the v_count is left at 1 for
 837  837   * the call to VOP_INACTIVE. This prevents another thread
 838  838   * from reclaiming and releasing the vnode *before* the
 839  839   * VOP_INACTIVE routine has a chance to destroy the vnode.
 840  840   * We can't have more than 1 thread calling VOP_INACTIVE
 841  841   * on a vnode.
 842  842   */
 843  843  void
 844  844  vn_rele(vnode_t *vp)
 845  845  {
 846      -        VERIFY(vp->v_count > 0);
 847  846          mutex_enter(&vp->v_lock);
 848  847          if (vp->v_count == 1) {
 849  848                  mutex_exit(&vp->v_lock);
 850  849                  VOP_INACTIVE(vp, CRED(), NULL);
 851  850                  return;
 852  851          }
      852 +        else{
      853 +                VERIFY(vp->v_count > 0);
      854 +        }
 853  855          VN_RELE_LOCKED(vp);
 854  856          mutex_exit(&vp->v_lock);
 855  857  }
 856  858  
 857  859  void
 858  860  vn_phantom_rele(vnode_t *vp)
 859  861  {
 860      -        VERIFY(vp->v_count > 0);
 861      -
 862  862          mutex_enter(&vp->v_lock);
 863      -        VERIFY3U(vp->v_count, >=, vp->v_phantom_count);
      863 +
 864  864          vp->v_phantom_count--;
 865  865          DTRACE_PROBE1(vn__phantom_rele, vnode_t *, vp);
 866  866          if (vp->v_count == 1) {
 867  867                  ASSERT0(vp->v_phantom_count);
 868  868                  mutex_exit(&vp->v_lock);
 869  869                  VOP_INACTIVE(vp, CRED(), NULL);
 870  870                  return;
      871 +        }else{
      872 +                VERIFY(vp->v_count > 0);
      873 +                VERIFY3U(vp->v_count, >=, vp->v_phantom_count);
 871  874          }
 872  875          VN_RELE_LOCKED(vp);
 873  876          mutex_exit(&vp->v_lock);
 874  877  }
 875  878  
 876  879  /*
 877  880   * Return the number of non-phantom holds. Things such as portfs will use
 878  881   * phantom holds to prevent it from blocking filesystems from mounting over
 879  882   * watched directories.
 880  883   */
↓ open down ↓ 6 lines elided ↑ open up ↑
 887  890  
 888  891  /*
 889  892   * Release a vnode referenced by the DNLC. Multiple DNLC references are treated
 890  893   * as a single reference, so v_count is not decremented until the last DNLC hold
 891  894   * is released. This makes it possible to distinguish vnodes that are referenced
 892  895   * only by the DNLC.
 893  896   */
 894  897  void
 895  898  vn_rele_dnlc(vnode_t *vp)
 896  899  {
 897      -        VERIFY((vp->v_count > 0) && (vp->v_count_dnlc > 0));
 898  900          mutex_enter(&vp->v_lock);
      901 +
 899  902          if (--vp->v_count_dnlc == 0) {
 900  903                  if (vp->v_count == 1) {
 901  904                          mutex_exit(&vp->v_lock);
 902  905                          VOP_INACTIVE(vp, CRED(), NULL);
 903  906                          return;
 904  907                  }
 905  908                  VN_RELE_LOCKED(vp);
      909 +        }else{
      910 +                VERIFY((vp->v_count > 0) && (vp->v_count_dnlc > 0));
 906  911          }
 907  912          mutex_exit(&vp->v_lock);
 908  913  }
 909  914  
 910  915  /*
 911  916   * Like vn_rele() except that it clears v_stream under v_lock.
 912  917   * This is used by sockfs when it dismantles the association between
 913  918   * the sockfs node and the vnode in the underlying file system.
 914  919   * v_lock has to be held to prevent a thread coming through the lookupname
 915  920   * path from accessing a stream head that is going away.
 916  921   */
 917  922  void
 918  923  vn_rele_stream(vnode_t *vp)
 919  924  {
 920      -        VERIFY(vp->v_count > 0);
 921  925          mutex_enter(&vp->v_lock);
      926 +
 922  927          vp->v_stream = NULL;
 923  928          if (vp->v_count == 1) {
 924  929                  mutex_exit(&vp->v_lock);
 925  930                  VOP_INACTIVE(vp, CRED(), NULL);
 926  931                  return;
 927  932          }
      933 +        else{
      934 +                VERIFY(vp->v_count > 0);
      935 +        }
 928  936          VN_RELE_LOCKED(vp);
 929  937          mutex_exit(&vp->v_lock);
 930  938  }
 931  939  
 932  940  static void
 933  941  vn_rele_inactive(vnode_t *vp)
 934  942  {
 935  943          VOP_INACTIVE(vp, CRED(), NULL);
 936  944  }
 937  945  
↓ open down ↓ 3 lines elided ↑ open up ↑
 941  949   * the file system as a result of releasing the vnode. Note, file systems
 942  950   * already have to handle the race where the vnode is incremented before the
 943  951   * inactive routine is called and does its locking.
 944  952   *
 945  953   * Warning: Excessive use of this routine can lead to performance problems.
 946  954   * This is because taskqs throttle back allocation if too many are created.
 947  955   */
 948  956  void
 949  957  vn_rele_async(vnode_t *vp, taskq_t *taskq)
 950  958  {
 951      -        VERIFY(vp->v_count > 0);
 952  959          mutex_enter(&vp->v_lock);
 953  960          if (vp->v_count == 1) {
 954  961                  mutex_exit(&vp->v_lock);
 955  962                  VERIFY(taskq_dispatch(taskq, (task_func_t *)vn_rele_inactive,
 956  963                      vp, TQ_SLEEP) != TASKQID_INVALID);
 957  964                  return;
 958  965          }
      966 +        else{
      967 +                VERIFY(vp->v_count > 0);
      968 +        }
 959  969          VN_RELE_LOCKED(vp);
 960  970          mutex_exit(&vp->v_lock);
 961  971  }
 962  972  
 963  973  int
 964  974  vn_open(
 965  975          char *pnamep,
 966  976          enum uio_seg seg,
 967  977          int filemode,
 968  978          int createmode,
↓ open down ↓ 3964 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX