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/sa.c
          +++ new/usr/src/uts/common/fs/zfs/sa.c
↓ open down ↓ 1291 lines elided ↑ open up ↑
1292 1292                  hdl->sa_bonus_tab = idx_tab;
1293 1293          else
1294 1294                  hdl->sa_spill_tab = idx_tab;
1295 1295  
1296 1296          mutex_exit(&sa->sa_lock);
1297 1297          return (0);
1298 1298  }
1299 1299  
1300 1300  /*ARGSUSED*/
1301 1301  void
1302      -sa_evict(dmu_buf_t *db, void *sap)
     1302 +sa_evict(dmu_buf_user_t *dbu)
1303 1303  {
1304      -        panic("evicting sa dbuf %p\n", (void *)db);
     1304 +        panic("evicting sa dbuf\n");
1305 1305  }
1306 1306  
1307 1307  static void
1308 1308  sa_idx_tab_rele(objset_t *os, void *arg)
1309 1309  {
1310 1310          sa_os_t *sa = os->os_sa;
1311 1311          sa_idx_tab_t *idx_tab = arg;
1312 1312  
1313 1313          if (idx_tab == NULL)
1314 1314                  return;
↓ open down ↓ 18 lines elided ↑ open up ↑
1333 1333  {
1334 1334          sa_os_t *sa = os->os_sa;
1335 1335  
1336 1336          ASSERT(MUTEX_HELD(&sa->sa_lock));
1337 1337          (void) refcount_add(&idx_tab->sa_refcount, NULL);
1338 1338  }
1339 1339  
1340 1340  void
1341 1341  sa_handle_destroy(sa_handle_t *hdl)
1342 1342  {
     1343 +        dmu_buf_t *db = hdl->sa_bonus;
     1344 +
1343 1345          mutex_enter(&hdl->sa_lock);
1344      -        (void) dmu_buf_update_user((dmu_buf_t *)hdl->sa_bonus, hdl,
1345      -            NULL, NULL, NULL);
     1346 +        (void) dmu_buf_remove_user(db, &hdl->db_evict);
1346 1347  
1347 1348          if (hdl->sa_bonus_tab) {
1348 1349                  sa_idx_tab_rele(hdl->sa_os, hdl->sa_bonus_tab);
1349 1350                  hdl->sa_bonus_tab = NULL;
1350 1351          }
1351 1352          if (hdl->sa_spill_tab) {
1352 1353                  sa_idx_tab_rele(hdl->sa_os, hdl->sa_spill_tab);
1353 1354                  hdl->sa_spill_tab = NULL;
1354 1355          }
1355 1356  
↓ open down ↓ 5 lines elided ↑ open up ↑
1361 1362  
1362 1363          kmem_cache_free(sa_cache, hdl);
1363 1364  }
1364 1365  
1365 1366  int
1366 1367  sa_handle_get_from_db(objset_t *os, dmu_buf_t *db, void *userp,
1367 1368      sa_handle_type_t hdl_type, sa_handle_t **handlepp)
1368 1369  {
1369 1370          int error = 0;
1370 1371          dmu_object_info_t doi;
1371      -        sa_handle_t *handle;
     1372 +        sa_handle_t *handle = NULL;
1372 1373  
1373 1374  #ifdef ZFS_DEBUG
1374 1375          dmu_object_info_from_db(db, &doi);
1375 1376          ASSERT(doi.doi_bonus_type == DMU_OT_SA ||
1376 1377              doi.doi_bonus_type == DMU_OT_ZNODE);
1377 1378  #endif
1378 1379          /* find handle, if it exists */
1379 1380          /* if one doesn't exist then create a new one, and initialize it */
1380 1381  
1381      -        handle = (hdl_type == SA_HDL_SHARED) ? dmu_buf_get_user(db) : NULL;
     1382 +        if (hdl_type == SA_HDL_SHARED)
     1383 +                handle = (sa_handle_t *)dmu_buf_get_user(db);
     1384 +
1382 1385          if (handle == NULL) {
1383      -                sa_handle_t *newhandle;
     1386 +                sa_handle_t *winner = NULL;
     1387 +
     1388 +                bzero(&handle->db_evict, sizeof(dmu_buf_user_t));
1384 1389                  handle = kmem_cache_alloc(sa_cache, KM_SLEEP);
1385 1390                  handle->sa_userp = userp;
1386 1391                  handle->sa_bonus = db;
1387 1392                  handle->sa_os = os;
1388 1393                  handle->sa_spill = NULL;
1389 1394  
1390 1395                  error = sa_build_index(handle, SA_BONUS);
1391      -                newhandle = (hdl_type == SA_HDL_SHARED) ?
1392      -                    dmu_buf_set_user_ie(db, handle,
1393      -                    NULL, sa_evict) : NULL;
1394      -
1395      -                if (newhandle != NULL) {
     1396 +                if (hdl_type == SA_HDL_SHARED) {
     1397 +                        dmu_buf_init_user(&handle->db_evict, sa_evict);
     1398 +                        winner = (sa_handle_t *)
     1399 +                            dmu_buf_set_user_ie(db, &handle->db_evict);
     1400 +                }
     1401 +                if (winner != NULL) {
1396 1402                          kmem_cache_free(sa_cache, handle);
1397      -                        handle = newhandle;
     1403 +                        handle = winner;
1398 1404                  }
1399 1405          }
1400 1406          *handlepp = handle;
1401 1407  
1402 1408          return (error);
1403 1409  }
1404 1410  
1405 1411  int
1406 1412  sa_handle_get(objset_t *objset, uint64_t objid, void *userp,
1407 1413      sa_handle_type_t hdl_type, sa_handle_t **handlepp)
↓ open down ↓ 492 lines elided ↑ open up ↑
1900 1906  void
1901 1907  sa_object_size(sa_handle_t *hdl, uint32_t *blksize, u_longlong_t *nblocks)
1902 1908  {
1903 1909          dmu_object_size_from_db((dmu_buf_t *)hdl->sa_bonus,
1904 1910              blksize, nblocks);
1905 1911  }
1906 1912  
1907 1913  void
1908 1914  sa_update_user(sa_handle_t *newhdl, sa_handle_t *oldhdl)
1909 1915  {
1910      -        (void) dmu_buf_update_user((dmu_buf_t *)newhdl->sa_bonus,
1911      -            oldhdl, newhdl, NULL, sa_evict);
     1916 +        dmu_buf_user_t *new_user = &newhdl->db_evict;
     1917 +        dmu_buf_user_t *old_user = &oldhdl->db_evict;
     1918 +
     1919 +        dmu_buf_init_user(new_user, sa_evict);
     1920 +        VERIFY(dmu_buf_replace_user(newhdl->sa_bonus, old_user,
     1921 +            new_user) == old_user);
1912 1922          oldhdl->sa_bonus = NULL;
1913 1923  }
1914 1924  
1915 1925  void
1916 1926  sa_set_userp(sa_handle_t *hdl, void *ptr)
1917 1927  {
1918 1928          hdl->sa_userp = ptr;
1919 1929  }
1920 1930  
1921 1931  dmu_buf_t *
↓ open down ↓ 73 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX