FreeBSD ZFS
The Zettabyte File System
|
00001 /* 00002 * CDDL HEADER START 00003 * 00004 * The contents of this file are subject to the terms of the 00005 * Common Development and Distribution License (the "License"). 00006 * You may not use this file except in compliance with the License. 00007 * 00008 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 00009 * or http://www.opensolaris.org/os/licensing. 00010 * See the License for the specific language governing permissions 00011 * and limitations under the License. 00012 * 00013 * When distributing Covered Code, include this CDDL HEADER in each 00014 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 00015 * If applicable, add the following below this CDDL HEADER, with the 00016 * fields enclosed by brackets "[]" replaced with your own identifying 00017 * information: Portions Copyright [yyyy] [name of copyright owner] 00018 * 00019 * CDDL HEADER END 00020 */ 00021 /* 00022 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 00023 * Use is subject to license terms. 00024 */ 00025 00026 #ifndef _SYS_SPACE_MAP_H 00027 #define _SYS_SPACE_MAP_H 00028 00029 #include <sys/avl.h> 00030 #include <sys/dmu.h> 00031 00032 #ifdef __cplusplus 00033 extern "C" { 00034 #endif 00035 00036 typedef struct space_map_ops space_map_ops_t; 00037 00038 typedef struct space_map { 00039 avl_tree_t sm_root; 00040 uint64_t sm_space; 00041 uint64_t sm_start; 00042 uint64_t sm_size; 00043 uint8_t sm_shift; 00044 uint8_t sm_pad[3]; 00045 uint8_t sm_loaded; 00046 uint8_t sm_loading; 00047 kcondvar_t sm_load_cv; 00048 space_map_ops_t *sm_ops; 00049 avl_tree_t *sm_pp_root; 00050 void *sm_ppd; 00051 kmutex_t *sm_lock; 00052 } space_map_t; 00053 00054 typedef struct space_seg { 00055 avl_node_t ss_node; 00056 avl_node_t ss_pp_node; 00057 uint64_t ss_start; 00058 uint64_t ss_end; 00059 } space_seg_t; 00060 00061 typedef struct space_ref { 00062 avl_node_t sr_node; 00063 uint64_t sr_offset; 00064 int64_t sr_refcnt; 00065 } space_ref_t; 00066 00067 typedef struct space_map_obj { 00068 uint64_t smo_object; 00069 uint64_t smo_objsize; 00070 uint64_t smo_alloc; 00071 } space_map_obj_t; 00072 00073 struct space_map_ops { 00074 void (*smop_load)(space_map_t *sm); 00075 void (*smop_unload)(space_map_t *sm); 00076 uint64_t (*smop_alloc)(space_map_t *sm, uint64_t size); 00077 void (*smop_claim)(space_map_t *sm, uint64_t start, uint64_t size); 00078 void (*smop_free)(space_map_t *sm, uint64_t start, uint64_t size); 00079 uint64_t (*smop_max)(space_map_t *sm); 00080 boolean_t (*smop_fragmented)(space_map_t *sm); 00081 }; 00082 00105 /* All this stuff takes and returns bytes */ 00106 #define SM_RUN_DECODE(x) (BF64_DECODE(x, 0, 15) + 1) 00107 #define SM_RUN_ENCODE(x) BF64_ENCODE((x) - 1, 0, 15) 00108 #define SM_TYPE_DECODE(x) BF64_DECODE(x, 15, 1) 00109 #define SM_TYPE_ENCODE(x) BF64_ENCODE(x, 15, 1) 00110 #define SM_OFFSET_DECODE(x) BF64_DECODE(x, 16, 47) 00111 #define SM_OFFSET_ENCODE(x) BF64_ENCODE(x, 16, 47) 00112 #define SM_DEBUG_DECODE(x) BF64_DECODE(x, 63, 1) 00113 #define SM_DEBUG_ENCODE(x) BF64_ENCODE(x, 63, 1) 00114 00115 #define SM_DEBUG_ACTION_DECODE(x) BF64_DECODE(x, 60, 3) 00116 #define SM_DEBUG_ACTION_ENCODE(x) BF64_ENCODE(x, 60, 3) 00117 00118 #define SM_DEBUG_SYNCPASS_DECODE(x) BF64_DECODE(x, 50, 10) 00119 #define SM_DEBUG_SYNCPASS_ENCODE(x) BF64_ENCODE(x, 50, 10) 00120 00121 #define SM_DEBUG_TXG_DECODE(x) BF64_DECODE(x, 0, 50) 00122 #define SM_DEBUG_TXG_ENCODE(x) BF64_ENCODE(x, 0, 50) 00123 00124 #define SM_RUN_MAX SM_RUN_DECODE(~0ULL) 00125 00126 #define SM_ALLOC 0x0 00127 #define SM_FREE 0x1 00128 00137 #define SPACE_MAP_BLOCKSHIFT 12 00138 00139 typedef void space_map_func_t(space_map_t *sm, uint64_t start, uint64_t size); 00140 00141 extern void space_map_create(space_map_t *sm, uint64_t start, uint64_t size, 00142 uint8_t shift, kmutex_t *lp); 00143 extern void space_map_destroy(space_map_t *sm); 00144 extern void space_map_add(space_map_t *sm, uint64_t start, uint64_t size); 00145 extern void space_map_remove(space_map_t *sm, uint64_t start, uint64_t size); 00146 extern boolean_t space_map_contains(space_map_t *sm, 00147 uint64_t start, uint64_t size); 00148 extern void space_map_vacate(space_map_t *sm, 00149 space_map_func_t *func, space_map_t *mdest); 00150 extern void space_map_walk(space_map_t *sm, 00151 space_map_func_t *func, space_map_t *mdest); 00152 00153 extern void space_map_load_wait(space_map_t *sm); 00154 extern int space_map_load(space_map_t *sm, space_map_ops_t *ops, 00155 uint8_t maptype, space_map_obj_t *smo, objset_t *os); 00156 extern void space_map_unload(space_map_t *sm); 00157 00158 extern uint64_t space_map_alloc(space_map_t *sm, uint64_t size); 00159 extern void space_map_claim(space_map_t *sm, uint64_t start, uint64_t size); 00160 extern void space_map_free(space_map_t *sm, uint64_t start, uint64_t size); 00161 extern uint64_t space_map_maxsize(space_map_t *sm); 00162 00163 extern void space_map_sync(space_map_t *sm, uint8_t maptype, 00164 space_map_obj_t *smo, objset_t *os, dmu_tx_t *tx); 00165 extern void space_map_truncate(space_map_obj_t *smo, 00166 objset_t *os, dmu_tx_t *tx); 00167 00168 extern void space_map_ref_create(avl_tree_t *t); 00169 extern void space_map_ref_destroy(avl_tree_t *t); 00170 extern void space_map_ref_add_seg(avl_tree_t *t, 00171 uint64_t start, uint64_t end, int64_t refcnt); 00172 extern void space_map_ref_add_map(avl_tree_t *t, 00173 space_map_t *sm, int64_t refcnt); 00174 extern void space_map_ref_generate_map(avl_tree_t *t, 00175 space_map_t *sm, int64_t minref); 00176 00177 #ifdef __cplusplus 00178 } 00179 #endif 00180 00181 #endif /* _SYS_SPACE_MAP_H */