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/bpobj.c
          +++ new/usr/src/uts/common/fs/zfs/bpobj.c
↓ 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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright (c) 2011 by Delphix. All rights reserved.
       23 + * Copyright (c) 2012 by Delphix. All rights reserved.
  24   24   */
  25   25  
  26   26  #include <sys/bpobj.h>
  27   27  #include <sys/zfs_context.h>
  28   28  #include <sys/refcount.h>
  29   29  #include <sys/dsl_pool.h>
  30   30  
  31   31  uint64_t
  32   32  bpobj_alloc(objset_t *os, int blocksize, dmu_tx_t *tx)
  33   33  {
↓ open down ↓ 12 lines elided ↑ open up ↑
  46   46  
  47   47  void
  48   48  bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx)
  49   49  {
  50   50          int64_t i;
  51   51          bpobj_t bpo;
  52   52          dmu_object_info_t doi;
  53   53          int epb;
  54   54          dmu_buf_t *dbuf = NULL;
  55   55  
  56      -        VERIFY3U(0, ==, bpobj_open(&bpo, os, obj));
       56 +        VERIFY0(bpobj_open(&bpo, os, obj));
  57   57  
  58   58          mutex_enter(&bpo.bpo_lock);
  59   59  
  60   60          if (!bpo.bpo_havesubobj || bpo.bpo_phys->bpo_subobjs == 0)
  61   61                  goto out;
  62   62  
  63      -        VERIFY3U(0, ==, dmu_object_info(os, bpo.bpo_phys->bpo_subobjs, &doi));
       63 +        VERIFY0(dmu_object_info(os, bpo.bpo_phys->bpo_subobjs, &doi));
  64   64          epb = doi.doi_data_block_size / sizeof (uint64_t);
  65   65  
  66   66          for (i = bpo.bpo_phys->bpo_num_subobjs - 1; i >= 0; i--) {
  67   67                  uint64_t *objarray;
  68   68                  uint64_t offset, blkoff;
  69   69  
  70   70                  offset = i * sizeof (uint64_t);
  71   71                  blkoff = P2PHASE(i, epb);
  72   72  
  73   73                  if (dbuf == NULL || dbuf->db_offset > offset) {
  74   74                          if (dbuf)
  75   75                                  dmu_buf_rele(dbuf, FTAG);
  76      -                        VERIFY3U(0, ==, dmu_buf_hold(os,
       76 +                        VERIFY0(dmu_buf_hold(os,
  77   77                              bpo.bpo_phys->bpo_subobjs, offset, FTAG, &dbuf, 0));
  78   78                  }
  79   79  
  80   80                  ASSERT3U(offset, >=, dbuf->db_offset);
  81   81                  ASSERT3U(offset, <, dbuf->db_offset + dbuf->db_size);
  82   82  
  83   83                  objarray = dbuf->db_data;
  84   84                  bpobj_free(os, objarray[blkoff], tx);
  85   85          }
  86   86          if (dbuf) {
  87   87                  dmu_buf_rele(dbuf, FTAG);
  88   88                  dbuf = NULL;
  89   89          }
  90      -        VERIFY3U(0, ==, dmu_object_free(os, bpo.bpo_phys->bpo_subobjs, tx));
       90 +        VERIFY0(dmu_object_free(os, bpo.bpo_phys->bpo_subobjs, tx));
  91   91  
  92   92  out:
  93   93          mutex_exit(&bpo.bpo_lock);
  94   94          bpobj_close(&bpo);
  95   95  
  96      -        VERIFY3U(0, ==, dmu_object_free(os, obj, tx));
       96 +        VERIFY0(dmu_object_free(os, obj, tx));
  97   97  }
  98   98  
  99   99  int
 100  100  bpobj_open(bpobj_t *bpo, objset_t *os, uint64_t object)
 101  101  {
 102  102          dmu_object_info_t doi;
 103  103          int err;
 104  104  
 105  105          err = dmu_object_info(os, object, &doi);
 106  106          if (err)
↓ open down ↓ 90 lines elided ↑ open up ↑
 197  197                          bpo->bpo_phys->bpo_num_blkptrs--;
 198  198                          ASSERT3S(bpo->bpo_phys->bpo_num_blkptrs, >=, 0);
 199  199                  }
 200  200          }
 201  201          if (dbuf) {
 202  202                  dmu_buf_rele(dbuf, FTAG);
 203  203                  dbuf = NULL;
 204  204          }
 205  205          if (free) {
 206  206                  i++;
 207      -                VERIFY3U(0, ==, dmu_free_range(bpo->bpo_os, bpo->bpo_object,
      207 +                VERIFY0(dmu_free_range(bpo->bpo_os, bpo->bpo_object,
 208  208                      i * sizeof (blkptr_t), -1ULL, tx));
 209  209          }
 210  210          if (err || !bpo->bpo_havesubobj || bpo->bpo_phys->bpo_subobjs == 0)
 211  211                  goto out;
 212  212  
 213  213          ASSERT(bpo->bpo_havecomp);
 214  214          err = dmu_object_info(bpo->bpo_os, bpo->bpo_phys->bpo_subobjs, &doi);
 215  215          if (err) {
 216  216                  mutex_exit(&bpo->bpo_lock);
 217  217                  return (err);
↓ open down ↓ 27 lines elided ↑ open up ↑
 245  245                  if (err)
 246  246                          break;
 247  247                  if (free) {
 248  248                          err = bpobj_space(&sublist,
 249  249                              &used_before, &comp_before, &uncomp_before);
 250  250                          if (err)
 251  251                                  break;
 252  252                  }
 253  253                  err = bpobj_iterate_impl(&sublist, func, arg, tx, free);
 254  254                  if (free) {
 255      -                        VERIFY3U(0, ==, bpobj_space(&sublist,
      255 +                        VERIFY0(bpobj_space(&sublist,
 256  256                              &used_after, &comp_after, &uncomp_after));
 257  257                          bpo->bpo_phys->bpo_bytes -= used_before - used_after;
 258  258                          ASSERT3S(bpo->bpo_phys->bpo_bytes, >=, 0);
 259  259                          bpo->bpo_phys->bpo_comp -= comp_before - comp_after;
 260  260                          bpo->bpo_phys->bpo_uncomp -=
 261  261                              uncomp_before - uncomp_after;
 262  262                  }
 263  263  
 264  264                  bpobj_close(&sublist);
 265  265                  if (err)
↓ open down ↓ 5 lines elided ↑ open up ↑
 271  271                                  break;
 272  272                          bpo->bpo_phys->bpo_num_subobjs--;
 273  273                          ASSERT3S(bpo->bpo_phys->bpo_num_subobjs, >=, 0);
 274  274                  }
 275  275          }
 276  276          if (dbuf) {
 277  277                  dmu_buf_rele(dbuf, FTAG);
 278  278                  dbuf = NULL;
 279  279          }
 280  280          if (free) {
 281      -                VERIFY3U(0, ==, dmu_free_range(bpo->bpo_os,
      281 +                VERIFY0(dmu_free_range(bpo->bpo_os,
 282  282                      bpo->bpo_phys->bpo_subobjs,
 283  283                      (i + 1) * sizeof (uint64_t), -1ULL, tx));
 284  284          }
 285  285  
 286  286  out:
 287  287          /* If there are no entries, there should be no bytes. */
 288  288          ASSERT(bpo->bpo_phys->bpo_num_blkptrs > 0 ||
 289  289              (bpo->bpo_havesubobj && bpo->bpo_phys->bpo_num_subobjs > 0) ||
 290  290              bpo->bpo_phys->bpo_bytes == 0);
 291  291  
↓ open down ↓ 22 lines elided ↑ open up ↑
 314  314  
 315  315  void
 316  316  bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx)
 317  317  {
 318  318          bpobj_t subbpo;
 319  319          uint64_t used, comp, uncomp, subsubobjs;
 320  320  
 321  321          ASSERT(bpo->bpo_havesubobj);
 322  322          ASSERT(bpo->bpo_havecomp);
 323  323  
 324      -        VERIFY3U(0, ==, bpobj_open(&subbpo, bpo->bpo_os, subobj));
 325      -        VERIFY3U(0, ==, bpobj_space(&subbpo, &used, &comp, &uncomp));
      324 +        VERIFY0(bpobj_open(&subbpo, bpo->bpo_os, subobj));
      325 +        VERIFY0(bpobj_space(&subbpo, &used, &comp, &uncomp));
 326  326  
 327  327          if (used == 0) {
 328  328                  /* No point in having an empty subobj. */
 329  329                  bpobj_close(&subbpo);
 330  330                  bpobj_free(bpo->bpo_os, subobj, tx);
 331  331                  return;
 332  332          }
 333  333  
 334  334          dmu_buf_will_dirty(bpo->bpo_dbuf, tx);
 335  335          if (bpo->bpo_phys->bpo_subobjs == 0) {
↓ open down ↓ 9 lines elided ↑ open up ↑
 345  345  
 346  346          /*
 347  347           * If subobj has only one block of subobjs, then move subobj's
 348  348           * subobjs to bpo's subobj list directly.  This reduces
 349  349           * recursion in bpobj_iterate due to nested subobjs.
 350  350           */
 351  351          subsubobjs = subbpo.bpo_phys->bpo_subobjs;
 352  352          if (subsubobjs != 0) {
 353  353                  dmu_object_info_t doi;
 354  354  
 355      -                VERIFY3U(0, ==, dmu_object_info(bpo->bpo_os, subsubobjs, &doi));
      355 +                VERIFY0(dmu_object_info(bpo->bpo_os, subsubobjs, &doi));
 356  356                  if (doi.doi_max_offset == doi.doi_data_block_size) {
 357  357                          dmu_buf_t *subdb;
 358  358                          uint64_t numsubsub = subbpo.bpo_phys->bpo_num_subobjs;
 359  359  
 360      -                        VERIFY3U(0, ==, dmu_buf_hold(bpo->bpo_os, subsubobjs,
      360 +                        VERIFY0(dmu_buf_hold(bpo->bpo_os, subsubobjs,
 361  361                              0, FTAG, &subdb, 0));
 362  362                          dmu_write(bpo->bpo_os, bpo->bpo_phys->bpo_subobjs,
 363  363                              bpo->bpo_phys->bpo_num_subobjs * sizeof (subobj),
 364  364                              numsubsub * sizeof (subobj), subdb->db_data, tx);
 365  365                          dmu_buf_rele(subdb, FTAG);
 366  366                          bpo->bpo_phys->bpo_num_subobjs += numsubsub;
 367  367  
 368  368                          dmu_buf_will_dirty(subbpo.bpo_dbuf, tx);
 369  369                          subbpo.bpo_phys->bpo_subobjs = 0;
 370      -                        VERIFY3U(0, ==, dmu_object_free(bpo->bpo_os,
      370 +                        VERIFY0(dmu_object_free(bpo->bpo_os,
 371  371                              subsubobjs, tx));
 372  372                  }
 373  373          }
 374  374          bpo->bpo_phys->bpo_bytes += used;
 375  375          bpo->bpo_phys->bpo_comp += comp;
 376  376          bpo->bpo_phys->bpo_uncomp += uncomp;
 377  377          mutex_exit(&bpo->bpo_lock);
 378  378  
 379  379          bpobj_close(&subbpo);
 380  380  }
↓ open down ↓ 19 lines elided ↑ open up ↑
 400  400  
 401  401          offset = bpo->bpo_phys->bpo_num_blkptrs * sizeof (stored_bp);
 402  402          blkoff = P2PHASE(bpo->bpo_phys->bpo_num_blkptrs, bpo->bpo_epb);
 403  403  
 404  404          if (bpo->bpo_cached_dbuf == NULL ||
 405  405              offset < bpo->bpo_cached_dbuf->db_offset ||
 406  406              offset >= bpo->bpo_cached_dbuf->db_offset +
 407  407              bpo->bpo_cached_dbuf->db_size) {
 408  408                  if (bpo->bpo_cached_dbuf)
 409  409                          dmu_buf_rele(bpo->bpo_cached_dbuf, bpo);
 410      -                VERIFY3U(0, ==, dmu_buf_hold(bpo->bpo_os, bpo->bpo_object,
      410 +                VERIFY0(dmu_buf_hold(bpo->bpo_os, bpo->bpo_object,
 411  411                      offset, bpo, &bpo->bpo_cached_dbuf, 0));
 412  412          }
 413  413  
 414  414          dmu_buf_will_dirty(bpo->bpo_cached_dbuf, tx);
 415  415          bparray = bpo->bpo_cached_dbuf->db_data;
 416  416          bparray[blkoff] = stored_bp;
 417  417  
 418  418          dmu_buf_will_dirty(bpo->bpo_dbuf, tx);
 419  419          bpo->bpo_phys->bpo_num_blkptrs++;
 420  420          bpo->bpo_phys->bpo_bytes +=
↓ open down ↓ 80 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX