Print this page
    
3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
    
      
        | Split | Close | 
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/fs/zfs/zfs_debug.c
          +++ new/usr/src/uts/common/fs/zfs/zfs_debug.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  
    | ↓ open down ↓ | 12 lines elided | ↑ open up ↑ | 
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
       23 + * Copyright (c) 2012 by Delphix. All rights reserved.
  23   24   */
  24   25  
       26 +
  25   27  #include <sys/zfs_context.h>
  26   28  
  27   29  list_t zfs_dbgmsgs;
  28   30  int zfs_dbgmsg_size;
  29   31  kmutex_t zfs_dbgmsgs_lock;
  30   32  int zfs_dbgmsg_maxsize = 1<<20; /* 1MB */
  31   33  
  32   34  void
  33   35  zfs_dbgmsg_init(void)
  34   36  {
  35   37          list_create(&zfs_dbgmsgs, sizeof (zfs_dbgmsg_t),
  36   38              offsetof(zfs_dbgmsg_t, zdm_node));
  37   39          mutex_init(&zfs_dbgmsgs_lock, NULL, MUTEX_DEFAULT, NULL);
  38   40  }
  39   41  
  40   42  void
  
    | ↓ open down ↓ | 6 lines elided | ↑ open up ↑ | 
  41   43  zfs_dbgmsg_fini(void)
  42   44  {
  43   45          zfs_dbgmsg_t *zdm;
  44   46  
  45   47          while ((zdm = list_remove_head(&zfs_dbgmsgs)) != NULL) {
  46   48                  int size = sizeof (zfs_dbgmsg_t) + strlen(zdm->zdm_msg);
  47   49                  kmem_free(zdm, size);
  48   50                  zfs_dbgmsg_size -= size;
  49   51          }
  50   52          mutex_destroy(&zfs_dbgmsgs_lock);
  51      -        ASSERT3U(zfs_dbgmsg_size, ==, 0);
       53 +        ASSERT0(zfs_dbgmsg_size);
  52   54  }
  53   55  
  54   56  /*
  55   57   * Print these messages by running:
  56      - *      echo ::zfs_dbgmsg | mdb -k
       58 + * echo ::zfs_dbgmsg | mdb -k
  57   59   *
  58   60   * Monitor these messages by running:
  59   61   *      dtrace -q -n 'zfs-dbgmsg{printf("%s\n", stringof(arg0))}'
  60   62   */
  61   63  void
  62   64  zfs_dbgmsg(const char *fmt, ...)
  63   65  {
  64   66          int size;
  65   67          va_list adx;
  66   68          zfs_dbgmsg_t *zdm;
  67   69  
  68   70          va_start(adx, fmt);
  69   71          size = vsnprintf(NULL, 0, fmt, adx);
  70   72          va_end(adx);
  71   73  
  72   74          /*
  73   75           * There is one byte of string in sizeof (zfs_dbgmsg_t), used
  74   76           * for the terminating null.
  75   77           */
  76   78          zdm = kmem_alloc(sizeof (zfs_dbgmsg_t) + size, KM_SLEEP);
  77   79          zdm->zdm_timestamp = gethrestime_sec();
  78   80  
  79   81          va_start(adx, fmt);
  80   82          (void) vsnprintf(zdm->zdm_msg, size + 1, fmt, adx);
  81   83          va_end(adx);
  82   84  
  83   85          DTRACE_PROBE1(zfs__dbgmsg, char *, zdm->zdm_msg);
  84   86  
  85   87          mutex_enter(&zfs_dbgmsgs_lock);
  86   88          list_insert_tail(&zfs_dbgmsgs, zdm);
  87   89          zfs_dbgmsg_size += sizeof (zfs_dbgmsg_t) + size;
  88   90          while (zfs_dbgmsg_size > zfs_dbgmsg_maxsize) {
  89   91                  zdm = list_remove_head(&zfs_dbgmsgs);
  90   92                  size = sizeof (zfs_dbgmsg_t) + strlen(zdm->zdm_msg);
  91   93                  kmem_free(zdm, size);
  92   94                  zfs_dbgmsg_size -= size;
  93   95          }
  94   96          mutex_exit(&zfs_dbgmsgs_lock);
  95   97  }
  
    | ↓ open down ↓ | 29 lines elided | ↑ open up ↑ | 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX