Deleted Added
full compact
sa.c (286539) sa.c (286575)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 9 unchanged lines hidden (view full) ---

18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 * Portions Copyright 2011 iXsystems, Inc
25 * Copyright (c) 2013 by Delphix. All rights reserved.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 9 unchanged lines hidden (view full) ---

18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 * Portions Copyright 2011 iXsystems, Inc
25 * Copyright (c) 2013 by Delphix. All rights reserved.
26 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
26 */
27
28#include <sys/zfs_context.h>
29#include <sys/types.h>
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/sysmacros.h>
33#include <sys/dmu.h>

--- 180 unchanged lines hidden (view full) ---

214 return (0);
215}
216
217/*ARGSUSED*/
218static void
219sa_cache_destructor(void *buf, void *unused)
220{
221 sa_handle_t *hdl = buf;
27 */
28
29#include <sys/zfs_context.h>
30#include <sys/types.h>
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/sysmacros.h>
34#include <sys/dmu.h>

--- 180 unchanged lines hidden (view full) ---

215 return (0);
216}
217
218/*ARGSUSED*/
219static void
220sa_cache_destructor(void *buf, void *unused)
221{
222 sa_handle_t *hdl = buf;
223 hdl->sa_dbu.dbu_evict_func = NULL;
222 mutex_destroy(&hdl->sa_lock);
223}
224
225void
226sa_cache_init(void)
227{
228 sa_cache = kmem_cache_create("sa_cache",
229 sizeof (sa_handle_t), 0, sa_cache_constructor,

--- 1063 unchanged lines hidden (view full) ---

1293 else
1294 hdl->sa_spill_tab = idx_tab;
1295
1296 mutex_exit(&sa->sa_lock);
1297 return (0);
1298}
1299
1300/*ARGSUSED*/
224 mutex_destroy(&hdl->sa_lock);
225}
226
227void
228sa_cache_init(void)
229{
230 sa_cache = kmem_cache_create("sa_cache",
231 sizeof (sa_handle_t), 0, sa_cache_constructor,

--- 1063 unchanged lines hidden (view full) ---

1295 else
1296 hdl->sa_spill_tab = idx_tab;
1297
1298 mutex_exit(&sa->sa_lock);
1299 return (0);
1300}
1301
1302/*ARGSUSED*/
1301void
1302sa_evict(dmu_buf_t *db, void *sap)
1303static void
1304sa_evict(void *dbu)
1303{
1305{
1304 panic("evicting sa dbuf %p\n", (void *)db);
1306 panic("evicting sa dbuf\n");
1305}
1306
1307static void
1308sa_idx_tab_rele(objset_t *os, void *arg)
1309{
1310 sa_os_t *sa = os->os_sa;
1311 sa_idx_tab_t *idx_tab = arg;
1312

--- 22 unchanged lines hidden (view full) ---

1335
1336 ASSERT(MUTEX_HELD(&sa->sa_lock));
1337 (void) refcount_add(&idx_tab->sa_refcount, NULL);
1338}
1339
1340void
1341sa_handle_destroy(sa_handle_t *hdl)
1342{
1307}
1308
1309static void
1310sa_idx_tab_rele(objset_t *os, void *arg)
1311{
1312 sa_os_t *sa = os->os_sa;
1313 sa_idx_tab_t *idx_tab = arg;
1314

--- 22 unchanged lines hidden (view full) ---

1337
1338 ASSERT(MUTEX_HELD(&sa->sa_lock));
1339 (void) refcount_add(&idx_tab->sa_refcount, NULL);
1340}
1341
1342void
1343sa_handle_destroy(sa_handle_t *hdl)
1344{
1345 dmu_buf_t *db = hdl->sa_bonus;
1346
1343 mutex_enter(&hdl->sa_lock);
1347 mutex_enter(&hdl->sa_lock);
1344 (void) dmu_buf_update_user((dmu_buf_t *)hdl->sa_bonus, hdl,
1345 NULL, NULL);
1348 (void) dmu_buf_remove_user(db, &hdl->sa_dbu);
1346
1347 if (hdl->sa_bonus_tab)
1348 sa_idx_tab_rele(hdl->sa_os, hdl->sa_bonus_tab);
1349
1350 if (hdl->sa_spill_tab)
1351 sa_idx_tab_rele(hdl->sa_os, hdl->sa_spill_tab);
1352
1353 dmu_buf_rele(hdl->sa_bonus, NULL);

--- 6 unchanged lines hidden (view full) ---

1360}
1361
1362int
1363sa_handle_get_from_db(objset_t *os, dmu_buf_t *db, void *userp,
1364 sa_handle_type_t hdl_type, sa_handle_t **handlepp)
1365{
1366 int error = 0;
1367 dmu_object_info_t doi;
1349
1350 if (hdl->sa_bonus_tab)
1351 sa_idx_tab_rele(hdl->sa_os, hdl->sa_bonus_tab);
1352
1353 if (hdl->sa_spill_tab)
1354 sa_idx_tab_rele(hdl->sa_os, hdl->sa_spill_tab);
1355
1356 dmu_buf_rele(hdl->sa_bonus, NULL);

--- 6 unchanged lines hidden (view full) ---

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

--- 501 unchanged lines hidden (view full) ---

1905void
1906sa_object_size(sa_handle_t *hdl, uint32_t *blksize, u_longlong_t *nblocks)
1907{
1908 dmu_object_size_from_db((dmu_buf_t *)hdl->sa_bonus,
1909 blksize, nblocks);
1910}
1911
1912void
1405 }
1406 }
1407 *handlepp = handle;
1408
1409 return (error);
1410}
1411
1412int

--- 501 unchanged lines hidden (view full) ---

1914void
1915sa_object_size(sa_handle_t *hdl, uint32_t *blksize, u_longlong_t *nblocks)
1916{
1917 dmu_object_size_from_db((dmu_buf_t *)hdl->sa_bonus,
1918 blksize, nblocks);
1919}
1920
1921void
1913sa_update_user(sa_handle_t *newhdl, sa_handle_t *oldhdl)
1914{
1915 (void) dmu_buf_update_user((dmu_buf_t *)newhdl->sa_bonus,
1916 oldhdl, newhdl, sa_evict);
1917 oldhdl->sa_bonus = NULL;
1918}
1919
1920void
1921sa_set_userp(sa_handle_t *hdl, void *ptr)
1922{
1923 hdl->sa_userp = ptr;
1924}
1925
1926dmu_buf_t *
1927sa_get_db(sa_handle_t *hdl)
1928{

--- 71 unchanged lines hidden ---
1922sa_set_userp(sa_handle_t *hdl, void *ptr)
1923{
1924 hdl->sa_userp = ptr;
1925}
1926
1927dmu_buf_t *
1928sa_get_db(sa_handle_t *hdl)
1929{

--- 71 unchanged lines hidden ---