10a586ceaSMark Shellenbaum /* 20a586ceaSMark Shellenbaum * CDDL HEADER START 30a586ceaSMark Shellenbaum * 40a586ceaSMark Shellenbaum * The contents of this file are subject to the terms of the 50a586ceaSMark Shellenbaum * Common Development and Distribution License (the "License"). 60a586ceaSMark Shellenbaum * You may not use this file except in compliance with the License. 70a586ceaSMark Shellenbaum * 80a586ceaSMark Shellenbaum * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90a586ceaSMark Shellenbaum * or http://www.opensolaris.org/os/licensing. 100a586ceaSMark Shellenbaum * See the License for the specific language governing permissions 110a586ceaSMark Shellenbaum * and limitations under the License. 120a586ceaSMark Shellenbaum * 130a586ceaSMark Shellenbaum * When distributing Covered Code, include this CDDL HEADER in each 140a586ceaSMark Shellenbaum * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150a586ceaSMark Shellenbaum * If applicable, add the following below this CDDL HEADER, with the 160a586ceaSMark Shellenbaum * fields enclosed by brackets "[]" replaced with your own identifying 170a586ceaSMark Shellenbaum * information: Portions Copyright [yyyy] [name of copyright owner] 180a586ceaSMark Shellenbaum * 190a586ceaSMark Shellenbaum * CDDL HEADER END 200a586ceaSMark Shellenbaum */ 210a586ceaSMark Shellenbaum /* 22*1d8ccc7bSMark Shellenbaum * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 230a586ceaSMark Shellenbaum */ 240a586ceaSMark Shellenbaum 250a586ceaSMark Shellenbaum #ifndef _SYS_SA_H 260a586ceaSMark Shellenbaum #define _SYS_SA_H 270a586ceaSMark Shellenbaum 280a586ceaSMark Shellenbaum #include <sys/dmu.h> 290a586ceaSMark Shellenbaum 300a586ceaSMark Shellenbaum /* 310a586ceaSMark Shellenbaum * Currently available byteswap functions. 320a586ceaSMark Shellenbaum * If it all possible new attributes should used 330a586ceaSMark Shellenbaum * one of the already defined byteswap functions. 340a586ceaSMark Shellenbaum * If a new byteswap function is added then the 350a586ceaSMark Shellenbaum * ZPL/Pool version will need to be bumped. 360a586ceaSMark Shellenbaum */ 370a586ceaSMark Shellenbaum 380a586ceaSMark Shellenbaum typedef enum sa_bswap_type { 390a586ceaSMark Shellenbaum SA_UINT64_ARRAY, 400a586ceaSMark Shellenbaum SA_UINT32_ARRAY, 410a586ceaSMark Shellenbaum SA_UINT16_ARRAY, 420a586ceaSMark Shellenbaum SA_UINT8_ARRAY, 430a586ceaSMark Shellenbaum SA_ACL, 440a586ceaSMark Shellenbaum } sa_bswap_type_t; 450a586ceaSMark Shellenbaum 460a586ceaSMark Shellenbaum typedef uint16_t sa_attr_type_t; 470a586ceaSMark Shellenbaum 480a586ceaSMark Shellenbaum /* 490a586ceaSMark Shellenbaum * Attribute to register support for. 500a586ceaSMark Shellenbaum */ 510a586ceaSMark Shellenbaum typedef struct sa_attr_reg { 520a586ceaSMark Shellenbaum char *sa_name; /* attribute name */ 530a586ceaSMark Shellenbaum uint16_t sa_length; 540a586ceaSMark Shellenbaum sa_bswap_type_t sa_byteswap; /* bswap functon enum */ 550a586ceaSMark Shellenbaum sa_attr_type_t sa_attr; /* filled in during registration */ 560a586ceaSMark Shellenbaum } sa_attr_reg_t; 570a586ceaSMark Shellenbaum 580a586ceaSMark Shellenbaum 590a586ceaSMark Shellenbaum typedef void (sa_data_locator_t)(void **, uint32_t *, uint32_t, 600a586ceaSMark Shellenbaum boolean_t, void *userptr); 610a586ceaSMark Shellenbaum 620a586ceaSMark Shellenbaum /* 630a586ceaSMark Shellenbaum * array of attributes to store. 640a586ceaSMark Shellenbaum * 650a586ceaSMark Shellenbaum * This array should be treated as opaque/private data. 660a586ceaSMark Shellenbaum * The SA_BULK_ADD_ATTR() macro should be used for manipulating 670a586ceaSMark Shellenbaum * the array. 680a586ceaSMark Shellenbaum * 690a586ceaSMark Shellenbaum * When sa_replace_all_by_template() is used the attributes 700a586ceaSMark Shellenbaum * will be stored in the order defined in the array, except that 710a586ceaSMark Shellenbaum * the attributes may be split between the bonus and the spill buffer 720a586ceaSMark Shellenbaum * 730a586ceaSMark Shellenbaum */ 740a586ceaSMark Shellenbaum typedef struct sa_bulk_attr { 750a586ceaSMark Shellenbaum void *sa_data; 760a586ceaSMark Shellenbaum sa_data_locator_t *sa_data_func; 770a586ceaSMark Shellenbaum uint16_t sa_length; 780a586ceaSMark Shellenbaum sa_attr_type_t sa_attr; 790a586ceaSMark Shellenbaum /* the following are private to the sa framework */ 800a586ceaSMark Shellenbaum void *sa_addr; 810a586ceaSMark Shellenbaum uint16_t sa_buftype; 820a586ceaSMark Shellenbaum uint16_t sa_size; 830a586ceaSMark Shellenbaum } sa_bulk_attr_t; 840a586ceaSMark Shellenbaum 850a586ceaSMark Shellenbaum 860a586ceaSMark Shellenbaum /* 870a586ceaSMark Shellenbaum * special macro for adding entries for bulk attr support 880a586ceaSMark Shellenbaum * bulk - sa_bulk_attr_t 890a586ceaSMark Shellenbaum * count - integer that will be incremented during each add 900a586ceaSMark Shellenbaum * attr - attribute to manipulate 910a586ceaSMark Shellenbaum * func - function for accessing data. 920a586ceaSMark Shellenbaum * data - pointer to data. 930a586ceaSMark Shellenbaum * len - length of data 940a586ceaSMark Shellenbaum */ 950a586ceaSMark Shellenbaum 960a586ceaSMark Shellenbaum #define SA_ADD_BULK_ATTR(b, idx, attr, func, data, len) \ 970a586ceaSMark Shellenbaum { \ 980a586ceaSMark Shellenbaum b[idx].sa_attr = attr;\ 990a586ceaSMark Shellenbaum b[idx].sa_data_func = func; \ 1000a586ceaSMark Shellenbaum b[idx].sa_data = data; \ 1010a586ceaSMark Shellenbaum b[idx++].sa_length = len; \ 1020a586ceaSMark Shellenbaum } 1030a586ceaSMark Shellenbaum 1040a586ceaSMark Shellenbaum typedef struct sa_os sa_os_t; 1050a586ceaSMark Shellenbaum 1060a586ceaSMark Shellenbaum typedef enum sa_handle_type { 1070a586ceaSMark Shellenbaum SA_HDL_SHARED, 1080a586ceaSMark Shellenbaum SA_HDL_PRIVATE 1090a586ceaSMark Shellenbaum } sa_handle_type_t; 1100a586ceaSMark Shellenbaum 1110a586ceaSMark Shellenbaum struct sa_handle; 1120a586ceaSMark Shellenbaum typedef void *sa_lookup_tab_t; 1130a586ceaSMark Shellenbaum typedef struct sa_handle sa_handle_t; 1140a586ceaSMark Shellenbaum 1150a586ceaSMark Shellenbaum typedef void (sa_update_cb_t)(sa_handle_t *, dmu_tx_t *tx); 1160a586ceaSMark Shellenbaum 1170a586ceaSMark Shellenbaum int sa_handle_get(objset_t *, uint64_t, void *userp, 1180a586ceaSMark Shellenbaum sa_handle_type_t, sa_handle_t **); 1190a586ceaSMark Shellenbaum int sa_handle_get_from_db(objset_t *, dmu_buf_t *, void *userp, 1200a586ceaSMark Shellenbaum sa_handle_type_t, sa_handle_t **); 1210a586ceaSMark Shellenbaum void sa_handle_destroy(sa_handle_t *); 1220a586ceaSMark Shellenbaum int sa_buf_hold(objset_t *, uint64_t, void *, dmu_buf_t **); 1230a586ceaSMark Shellenbaum void sa_buf_rele(dmu_buf_t *, void *); 1240a586ceaSMark Shellenbaum int sa_lookup(sa_handle_t *, sa_attr_type_t, void *buf, uint32_t buflen); 1250a586ceaSMark Shellenbaum int sa_update(sa_handle_t *, sa_attr_type_t, void *buf, 1260a586ceaSMark Shellenbaum uint32_t buflen, dmu_tx_t *); 1270a586ceaSMark Shellenbaum int sa_remove(sa_handle_t *, sa_attr_type_t, dmu_tx_t *); 1280a586ceaSMark Shellenbaum int sa_bulk_lookup(sa_handle_t *, sa_bulk_attr_t *, int count); 1290a586ceaSMark Shellenbaum int sa_bulk_lookup_locked(sa_handle_t *, sa_bulk_attr_t *, int count); 1300a586ceaSMark Shellenbaum int sa_bulk_update(sa_handle_t *, sa_bulk_attr_t *, int count, dmu_tx_t *); 1310a586ceaSMark Shellenbaum int sa_size(sa_handle_t *, sa_attr_type_t, int *); 1320a586ceaSMark Shellenbaum int sa_update_from_cb(sa_handle_t *, sa_attr_type_t, 1330a586ceaSMark Shellenbaum uint32_t buflen, sa_data_locator_t *, void *userdata, dmu_tx_t *); 1340a586ceaSMark Shellenbaum void sa_object_info(sa_handle_t *, dmu_object_info_t *); 1350a586ceaSMark Shellenbaum void sa_object_size(sa_handle_t *, uint32_t *, u_longlong_t *); 1360a586ceaSMark Shellenbaum void *sa_get_userdata(sa_handle_t *); 1370a586ceaSMark Shellenbaum void sa_set_userp(sa_handle_t *, void *); 1380a586ceaSMark Shellenbaum dmu_buf_t *sa_get_db(sa_handle_t *); 1390a586ceaSMark Shellenbaum uint64_t sa_handle_object(sa_handle_t *); 1400a586ceaSMark Shellenbaum boolean_t sa_attr_would_spill(sa_handle_t *, sa_attr_type_t, int size); 1410a586ceaSMark Shellenbaum void sa_register_update_callback(objset_t *, sa_update_cb_t *); 142*1d8ccc7bSMark Shellenbaum int sa_setup(objset_t *, uint64_t, sa_attr_reg_t *, int, sa_attr_type_t **); 1430a586ceaSMark Shellenbaum void sa_tear_down(objset_t *); 1440a586ceaSMark Shellenbaum int sa_replace_all_by_template(sa_handle_t *, sa_bulk_attr_t *, 1450a586ceaSMark Shellenbaum int, dmu_tx_t *); 1460a586ceaSMark Shellenbaum int sa_replace_all_by_template_locked(sa_handle_t *, sa_bulk_attr_t *, 1470a586ceaSMark Shellenbaum int, dmu_tx_t *); 1480a586ceaSMark Shellenbaum boolean_t sa_enabled(objset_t *); 1490a586ceaSMark Shellenbaum void sa_cache_init(); 1500a586ceaSMark Shellenbaum void sa_cache_fini(); 1510a586ceaSMark Shellenbaum int sa_set_sa_object(objset_t *, uint64_t); 1520a586ceaSMark Shellenbaum int sa_hdrsize(void *); 1530a586ceaSMark Shellenbaum void sa_handle_lock(sa_handle_t *); 1540a586ceaSMark Shellenbaum void sa_handle_unlock(sa_handle_t *); 1550a586ceaSMark Shellenbaum 1560a586ceaSMark Shellenbaum #ifdef _KERNEL 1570a586ceaSMark Shellenbaum int sa_lookup_uio(sa_handle_t *, sa_attr_type_t, uio_t *); 1580a586ceaSMark Shellenbaum #endif 1590a586ceaSMark Shellenbaum 1600a586ceaSMark Shellenbaum #ifdef __cplusplus 1610a586ceaSMark Shellenbaum extern "C" { 1620a586ceaSMark Shellenbaum #endif 1630a586ceaSMark Shellenbaum 1640a586ceaSMark Shellenbaum 1650a586ceaSMark Shellenbaum #ifdef __cplusplus 1660a586ceaSMark Shellenbaum } 1670a586ceaSMark Shellenbaum #endif 1680a586ceaSMark Shellenbaum 1690a586ceaSMark Shellenbaum #endif /* _SYS_SA_H */ 170