Print this page
patch first-pass


1363 {
1364         int error = 0;
1365         dmu_object_info_t doi;
1366         sa_handle_t *handle = NULL;
1367 
1368 #ifdef ZFS_DEBUG
1369         dmu_object_info_from_db(db, &doi);
1370         ASSERT(doi.doi_bonus_type == DMU_OT_SA ||
1371             doi.doi_bonus_type == DMU_OT_ZNODE);
1372 #endif
1373         /* find handle, if it exists */
1374         /* if one doesn't exist then create a new one, and initialize it */
1375 
1376         if (hdl_type == SA_HDL_SHARED)
1377                 handle = dmu_buf_get_user(db);
1378 
1379         if (handle == NULL) {
1380                 sa_handle_t *winner = NULL;
1381 
1382                 handle = kmem_cache_alloc(sa_cache, KM_SLEEP);

1383                 handle->sa_dbu.dbu_evict_func = NULL;
1384                 handle->sa_userp = userp;
1385                 handle->sa_bonus = db;
1386                 handle->sa_os = os;
1387                 handle->sa_spill = NULL;
1388                 handle->sa_bonus_tab = NULL;
1389                 handle->sa_spill_tab = NULL;
1390 
1391                 error = sa_build_index(handle, SA_BONUS);
1392 
1393                 if (hdl_type == SA_HDL_SHARED) {
1394                         dmu_buf_init_user(&handle->sa_dbu, sa_evict, NULL);

1395                         winner = dmu_buf_set_user_ie(db, &handle->sa_dbu);
1396                 }
1397 
1398                 if (winner != NULL) {
1399                         kmem_cache_free(sa_cache, handle);
1400                         handle = winner;
1401                 }
1402         }
1403         *handlepp = handle;
1404 
1405         return (error);
1406 }
1407 
1408 int
1409 sa_handle_get(objset_t *objset, uint64_t objid, void *userp,
1410     sa_handle_type_t hdl_type, sa_handle_t **handlepp)
1411 {
1412         dmu_buf_t *db;
1413         int error;
1414 




1363 {
1364         int error = 0;
1365         dmu_object_info_t doi;
1366         sa_handle_t *handle = NULL;
1367 
1368 #ifdef ZFS_DEBUG
1369         dmu_object_info_from_db(db, &doi);
1370         ASSERT(doi.doi_bonus_type == DMU_OT_SA ||
1371             doi.doi_bonus_type == DMU_OT_ZNODE);
1372 #endif
1373         /* find handle, if it exists */
1374         /* if one doesn't exist then create a new one, and initialize it */
1375 
1376         if (hdl_type == SA_HDL_SHARED)
1377                 handle = dmu_buf_get_user(db);
1378 
1379         if (handle == NULL) {
1380                 sa_handle_t *winner = NULL;
1381 
1382                 handle = kmem_cache_alloc(sa_cache, KM_SLEEP);
1383                 handle->sa_dbu.dbu_evict_func_prep = NULL;
1384                 handle->sa_dbu.dbu_evict_func = NULL;
1385                 handle->sa_userp = userp;
1386                 handle->sa_bonus = db;
1387                 handle->sa_os = os;
1388                 handle->sa_spill = NULL;
1389                 handle->sa_bonus_tab = NULL;
1390                 handle->sa_spill_tab = NULL;
1391 
1392                 error = sa_build_index(handle, SA_BONUS);
1393 
1394                 if (hdl_type == SA_HDL_SHARED) {
1395                         dmu_buf_init_user(&handle->sa_dbu, NULL, sa_evict,
1396                             NULL);
1397                         winner = dmu_buf_set_user_ie(db, &handle->sa_dbu);
1398                 }
1399 
1400                 if (winner != NULL) {
1401                         kmem_cache_free(sa_cache, handle);
1402                         handle = winner;
1403                 }
1404         }
1405         *handlepp = handle;
1406 
1407         return (error);
1408 }
1409 
1410 int
1411 sa_handle_get(objset_t *objset, uint64_t objid, void *userp,
1412     sa_handle_type_t hdl_type, sa_handle_t **handlepp)
1413 {
1414         dmu_buf_t *db;
1415         int error;
1416