Print this page
3752 want more verifiable dbuf user eviction
Submitted by:   Justin Gibbs <justing@spectralogic.com>
Submitted by:   Will Andrews <willa@spectralogic.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/zfs/zap.c
          +++ new/usr/src/uts/common/fs/zfs/zap.c
↓ open down ↓ 42 lines elided ↑ open up ↑
  43   43  #include <sys/zfs_context.h>
  44   44  #include <sys/zfs_znode.h>
  45   45  #include <sys/fs/zfs.h>
  46   46  #include <sys/zap.h>
  47   47  #include <sys/refcount.h>
  48   48  #include <sys/zap_impl.h>
  49   49  #include <sys/zap_leaf.h>
  50   50  
  51   51  int fzap_default_block_shift = 14; /* 16k blocksize */
  52   52  
  53      -static void zap_leaf_pageout(dmu_buf_t *db, void *vl);
  54   53  static uint64_t zap_allocate_blocks(zap_t *zap, int nblocks);
  55   54  
  56      -
  57   55  void
  58   56  fzap_byteswap(void *vbuf, size_t size)
  59   57  {
  60   58          uint64_t block_type;
  61   59  
  62   60          block_type = *(uint64_t *)vbuf;
  63   61  
  64   62          if (block_type == ZBT_LEAF || block_type == BSWAP_64(ZBT_LEAF))
  65   63                  zap_leaf_byteswap(vbuf, size);
  66   64          else {
↓ open down ↓ 6 lines elided ↑ open up ↑
  73   71  fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags)
  74   72  {
  75   73          dmu_buf_t *db;
  76   74          zap_leaf_t *l;
  77   75          int i;
  78   76          zap_phys_t *zp;
  79   77  
  80   78          ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
  81   79          zap->zap_ismicro = FALSE;
  82   80  
  83      -        (void) dmu_buf_update_user(zap->zap_dbuf, zap, zap,
  84      -            &zap->zap_f.zap_phys, zap_evict);
       81 +        zap->db_evict.evict_func = zap_evict;
  85   82  
  86   83          mutex_init(&zap->zap_f.zap_num_entries_mtx, 0, 0, 0);
  87   84          zap->zap_f.zap_block_shift = highbit(zap->zap_dbuf->db_size) - 1;
  88   85  
  89      -        zp = zap->zap_f.zap_phys;
       86 +        zp = zap->zap_f_phys;
  90   87          /*
  91   88           * explicitly zero it since it might be coming from an
  92   89           * initialized microzap
  93   90           */
  94   91          bzero(zap->zap_dbuf->db_data, zap->zap_dbuf->db_size);
  95   92          zp->zap_block_type = ZBT_HEADER;
  96   93          zp->zap_magic = ZAP_MAGIC;
  97   94  
  98   95          zp->zap_ptrtbl.zt_shift = ZAP_EMBEDDED_PTRTBL_SHIFT(zap);
  99   96  
↓ open down ↓ 10 lines elided ↑ open up ↑
 110  107  
 111  108          /*
 112  109           * set up block 1 - the first leaf
 113  110           */
 114  111          VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object,
 115  112              1<<FZAP_BLOCK_SHIFT(zap), FTAG, &db, DMU_READ_NO_PREFETCH));
 116  113          dmu_buf_will_dirty(db, tx);
 117  114  
 118  115          l = kmem_zalloc(sizeof (zap_leaf_t), KM_SLEEP);
 119  116          l->l_dbuf = db;
 120      -        l->l_phys = db->db_data;
 121  117  
 122  118          zap_leaf_init(l, zp->zap_normflags != 0);
 123  119  
 124  120          kmem_free(l, sizeof (zap_leaf_t));
 125  121          dmu_buf_rele(db, FTAG);
 126  122  }
 127  123  
 128  124  static int
 129  125  zap_tryupgradedir(zap_t *zap, dmu_tx_t *tx)
 130  126  {
↓ open down ↓ 186 lines elided ↑ open up ↑
 317  313  
 318  314  static int
 319  315  zap_grow_ptrtbl(zap_t *zap, dmu_tx_t *tx)
 320  316  {
 321  317          /*
 322  318           * The pointer table should never use more hash bits than we
 323  319           * have (otherwise we'd be using useless zero bits to index it).
 324  320           * If we are within 2 bits of running out, stop growing, since
 325  321           * this is already an aberrant condition.
 326  322           */
 327      -        if (zap->zap_f.zap_phys->zap_ptrtbl.zt_shift >= zap_hashbits(zap) - 2)
      323 +        if (zap->zap_f_phys->zap_ptrtbl.zt_shift >= zap_hashbits(zap) - 2)
 328  324                  return (SET_ERROR(ENOSPC));
 329  325  
 330      -        if (zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks == 0) {
      326 +        if (zap->zap_f_phys->zap_ptrtbl.zt_numblks == 0) {
 331  327                  /*
 332  328                   * We are outgrowing the "embedded" ptrtbl (the one
 333  329                   * stored in the header block).  Give it its own entire
 334  330                   * block, which will double the size of the ptrtbl.
 335  331                   */
 336  332                  uint64_t newblk;
 337  333                  dmu_buf_t *db_new;
 338  334                  int err;
 339  335  
 340      -                ASSERT3U(zap->zap_f.zap_phys->zap_ptrtbl.zt_shift, ==,
      336 +                ASSERT3U(zap->zap_f_phys->zap_ptrtbl.zt_shift, ==,
 341  337                      ZAP_EMBEDDED_PTRTBL_SHIFT(zap));
 342      -                ASSERT0(zap->zap_f.zap_phys->zap_ptrtbl.zt_blk);
      338 +                ASSERT0(zap->zap_f_phys->zap_ptrtbl.zt_blk);
 343  339  
 344  340                  newblk = zap_allocate_blocks(zap, 1);
 345  341                  err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
 346  342                      newblk << FZAP_BLOCK_SHIFT(zap), FTAG, &db_new,
 347  343                      DMU_READ_NO_PREFETCH);
 348  344                  if (err)
 349  345                          return (err);
 350  346                  dmu_buf_will_dirty(db_new, tx);
 351  347                  zap_ptrtbl_transfer(&ZAP_EMBEDDED_PTRTBL_ENT(zap, 0),
 352  348                      db_new->db_data, 1 << ZAP_EMBEDDED_PTRTBL_SHIFT(zap));
 353  349                  dmu_buf_rele(db_new, FTAG);
 354  350  
 355      -                zap->zap_f.zap_phys->zap_ptrtbl.zt_blk = newblk;
 356      -                zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks = 1;
 357      -                zap->zap_f.zap_phys->zap_ptrtbl.zt_shift++;
      351 +                zap->zap_f_phys->zap_ptrtbl.zt_blk = newblk;
      352 +                zap->zap_f_phys->zap_ptrtbl.zt_numblks = 1;
      353 +                zap->zap_f_phys->zap_ptrtbl.zt_shift++;
 358  354  
 359      -                ASSERT3U(1ULL << zap->zap_f.zap_phys->zap_ptrtbl.zt_shift, ==,
 360      -                    zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks <<
      355 +                ASSERT3U(1ULL << zap->zap_f_phys->zap_ptrtbl.zt_shift, ==,
      356 +                    zap->zap_f_phys->zap_ptrtbl.zt_numblks <<
 361  357                      (FZAP_BLOCK_SHIFT(zap)-3));
 362  358  
 363  359                  return (0);
 364  360          } else {
 365      -                return (zap_table_grow(zap, &zap->zap_f.zap_phys->zap_ptrtbl,
      361 +                return (zap_table_grow(zap, &zap->zap_f_phys->zap_ptrtbl,
 366  362                      zap_ptrtbl_transfer, tx));
 367  363          }
 368  364  }
 369  365  
 370  366  static void
 371  367  zap_increment_num_entries(zap_t *zap, int delta, dmu_tx_t *tx)
 372  368  {
 373  369          dmu_buf_will_dirty(zap->zap_dbuf, tx);
 374  370          mutex_enter(&zap->zap_f.zap_num_entries_mtx);
 375      -        ASSERT(delta > 0 || zap->zap_f.zap_phys->zap_num_entries >= -delta);
 376      -        zap->zap_f.zap_phys->zap_num_entries += delta;
      371 +        ASSERT(delta > 0 || zap->zap_f_phys->zap_num_entries >= -delta);
      372 +        zap->zap_f_phys->zap_num_entries += delta;
 377  373          mutex_exit(&zap->zap_f.zap_num_entries_mtx);
 378  374  }
 379  375  
 380  376  static uint64_t
 381  377  zap_allocate_blocks(zap_t *zap, int nblocks)
 382  378  {
 383  379          uint64_t newblk;
 384  380          ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
 385      -        newblk = zap->zap_f.zap_phys->zap_freeblk;
 386      -        zap->zap_f.zap_phys->zap_freeblk += nblocks;
      381 +        newblk = zap->zap_f_phys->zap_freeblk;
      382 +        zap->zap_f_phys->zap_freeblk += nblocks;
 387  383          return (newblk);
 388  384  }
 389  385  
      386 +static void
      387 +zap_leaf_pageout(dmu_buf_user_t *dbu)
      388 +{
      389 +        zap_leaf_t *l = (zap_leaf_t *)dbu;
      390 +
      391 +        rw_destroy(&l->l_rwlock);
      392 +        kmem_free(l, sizeof (zap_leaf_t));
      393 +}
      394 +
 390  395  static zap_leaf_t *
 391  396  zap_create_leaf(zap_t *zap, dmu_tx_t *tx)
 392  397  {
 393  398          void *winner;
 394  399          zap_leaf_t *l = kmem_alloc(sizeof (zap_leaf_t), KM_SLEEP);
 395  400  
 396  401          ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
 397  402  
 398  403          rw_init(&l->l_rwlock, 0, 0, 0);
 399  404          rw_enter(&l->l_rwlock, RW_WRITER);
 400  405          l->l_blkid = zap_allocate_blocks(zap, 1);
 401  406          l->l_dbuf = NULL;
 402      -        l->l_phys = NULL;
 403  407  
 404  408          VERIFY(0 == dmu_buf_hold(zap->zap_objset, zap->zap_object,
 405  409              l->l_blkid << FZAP_BLOCK_SHIFT(zap), NULL, &l->l_dbuf,
 406  410              DMU_READ_NO_PREFETCH));
 407      -        winner = dmu_buf_set_user(l->l_dbuf, l, &l->l_phys, zap_leaf_pageout);
      411 +        dmu_buf_init_user(&l->db_evict, zap_leaf_pageout);
      412 +        winner = (zap_leaf_t *)dmu_buf_set_user(l->l_dbuf, &l->db_evict);
 408  413          ASSERT(winner == NULL);
 409  414          dmu_buf_will_dirty(l->l_dbuf, tx);
 410  415  
 411  416          zap_leaf_init(l, zap->zap_normflags != 0);
 412  417  
 413      -        zap->zap_f.zap_phys->zap_num_leafs++;
      418 +        zap->zap_f_phys->zap_num_leafs++;
 414  419  
 415  420          return (l);
 416  421  }
 417  422  
 418  423  int
 419  424  fzap_count(zap_t *zap, uint64_t *count)
 420  425  {
 421  426          ASSERT(!zap->zap_ismicro);
 422  427          mutex_enter(&zap->zap_f.zap_num_entries_mtx); /* unnecessary */
 423      -        *count = zap->zap_f.zap_phys->zap_num_entries;
      428 +        *count = zap->zap_f_phys->zap_num_entries;
 424  429          mutex_exit(&zap->zap_f.zap_num_entries_mtx);
 425  430          return (0);
 426  431  }
 427  432  
 428  433  /*
 429  434   * Routines for obtaining zap_leaf_t's
 430  435   */
 431  436  
 432  437  void
 433  438  zap_put_leaf(zap_leaf_t *l)
 434  439  {
 435  440          rw_exit(&l->l_rwlock);
 436  441          dmu_buf_rele(l->l_dbuf, NULL);
 437  442  }
 438  443  
 439      -_NOTE(ARGSUSED(0))
 440      -static void
 441      -zap_leaf_pageout(dmu_buf_t *db, void *vl)
 442      -{
 443      -        zap_leaf_t *l = vl;
 444      -
 445      -        rw_destroy(&l->l_rwlock);
 446      -        kmem_free(l, sizeof (zap_leaf_t));
 447      -}
 448      -
 449  444  static zap_leaf_t *
 450  445  zap_open_leaf(uint64_t blkid, dmu_buf_t *db)
 451  446  {
 452  447          zap_leaf_t *l, *winner;
 453  448  
 454  449          ASSERT(blkid != 0);
 455  450  
 456  451          l = kmem_alloc(sizeof (zap_leaf_t), KM_SLEEP);
 457  452          rw_init(&l->l_rwlock, 0, 0, 0);
 458  453          rw_enter(&l->l_rwlock, RW_WRITER);
 459  454          l->l_blkid = blkid;
 460  455          l->l_bs = highbit(db->db_size)-1;
 461  456          l->l_dbuf = db;
 462      -        l->l_phys = NULL;
 463  457  
 464      -        winner = dmu_buf_set_user(db, l, &l->l_phys, zap_leaf_pageout);
      458 +        dmu_buf_init_user(&l->db_evict, zap_leaf_pageout);
      459 +        winner = (zap_leaf_t *)dmu_buf_set_user(db, &l->db_evict);
 465  460  
 466  461          rw_exit(&l->l_rwlock);
 467  462          if (winner != NULL) {
 468  463                  /* someone else set it first */
 469      -                zap_leaf_pageout(NULL, l);
      464 +                zap_leaf_pageout(&l->db_evict);
 470  465                  l = winner;
 471  466          }
 472  467  
 473  468          /*
 474  469           * lhr_pad was previously used for the next leaf in the leaf
 475  470           * chain.  There should be no chained leafs (as we have removed
 476  471           * support for them).
 477  472           */
 478  473          ASSERT0(l->l_phys->l_hdr.lh_pad1);
 479  474  
↓ open down ↓ 28 lines elided ↑ open up ↑
 508  503          err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
 509  504              blkid << bs, NULL, &db, DMU_READ_NO_PREFETCH);
 510  505          if (err)
 511  506                  return (err);
 512  507  
 513  508          ASSERT3U(db->db_object, ==, zap->zap_object);
 514  509          ASSERT3U(db->db_offset, ==, blkid << bs);
 515  510          ASSERT3U(db->db_size, ==, 1 << bs);
 516  511          ASSERT(blkid != 0);
 517  512  
 518      -        l = dmu_buf_get_user(db);
      513 +        l = (zap_leaf_t *)dmu_buf_get_user(db);
 519  514  
 520  515          if (l == NULL)
 521  516                  l = zap_open_leaf(blkid, db);
 522  517  
 523  518          rw_enter(&l->l_rwlock, lt);
 524  519          /*
 525  520           * Must lock before dirtying, otherwise l->l_phys could change,
 526  521           * causing ASSERT below to fail.
 527  522           */
 528  523          if (lt == RW_WRITER)
↓ open down ↓ 6 lines elided ↑ open up ↑
 535  530  
 536  531          *lp = l;
 537  532          return (0);
 538  533  }
 539  534  
 540  535  static int
 541  536  zap_idx_to_blk(zap_t *zap, uint64_t idx, uint64_t *valp)
 542  537  {
 543  538          ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
 544  539  
 545      -        if (zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks == 0) {
      540 +        if (zap->zap_f_phys->zap_ptrtbl.zt_numblks == 0) {
 546  541                  ASSERT3U(idx, <,
 547      -                    (1ULL << zap->zap_f.zap_phys->zap_ptrtbl.zt_shift));
      542 +                    (1ULL << zap->zap_f_phys->zap_ptrtbl.zt_shift));
 548  543                  *valp = ZAP_EMBEDDED_PTRTBL_ENT(zap, idx);
 549  544                  return (0);
 550  545          } else {
 551      -                return (zap_table_load(zap, &zap->zap_f.zap_phys->zap_ptrtbl,
      546 +                return (zap_table_load(zap, &zap->zap_f_phys->zap_ptrtbl,
 552  547                      idx, valp));
 553  548          }
 554  549  }
 555  550  
 556  551  static int
 557  552  zap_set_idx_to_blk(zap_t *zap, uint64_t idx, uint64_t blk, dmu_tx_t *tx)
 558  553  {
 559  554          ASSERT(tx != NULL);
 560  555          ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
 561  556  
 562      -        if (zap->zap_f.zap_phys->zap_ptrtbl.zt_blk == 0) {
      557 +        if (zap->zap_f_phys->zap_ptrtbl.zt_blk == 0) {
 563  558                  ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) = blk;
 564  559                  return (0);
 565  560          } else {
 566      -                return (zap_table_store(zap, &zap->zap_f.zap_phys->zap_ptrtbl,
      561 +                return (zap_table_store(zap, &zap->zap_f_phys->zap_ptrtbl,
 567  562                      idx, blk, tx));
 568  563          }
 569  564  }
 570  565  
 571  566  static int
 572  567  zap_deref_leaf(zap_t *zap, uint64_t h, dmu_tx_t *tx, krw_t lt, zap_leaf_t **lp)
 573  568  {
 574  569          uint64_t idx, blk;
 575  570          int err;
 576  571  
 577  572          ASSERT(zap->zap_dbuf == NULL ||
 578      -            zap->zap_f.zap_phys == zap->zap_dbuf->db_data);
 579      -        ASSERT3U(zap->zap_f.zap_phys->zap_magic, ==, ZAP_MAGIC);
 580      -        idx = ZAP_HASH_IDX(h, zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
      573 +            zap->zap_f_phys == zap->zap_dbuf->db_data);
      574 +        ASSERT3U(zap->zap_f_phys->zap_magic, ==, ZAP_MAGIC);
      575 +        idx = ZAP_HASH_IDX(h, zap->zap_f_phys->zap_ptrtbl.zt_shift);
 581  576          err = zap_idx_to_blk(zap, idx, &blk);
 582  577          if (err != 0)
 583  578                  return (err);
 584  579          err = zap_get_leaf_byblk(zap, blk, tx, lt, lp);
 585  580  
 586  581          ASSERT(err || ZAP_HASH_IDX(h, (*lp)->l_phys->l_hdr.lh_prefix_len) ==
 587  582              (*lp)->l_phys->l_hdr.lh_prefix);
 588  583          return (err);
 589  584  }
 590  585  
 591  586  static int
 592  587  zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp)
 593  588  {
 594  589          zap_t *zap = zn->zn_zap;
 595  590          uint64_t hash = zn->zn_hash;
 596  591          zap_leaf_t *nl;
 597  592          int prefix_diff, i, err;
 598  593          uint64_t sibling;
 599  594          int old_prefix_len = l->l_phys->l_hdr.lh_prefix_len;
 600  595  
 601      -        ASSERT3U(old_prefix_len, <=, zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
      596 +        ASSERT3U(old_prefix_len, <=, zap->zap_f_phys->zap_ptrtbl.zt_shift);
 602  597          ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
 603  598  
 604  599          ASSERT3U(ZAP_HASH_IDX(hash, old_prefix_len), ==,
 605  600              l->l_phys->l_hdr.lh_prefix);
 606  601  
 607  602          if (zap_tryupgradedir(zap, tx) == 0 ||
 608      -            old_prefix_len == zap->zap_f.zap_phys->zap_ptrtbl.zt_shift) {
      603 +            old_prefix_len == zap->zap_f_phys->zap_ptrtbl.zt_shift) {
 609  604                  /* We failed to upgrade, or need to grow the pointer table */
 610  605                  objset_t *os = zap->zap_objset;
 611  606                  uint64_t object = zap->zap_object;
 612  607  
 613  608                  zap_put_leaf(l);
 614  609                  zap_unlockdir(zap);
 615  610                  err = zap_lockdir(os, object, tx, RW_WRITER,
 616  611                      FALSE, FALSE, &zn->zn_zap);
 617  612                  zap = zn->zn_zap;
 618  613                  if (err)
 619  614                          return (err);
 620  615                  ASSERT(!zap->zap_ismicro);
 621  616  
 622  617                  while (old_prefix_len ==
 623      -                    zap->zap_f.zap_phys->zap_ptrtbl.zt_shift) {
      618 +                    zap->zap_f_phys->zap_ptrtbl.zt_shift) {
 624  619                          err = zap_grow_ptrtbl(zap, tx);
 625  620                          if (err)
 626  621                                  return (err);
 627  622                  }
 628  623  
 629  624                  err = zap_deref_leaf(zap, hash, tx, RW_WRITER, &l);
 630  625                  if (err)
 631  626                          return (err);
 632  627  
 633  628                  if (l->l_phys->l_hdr.lh_prefix_len != old_prefix_len) {
 634  629                          /* it split while our locks were down */
 635  630                          *lp = l;
 636  631                          return (0);
 637  632                  }
 638  633          }
 639  634          ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
 640      -        ASSERT3U(old_prefix_len, <, zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
      635 +        ASSERT3U(old_prefix_len, <, zap->zap_f_phys->zap_ptrtbl.zt_shift);
 641  636          ASSERT3U(ZAP_HASH_IDX(hash, old_prefix_len), ==,
 642  637              l->l_phys->l_hdr.lh_prefix);
 643  638  
 644      -        prefix_diff = zap->zap_f.zap_phys->zap_ptrtbl.zt_shift -
      639 +        prefix_diff = zap->zap_f_phys->zap_ptrtbl.zt_shift -
 645  640              (old_prefix_len + 1);
 646  641          sibling = (ZAP_HASH_IDX(hash, old_prefix_len + 1) | 1) << prefix_diff;
 647  642  
 648  643          /* check for i/o errors before doing zap_leaf_split */
 649  644          for (i = 0; i < (1ULL<<prefix_diff); i++) {
 650  645                  uint64_t blk;
 651  646                  err = zap_idx_to_blk(zap, sibling+i, &blk);
 652  647                  if (err)
 653  648                          return (err);
 654  649                  ASSERT3U(blk, ==, l->l_blkid);
↓ open down ↓ 17 lines elided ↑ open up ↑
 672  667                  *lp = l;
 673  668          }
 674  669  
 675  670          return (0);
 676  671  }
 677  672  
 678  673  static void
 679  674  zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx)
 680  675  {
 681  676          zap_t *zap = zn->zn_zap;
 682      -        int shift = zap->zap_f.zap_phys->zap_ptrtbl.zt_shift;
      677 +        int shift = zap->zap_f_phys->zap_ptrtbl.zt_shift;
 683  678          int leaffull = (l->l_phys->l_hdr.lh_prefix_len == shift &&
 684  679              l->l_phys->l_hdr.lh_nfree < ZAP_LEAF_LOW_WATER);
 685  680  
 686  681          zap_put_leaf(l);
 687  682  
 688      -        if (leaffull || zap->zap_f.zap_phys->zap_ptrtbl.zt_nextblk) {
      683 +        if (leaffull || zap->zap_f_phys->zap_ptrtbl.zt_nextblk) {
 689  684                  int err;
 690  685  
 691  686                  /*
 692  687                   * We are in the middle of growing the pointer table, or
 693  688                   * this leaf will soon make us grow it.
 694  689                   */
 695  690                  if (zap_tryupgradedir(zap, tx) == 0) {
 696  691                          objset_t *os = zap->zap_objset;
 697  692                          uint64_t zapobj = zap->zap_object;
 698  693  
 699  694                          zap_unlockdir(zap);
 700  695                          err = zap_lockdir(os, zapobj, tx,
 701  696                              RW_WRITER, FALSE, FALSE, &zn->zn_zap);
 702  697                          zap = zn->zn_zap;
 703  698                          if (err)
 704  699                                  return;
 705  700                  }
 706  701  
 707  702                  /* could have finished growing while our locks were down */
 708      -                if (zap->zap_f.zap_phys->zap_ptrtbl.zt_shift == shift)
      703 +                if (zap->zap_f_phys->zap_ptrtbl.zt_shift == shift)
 709  704                          (void) zap_grow_ptrtbl(zap, tx);
 710  705          }
 711  706  }
 712  707  
 713  708  static int
 714  709  fzap_checkname(zap_name_t *zn)
 715  710  {
 716  711          if (zn->zn_key_orig_numints * zn->zn_key_intlen > ZAP_MAXNAMELEN)
 717  712                  return (SET_ERROR(ENAMETOOLONG));
 718  713          return (0);
↓ open down ↓ 210 lines elided ↑ open up ↑
 929  924  }
 930  925  
 931  926  void
 932  927  fzap_prefetch(zap_name_t *zn)
 933  928  {
 934  929          uint64_t idx, blk;
 935  930          zap_t *zap = zn->zn_zap;
 936  931          int bs;
 937  932  
 938  933          idx = ZAP_HASH_IDX(zn->zn_hash,
 939      -            zap->zap_f.zap_phys->zap_ptrtbl.zt_shift);
      934 +            zap->zap_f_phys->zap_ptrtbl.zt_shift);
 940  935          if (zap_idx_to_blk(zap, idx, &blk) != 0)
 941  936                  return;
 942  937          bs = FZAP_BLOCK_SHIFT(zap);
 943  938          dmu_prefetch(zap->zap_objset, zap->zap_object, blk << bs, 1 << bs);
 944  939  }
 945  940  
 946  941  /*
 947  942   * Helper functions for consumers.
 948  943   */
 949  944  
↓ open down ↓ 319 lines elided ↑ open up ↑
1269 1264  
1270 1265  void
1271 1266  fzap_get_stats(zap_t *zap, zap_stats_t *zs)
1272 1267  {
1273 1268          int bs = FZAP_BLOCK_SHIFT(zap);
1274 1269          zs->zs_blocksize = 1ULL << bs;
1275 1270  
1276 1271          /*
1277 1272           * Set zap_phys_t fields
1278 1273           */
1279      -        zs->zs_num_leafs = zap->zap_f.zap_phys->zap_num_leafs;
1280      -        zs->zs_num_entries = zap->zap_f.zap_phys->zap_num_entries;
1281      -        zs->zs_num_blocks = zap->zap_f.zap_phys->zap_freeblk;
1282      -        zs->zs_block_type = zap->zap_f.zap_phys->zap_block_type;
1283      -        zs->zs_magic = zap->zap_f.zap_phys->zap_magic;
1284      -        zs->zs_salt = zap->zap_f.zap_phys->zap_salt;
     1274 +        zs->zs_num_leafs = zap->zap_f_phys->zap_num_leafs;
     1275 +        zs->zs_num_entries = zap->zap_f_phys->zap_num_entries;
     1276 +        zs->zs_num_blocks = zap->zap_f_phys->zap_freeblk;
     1277 +        zs->zs_block_type = zap->zap_f_phys->zap_block_type;
     1278 +        zs->zs_magic = zap->zap_f_phys->zap_magic;
     1279 +        zs->zs_salt = zap->zap_f_phys->zap_salt;
1285 1280  
1286 1281          /*
1287 1282           * Set zap_ptrtbl fields
1288 1283           */
1289      -        zs->zs_ptrtbl_len = 1ULL << zap->zap_f.zap_phys->zap_ptrtbl.zt_shift;
1290      -        zs->zs_ptrtbl_nextblk = zap->zap_f.zap_phys->zap_ptrtbl.zt_nextblk;
     1284 +        zs->zs_ptrtbl_len = 1ULL << zap->zap_f_phys->zap_ptrtbl.zt_shift;
     1285 +        zs->zs_ptrtbl_nextblk = zap->zap_f_phys->zap_ptrtbl.zt_nextblk;
1291 1286          zs->zs_ptrtbl_blks_copied =
1292      -            zap->zap_f.zap_phys->zap_ptrtbl.zt_blks_copied;
1293      -        zs->zs_ptrtbl_zt_blk = zap->zap_f.zap_phys->zap_ptrtbl.zt_blk;
1294      -        zs->zs_ptrtbl_zt_numblks = zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks;
1295      -        zs->zs_ptrtbl_zt_shift = zap->zap_f.zap_phys->zap_ptrtbl.zt_shift;
     1287 +            zap->zap_f_phys->zap_ptrtbl.zt_blks_copied;
     1288 +        zs->zs_ptrtbl_zt_blk = zap->zap_f_phys->zap_ptrtbl.zt_blk;
     1289 +        zs->zs_ptrtbl_zt_numblks = zap->zap_f_phys->zap_ptrtbl.zt_numblks;
     1290 +        zs->zs_ptrtbl_zt_shift = zap->zap_f_phys->zap_ptrtbl.zt_shift;
1296 1291  
1297      -        if (zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks == 0) {
     1292 +        if (zap->zap_f_phys->zap_ptrtbl.zt_numblks == 0) {
1298 1293                  /* the ptrtbl is entirely in the header block. */
1299 1294                  zap_stats_ptrtbl(zap, &ZAP_EMBEDDED_PTRTBL_ENT(zap, 0),
1300 1295                      1 << ZAP_EMBEDDED_PTRTBL_SHIFT(zap), zs);
1301 1296          } else {
1302 1297                  int b;
1303 1298  
1304 1299                  dmu_prefetch(zap->zap_objset, zap->zap_object,
1305      -                    zap->zap_f.zap_phys->zap_ptrtbl.zt_blk << bs,
1306      -                    zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks << bs);
     1300 +                    zap->zap_f_phys->zap_ptrtbl.zt_blk << bs,
     1301 +                    zap->zap_f_phys->zap_ptrtbl.zt_numblks << bs);
1307 1302  
1308      -                for (b = 0; b < zap->zap_f.zap_phys->zap_ptrtbl.zt_numblks;
     1303 +                for (b = 0; b < zap->zap_f_phys->zap_ptrtbl.zt_numblks;
1309 1304                      b++) {
1310 1305                          dmu_buf_t *db;
1311 1306                          int err;
1312 1307  
1313 1308                          err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
1314      -                            (zap->zap_f.zap_phys->zap_ptrtbl.zt_blk + b) << bs,
     1309 +                            (zap->zap_f_phys->zap_ptrtbl.zt_blk + b) << bs,
1315 1310                              FTAG, &db, DMU_READ_NO_PREFETCH);
1316 1311                          if (err == 0) {
1317 1312                                  zap_stats_ptrtbl(zap, db->db_data,
1318 1313                                      1<<(bs-3), zs);
1319 1314                                  dmu_buf_rele(db, FTAG);
1320 1315                          }
1321 1316                  }
1322 1317          }
1323 1318  }
1324 1319  
↓ open down ↓ 16 lines elided ↑ open up ↑
1341 1336  
1342 1337          /*
1343 1338           * Account for the pointer table blocks.
1344 1339           * If we are adding we need to account for the following cases :
1345 1340           * - If the pointer table is embedded, this operation could force an
1346 1341           *   external pointer table.
1347 1342           * - If this already has an external pointer table this operation
1348 1343           *   could extend the table.
1349 1344           */
1350 1345          if (add) {
1351      -                if (zap->zap_f.zap_phys->zap_ptrtbl.zt_blk == 0)
     1346 +                if (zap->zap_f_phys->zap_ptrtbl.zt_blk == 0)
1352 1347                          *towrite += zap->zap_dbuf->db_size;
1353 1348                  else
1354 1349                          *towrite += (zap->zap_dbuf->db_size * 3);
1355 1350          }
1356 1351  
1357 1352          /*
1358 1353           * Now, check if the block containing leaf is freeable
1359 1354           * and account accordingly.
1360 1355           */
1361 1356          err = zap_deref_leaf(zap, zn->zn_hash, NULL, RW_READER, &l);
↓ open down ↓ 17 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX