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/dsl_dir.c
          +++ new/usr/src/uts/common/fs/zfs/dsl_dir.c
↓ open down ↓ 35 lines elided ↑ open up ↑
  36   36  #include <sys/zap.h>
  37   37  #include <sys/zio.h>
  38   38  #include <sys/arc.h>
  39   39  #include <sys/sunddi.h>
  40   40  #include "zfs_namecheck.h"
  41   41  
  42   42  static uint64_t dsl_dir_space_towrite(dsl_dir_t *dd);
  43   43  
  44   44  /* ARGSUSED */
  45   45  static void
  46      -dsl_dir_evict(dmu_buf_t *db, void *arg)
       46 +dsl_dir_evict(dmu_buf_user_t *dbu)
  47   47  {
  48      -        dsl_dir_t *dd = arg;
       48 +        dsl_dir_t *dd = (dsl_dir_t *)dbu;
  49   49          dsl_pool_t *dp = dd->dd_pool;
  50   50          int t;
  51   51  
       52 +        dd->dd_dbuf = NULL;
       53 +
  52   54          for (t = 0; t < TXG_SIZE; t++) {
  53   55                  ASSERT(!txg_list_member(&dp->dp_dirty_dirs, dd, t));
  54   56                  ASSERT(dd->dd_tempreserved[t] == 0);
  55   57                  ASSERT(dd->dd_space_towrite[t] == 0);
  56   58          }
  57   59  
  58   60          if (dd->dd_parent)
  59   61                  dsl_dir_rele(dd->dd_parent, dd);
  60   62  
  61   63          spa_close(dd->dd_pool->dp_spa, dd);
↓ open down ↓ 13 lines elided ↑ open up ↑
  75   77  {
  76   78          dmu_buf_t *dbuf;
  77   79          dsl_dir_t *dd;
  78   80          int err;
  79   81  
  80   82          ASSERT(dsl_pool_config_held(dp));
  81   83  
  82   84          err = dmu_bonus_hold(dp->dp_meta_objset, ddobj, tag, &dbuf);
  83   85          if (err != 0)
  84   86                  return (err);
  85      -        dd = dmu_buf_get_user(dbuf);
       87 +        dd = (dsl_dir_t *)dmu_buf_get_user(dbuf);
  86   88  #ifdef ZFS_DEBUG
  87   89          {
  88   90                  dmu_object_info_t doi;
  89   91                  dmu_object_info_from_db(dbuf, &doi);
  90   92                  ASSERT3U(doi.doi_type, ==, DMU_OT_DSL_DIR);
  91   93                  ASSERT3U(doi.doi_bonus_size, >=, sizeof (dsl_dir_phys_t));
  92   94          }
  93   95  #endif
  94   96          if (dd == NULL) {
  95   97                  dsl_dir_t *winner;
  96   98  
  97   99                  dd = kmem_zalloc(sizeof (dsl_dir_t), KM_SLEEP);
  98  100                  dd->dd_object = ddobj;
  99  101                  dd->dd_dbuf = dbuf;
 100  102                  dd->dd_pool = dp;
 101      -                dd->dd_phys = dbuf->db_data;
 102  103                  mutex_init(&dd->dd_lock, NULL, MUTEX_DEFAULT, NULL);
 103  104  
 104  105                  list_create(&dd->dd_prop_cbs, sizeof (dsl_prop_cb_record_t),
 105  106                      offsetof(dsl_prop_cb_record_t, cbr_node));
 106  107  
 107  108                  dsl_dir_snap_cmtime_update(dd);
 108  109  
 109  110                  if (dd->dd_phys->dd_parent_obj) {
 110  111                          err = dsl_dir_hold_obj(dp, dd->dd_phys->dd_parent_obj,
 111  112                              NULL, dd, &dd->dd_parent);
↓ open down ↓ 32 lines elided ↑ open up ↑
 144  145                          err = dmu_bonus_hold(dp->dp_meta_objset,
 145  146                              dd->dd_phys->dd_origin_obj, FTAG, &origin_bonus);
 146  147                          if (err != 0)
 147  148                                  goto errout;
 148  149                          origin_phys = origin_bonus->db_data;
 149  150                          dd->dd_origin_txg =
 150  151                              origin_phys->ds_creation_txg;
 151  152                          dmu_buf_rele(origin_bonus, FTAG);
 152  153                  }
 153  154  
 154      -                winner = dmu_buf_set_user_ie(dbuf, dd, &dd->dd_phys,
 155      -                    dsl_dir_evict);
      155 +                dmu_buf_init_user(&dd->db_evict, dsl_dir_evict);
      156 +                winner = (dsl_dir_t *)dmu_buf_set_user_ie(dbuf, &dd->db_evict);
 156  157                  if (winner) {
 157  158                          if (dd->dd_parent)
 158  159                                  dsl_dir_rele(dd->dd_parent, dd);
 159  160                          mutex_destroy(&dd->dd_lock);
 160  161                          kmem_free(dd, sizeof (dsl_dir_t));
 161  162                          dd = winner;
 162  163                  } else {
 163  164                          spa_open_ref(dp->dp_spa, dd);
 164  165                  }
 165  166          }
↓ open down ↓ 1179 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX