Print this page
3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero


   3  *
   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 /*
  22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.

  23  */
  24 

  25 #include <sys/zfs_context.h>
  26 
  27 list_t zfs_dbgmsgs;
  28 int zfs_dbgmsg_size;
  29 kmutex_t zfs_dbgmsgs_lock;
  30 int zfs_dbgmsg_maxsize = 1<<20; /* 1MB */
  31 
  32 void
  33 zfs_dbgmsg_init(void)
  34 {
  35         list_create(&zfs_dbgmsgs, sizeof (zfs_dbgmsg_t),
  36             offsetof(zfs_dbgmsg_t, zdm_node));
  37         mutex_init(&zfs_dbgmsgs_lock, NULL, MUTEX_DEFAULT, NULL);
  38 }
  39 
  40 void
  41 zfs_dbgmsg_fini(void)
  42 {
  43         zfs_dbgmsg_t *zdm;
  44 
  45         while ((zdm = list_remove_head(&zfs_dbgmsgs)) != NULL) {
  46                 int size = sizeof (zfs_dbgmsg_t) + strlen(zdm->zdm_msg);
  47                 kmem_free(zdm, size);
  48                 zfs_dbgmsg_size -= size;
  49         }
  50         mutex_destroy(&zfs_dbgmsgs_lock);
  51         ASSERT3U(zfs_dbgmsg_size, ==, 0);
  52 }
  53 
  54 /*
  55  * Print these messages by running:
  56  *      echo ::zfs_dbgmsg | mdb -k
  57  *
  58  * Monitor these messages by running:
  59  *      dtrace -q -n 'zfs-dbgmsg{printf("%s\n", stringof(arg0))}'
  60  */
  61 void
  62 zfs_dbgmsg(const char *fmt, ...)
  63 {
  64         int size;
  65         va_list adx;
  66         zfs_dbgmsg_t *zdm;
  67 
  68         va_start(adx, fmt);
  69         size = vsnprintf(NULL, 0, fmt, adx);
  70         va_end(adx);
  71 




   3  *
   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 /*
  22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012 by Delphix. All rights reserved.
  24  */
  25 
  26 
  27 #include <sys/zfs_context.h>
  28 
  29 list_t zfs_dbgmsgs;
  30 int zfs_dbgmsg_size;
  31 kmutex_t zfs_dbgmsgs_lock;
  32 int zfs_dbgmsg_maxsize = 1<<20; /* 1MB */
  33 
  34 void
  35 zfs_dbgmsg_init(void)
  36 {
  37         list_create(&zfs_dbgmsgs, sizeof (zfs_dbgmsg_t),
  38             offsetof(zfs_dbgmsg_t, zdm_node));
  39         mutex_init(&zfs_dbgmsgs_lock, NULL, MUTEX_DEFAULT, NULL);
  40 }
  41 
  42 void
  43 zfs_dbgmsg_fini(void)
  44 {
  45         zfs_dbgmsg_t *zdm;
  46 
  47         while ((zdm = list_remove_head(&zfs_dbgmsgs)) != NULL) {
  48                 int size = sizeof (zfs_dbgmsg_t) + strlen(zdm->zdm_msg);
  49                 kmem_free(zdm, size);
  50                 zfs_dbgmsg_size -= size;
  51         }
  52         mutex_destroy(&zfs_dbgmsgs_lock);
  53         ASSERT0(zfs_dbgmsg_size);
  54 }
  55 
  56 /*
  57  * Print these messages by running:
  58  * echo ::zfs_dbgmsg | mdb -k
  59  *
  60  * Monitor these messages by running:
  61  *      dtrace -q -n 'zfs-dbgmsg{printf("%s\n", stringof(arg0))}'
  62  */
  63 void
  64 zfs_dbgmsg(const char *fmt, ...)
  65 {
  66         int size;
  67         va_list adx;
  68         zfs_dbgmsg_t *zdm;
  69 
  70         va_start(adx, fmt);
  71         size = vsnprintf(NULL, 0, fmt, adx);
  72         va_end(adx);
  73