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/dnode.c
          +++ new/usr/src/uts/common/fs/zfs/dnode.c
↓ open down ↓ 129 lines elided ↑ open up ↑
 130  130          mutex_destroy(&dn->dn_dbufs_mtx);
 131  131          cv_destroy(&dn->dn_notxholds);
 132  132          refcount_destroy(&dn->dn_holds);
 133  133          refcount_destroy(&dn->dn_tx_holds);
 134  134          ASSERT(!list_link_active(&dn->dn_link));
 135  135  
 136  136          for (i = 0; i < TXG_SIZE; i++) {
 137  137                  ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
 138  138                  avl_destroy(&dn->dn_ranges[i]);
 139  139                  list_destroy(&dn->dn_dirty_records[i]);
 140      -                ASSERT3U(dn->dn_next_nblkptr[i], ==, 0);
 141      -                ASSERT3U(dn->dn_next_nlevels[i], ==, 0);
 142      -                ASSERT3U(dn->dn_next_indblkshift[i], ==, 0);
 143      -                ASSERT3U(dn->dn_next_bonustype[i], ==, 0);
 144      -                ASSERT3U(dn->dn_rm_spillblk[i], ==, 0);
 145      -                ASSERT3U(dn->dn_next_bonuslen[i], ==, 0);
 146      -                ASSERT3U(dn->dn_next_blksz[i], ==, 0);
      140 +                ASSERT0(dn->dn_next_nblkptr[i]);
      141 +                ASSERT0(dn->dn_next_nlevels[i]);
      142 +                ASSERT0(dn->dn_next_indblkshift[i]);
      143 +                ASSERT0(dn->dn_next_bonustype[i]);
      144 +                ASSERT0(dn->dn_rm_spillblk[i]);
      145 +                ASSERT0(dn->dn_next_bonuslen[i]);
      146 +                ASSERT0(dn->dn_next_blksz[i]);
 147  147          }
 148  148  
 149      -        ASSERT3U(dn->dn_allocated_txg, ==, 0);
 150      -        ASSERT3U(dn->dn_free_txg, ==, 0);
 151      -        ASSERT3U(dn->dn_assigned_txg, ==, 0);
 152      -        ASSERT3U(dn->dn_dirtyctx, ==, 0);
      149 +        ASSERT0(dn->dn_allocated_txg);
      150 +        ASSERT0(dn->dn_free_txg);
      151 +        ASSERT0(dn->dn_assigned_txg);
      152 +        ASSERT0(dn->dn_dirtyctx);
 153  153          ASSERT3P(dn->dn_dirtyctx_firstset, ==, NULL);
 154  154          ASSERT3P(dn->dn_bonus, ==, NULL);
 155  155          ASSERT(!dn->dn_have_spill);
 156  156          ASSERT3P(dn->dn_zio, ==, NULL);
 157      -        ASSERT3U(dn->dn_oldused, ==, 0);
 158      -        ASSERT3U(dn->dn_oldflags, ==, 0);
 159      -        ASSERT3U(dn->dn_olduid, ==, 0);
 160      -        ASSERT3U(dn->dn_oldgid, ==, 0);
 161      -        ASSERT3U(dn->dn_newuid, ==, 0);
 162      -        ASSERT3U(dn->dn_newgid, ==, 0);
 163      -        ASSERT3U(dn->dn_id_flags, ==, 0);
      157 +        ASSERT0(dn->dn_oldused);
      158 +        ASSERT0(dn->dn_oldflags);
      159 +        ASSERT0(dn->dn_olduid);
      160 +        ASSERT0(dn->dn_oldgid);
      161 +        ASSERT0(dn->dn_newuid);
      162 +        ASSERT0(dn->dn_newgid);
      163 +        ASSERT0(dn->dn_id_flags);
 164  164  
 165      -        ASSERT3U(dn->dn_dbufs_count, ==, 0);
      165 +        ASSERT0(dn->dn_dbufs_count);
 166  166          list_destroy(&dn->dn_dbufs);
 167  167  }
 168  168  
 169  169  void
 170  170  dnode_init(void)
 171  171  {
 172  172          ASSERT(dnode_cache == NULL);
 173  173          dnode_cache = kmem_cache_create("dnode_t",
 174  174              sizeof (dnode_t),
 175  175              0, dnode_cons, dnode_dest, NULL, NULL, NULL, 0);
↓ open down ↓ 178 lines elided ↑ open up ↑
 354  354          ASSERT3U(refcount_count(&dn->dn_holds), >=, 1);
 355  355          ASSERT(RW_WRITE_HELD(&dn->dn_struct_rwlock));
 356  356          dnode_setdirty(dn, tx);
 357  357          dn->dn_rm_spillblk[tx->tx_txg&TXG_MASK] = DN_KILL_SPILLBLK;
 358  358          dn->dn_have_spill = B_FALSE;
 359  359  }
 360  360  
 361  361  static void
 362  362  dnode_setdblksz(dnode_t *dn, int size)
 363  363  {
 364      -        ASSERT3U(P2PHASE(size, SPA_MINBLOCKSIZE), ==, 0);
      364 +        ASSERT0(P2PHASE(size, SPA_MINBLOCKSIZE));
 365  365          ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
 366  366          ASSERT3U(size, >=, SPA_MINBLOCKSIZE);
 367  367          ASSERT3U(size >> SPA_MINBLOCKSHIFT, <,
 368  368              1<<(sizeof (dn->dn_phys->dn_datablkszsec) * 8));
 369  369          dn->dn_datablksz = size;
 370  370          dn->dn_datablkszsec = size >> SPA_MINBLOCKSHIFT;
 371  371          dn->dn_datablkshift = ISP2(size) ? highbit(size - 1) : 0;
 372  372  }
 373  373  
 374  374  static dnode_t *
↓ open down ↓ 124 lines elided ↑ open up ↑
 499  499          ASSERT(bcmp(dn->dn_phys, &dnode_phys_zero, sizeof (dnode_phys_t)) == 0);
 500  500          ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE);
 501  501          ASSERT(ot != DMU_OT_NONE);
 502  502          ASSERT(DMU_OT_IS_VALID(ot));
 503  503          ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
 504  504              (bonustype == DMU_OT_SA && bonuslen == 0) ||
 505  505              (bonustype != DMU_OT_NONE && bonuslen != 0));
 506  506          ASSERT(DMU_OT_IS_VALID(bonustype));
 507  507          ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
 508  508          ASSERT(dn->dn_type == DMU_OT_NONE);
 509      -        ASSERT3U(dn->dn_maxblkid, ==, 0);
 510      -        ASSERT3U(dn->dn_allocated_txg, ==, 0);
 511      -        ASSERT3U(dn->dn_assigned_txg, ==, 0);
      509 +        ASSERT0(dn->dn_maxblkid);
      510 +        ASSERT0(dn->dn_allocated_txg);
      511 +        ASSERT0(dn->dn_assigned_txg);
 512  512          ASSERT(refcount_is_zero(&dn->dn_tx_holds));
 513  513          ASSERT3U(refcount_count(&dn->dn_holds), <=, 1);
 514  514          ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL);
 515  515  
 516  516          for (i = 0; i < TXG_SIZE; i++) {
 517      -                ASSERT3U(dn->dn_next_nblkptr[i], ==, 0);
 518      -                ASSERT3U(dn->dn_next_nlevels[i], ==, 0);
 519      -                ASSERT3U(dn->dn_next_indblkshift[i], ==, 0);
 520      -                ASSERT3U(dn->dn_next_bonuslen[i], ==, 0);
 521      -                ASSERT3U(dn->dn_next_bonustype[i], ==, 0);
 522      -                ASSERT3U(dn->dn_rm_spillblk[i], ==, 0);
 523      -                ASSERT3U(dn->dn_next_blksz[i], ==, 0);
      517 +                ASSERT0(dn->dn_next_nblkptr[i]);
      518 +                ASSERT0(dn->dn_next_nlevels[i]);
      519 +                ASSERT0(dn->dn_next_indblkshift[i]);
      520 +                ASSERT0(dn->dn_next_bonuslen[i]);
      521 +                ASSERT0(dn->dn_next_bonustype[i]);
      522 +                ASSERT0(dn->dn_rm_spillblk[i]);
      523 +                ASSERT0(dn->dn_next_blksz[i]);
 524  524                  ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
 525  525                  ASSERT3P(list_head(&dn->dn_dirty_records[i]), ==, NULL);
 526      -                ASSERT3U(avl_numnodes(&dn->dn_ranges[i]), ==, 0);
      526 +                ASSERT0(avl_numnodes(&dn->dn_ranges[i]));
 527  527          }
 528  528  
 529  529          dn->dn_type = ot;
 530  530          dnode_setdblksz(dn, blocksize);
 531  531          dn->dn_indblkshift = ibs;
 532  532          dn->dn_nlevels = 1;
 533  533          if (bonustype == DMU_OT_SA) /* Maximize bonus space for SA */
 534  534                  dn->dn_nblkptr = 1;
 535  535          else
 536  536                  dn->dn_nblkptr = 1 +
↓ open down ↓ 21 lines elided ↑ open up ↑
 558  558  }
 559  559  
 560  560  void
 561  561  dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
 562  562      dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
 563  563  {
 564  564          int nblkptr;
 565  565  
 566  566          ASSERT3U(blocksize, >=, SPA_MINBLOCKSIZE);
 567  567          ASSERT3U(blocksize, <=, SPA_MAXBLOCKSIZE);
 568      -        ASSERT3U(blocksize % SPA_MINBLOCKSIZE, ==, 0);
      568 +        ASSERT0(blocksize % SPA_MINBLOCKSIZE);
 569  569          ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx));
 570  570          ASSERT(tx->tx_txg != 0);
 571  571          ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
 572  572              (bonustype != DMU_OT_NONE && bonuslen != 0) ||
 573  573              (bonustype == DMU_OT_SA && bonuslen == 0));
 574  574          ASSERT(DMU_OT_IS_VALID(bonustype));
 575  575          ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
 576  576  
 577  577          /* clean up any unreferenced dbufs */
 578  578          dnode_evict_dbufs(dn);
↓ open down ↓ 649 lines elided ↑ open up ↑
1228 1228          /*
1229 1229           * If we are already marked dirty, we're done.
1230 1230           */
1231 1231          if (list_link_active(&dn->dn_dirty_link[txg & TXG_MASK])) {
1232 1232                  mutex_exit(&os->os_lock);
1233 1233                  return;
1234 1234          }
1235 1235  
1236 1236          ASSERT(!refcount_is_zero(&dn->dn_holds) || list_head(&dn->dn_dbufs));
1237 1237          ASSERT(dn->dn_datablksz != 0);
1238      -        ASSERT3U(dn->dn_next_bonuslen[txg&TXG_MASK], ==, 0);
1239      -        ASSERT3U(dn->dn_next_blksz[txg&TXG_MASK], ==, 0);
1240      -        ASSERT3U(dn->dn_next_bonustype[txg&TXG_MASK], ==, 0);
     1238 +        ASSERT0(dn->dn_next_bonuslen[txg&TXG_MASK]);
     1239 +        ASSERT0(dn->dn_next_blksz[txg&TXG_MASK]);
     1240 +        ASSERT0(dn->dn_next_bonustype[txg&TXG_MASK]);
1241 1241  
1242 1242          dprintf_ds(os->os_dsl_dataset, "obj=%llu txg=%llu\n",
1243 1243              dn->dn_object, txg);
1244 1244  
1245 1245          if (dn->dn_free_txg > 0 && dn->dn_free_txg <= txg) {
1246 1246                  list_insert_tail(&os->os_free_dnodes[txg&TXG_MASK], dn);
1247 1247          } else {
1248 1248                  list_insert_tail(&os->os_dirty_dnodes[txg&TXG_MASK], dn);
1249 1249          }
1250 1250  
↓ open down ↓ 329 lines elided ↑ open up ↑
1580 1580          /* If the remaining range is past end of file, we're done */
1581 1581          if ((off >> blkshift) > dn->dn_maxblkid)
1582 1582                  goto out;
1583 1583  
1584 1584          ASSERT(ISP2(blksz));
1585 1585          if (trunc)
1586 1586                  tail = 0;
1587 1587          else
1588 1588                  tail = P2PHASE(len, blksz);
1589 1589  
1590      -        ASSERT3U(P2PHASE(off, blksz), ==, 0);
     1590 +        ASSERT0(P2PHASE(off, blksz));
1591 1591          /* zero out any partial block data at the end of the range */
1592 1592          if (tail) {
1593 1593                  if (len < tail)
1594 1594                          tail = len;
1595 1595                  if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off+len),
1596 1596                      TRUE, FTAG, &db) == 0) {
1597 1597                          /* don't dirty if not on disk and not dirty */
1598 1598                          if (db->db_last_dirty ||
1599 1599                              (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) {
1600 1600                                  rw_exit(&dn->dn_struct_rwlock);
↓ open down ↓ 161 lines elided ↑ open up ↑
1762 1762          mutex_enter(&dn->dn_mtx);
1763 1763          space = DN_USED_BYTES(dn->dn_phys);
1764 1764          if (delta > 0) {
1765 1765                  ASSERT3U(space + delta, >=, space); /* no overflow */
1766 1766          } else {
1767 1767                  ASSERT3U(space, >=, -delta); /* no underflow */
1768 1768          }
1769 1769          space += delta;
1770 1770          if (spa_version(dn->dn_objset->os_spa) < SPA_VERSION_DNODE_BYTES) {
1771 1771                  ASSERT((dn->dn_phys->dn_flags & DNODE_FLAG_USED_BYTES) == 0);
1772      -                ASSERT3U(P2PHASE(space, 1<<DEV_BSHIFT), ==, 0);
     1772 +                ASSERT0(P2PHASE(space, 1<<DEV_BSHIFT));
1773 1773                  dn->dn_phys->dn_used = space >> DEV_BSHIFT;
1774 1774          } else {
1775 1775                  dn->dn_phys->dn_used = space;
1776 1776                  dn->dn_phys->dn_flags |= DNODE_FLAG_USED_BYTES;
1777 1777          }
1778 1778          mutex_exit(&dn->dn_mtx);
1779 1779  }
1780 1780  
1781 1781  /*
1782 1782   * Call when we think we're going to write/free space in open context.
↓ open down ↓ 214 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX