1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 * Copyright by The HDF Group. * 3 * Copyright by the Board of Trustees of the University of Illinois. * 4 * All rights reserved. * 5 * * 6 * This file is part of HDF5. The full HDF5 copyright notice, including * 7 * terms governing use, modification, and redistribution, is contained in * 8 * the COPYING file, which can be found at the root of the source code * 9 * distribution tree, or in https://www.hdfgroup.org/licenses. * 10 * If you do not have access to either file, you may request a copy from * 11 * help@hdfgroup.org. * 12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 13 14 /*------------------------------------------------------------------------- 15 * 16 * Created: H5FSprivate.h 17 * May 2 2006 18 * Quincey Koziol 19 * 20 * Purpose: Private header for library accessible file free space routines. 21 * 22 *------------------------------------------------------------------------- 23 */ 24 25 #ifndef H5FSprivate_H 26 #define H5FSprivate_H 27 28 /* Private headers needed by this file */ 29 #include "H5Fprivate.h" /* File access */ 30 #include "H5FLprivate.h" /* Free Lists */ 31 32 /**************************/ 33 /* Library Private Macros */ 34 /**************************/ 35 36 /* Flags for H5FS_section_class_t 'flags' field */ 37 #define H5FS_CLS_GHOST_OBJ \ 38 0x01 /* Objects in this class shouldn't be \ 39 * serialized to the file. \ 40 */ 41 #define H5FS_CLS_SEPAR_OBJ \ 42 0x02 /* Objects in this class shouldn't \ 43 * participate in merge operations. \ 44 */ 45 #define H5FS_CLS_MERGE_SYM \ 46 0x04 /* Objects in this class only merge \ 47 * with other objects in this class. \ 48 */ 49 #define H5FS_CLS_ADJUST_OK \ 50 0x08 /* Objects in this class can be merged \ 51 * without requiring a can_adjust/adjust \ 52 * callback pair. \ 53 */ 54 55 /* Flags for H5FS_add() */ 56 #define H5FS_ADD_DESERIALIZING \ 57 0x01 /* Free space is being deserialized \ 58 */ 59 #define H5FS_ADD_RETURNED_SPACE \ 60 0x02 /* Section was previously allocated \ 61 * and is being returned to the \ 62 * free space manager (usually \ 63 * as a result of freeing an \ 64 * object) \ 65 */ 66 #define H5FS_ADD_SKIP_VALID \ 67 0x04 /* Don't check validity after adding \ 68 * this section. (state of the \ 69 * managed sections is in flux) \ 70 */ 71 72 #define H5FS_PAGE_END_NO_ADD \ 73 0x08 /* For "small" page fs: \ 74 * Don't add section to free space: \ 75 * when the section is at page end and \ 76 * when the section size is <= "small" \ 77 */ 78 79 /* Flags for deserialize callback */ 80 #define H5FS_DESERIALIZE_NO_ADD \ 81 0x01 /* Don't add section to free space \ 82 * manager after it's deserialized \ 83 * (its only here for it's side- \ 84 * effects). \ 85 */ 86 87 /****************************/ 88 /* Library Private Typedefs */ 89 /****************************/ 90 91 /* Free space info (forward decl - defined in H5FSpkg.h) */ 92 typedef struct H5FS_t H5FS_t; 93 94 /* Forward declaration free space section info */ 95 typedef struct H5FS_section_info_t H5FS_section_info_t; 96 97 /* Free space section class info */ 98 typedef struct H5FS_section_class_t { 99 /* Class variables */ 100 const unsigned type; /* Type of free space section */ 101 size_t serial_size; /* Size of serialized form of section */ 102 unsigned flags; /* Class flags */ 103 void * cls_private; /* Class private information */ 104 105 /* Class methods */ 106 herr_t (*init_cls)(struct H5FS_section_class_t *, 107 void *); /* Routine to initialize class-specific settings */ 108 herr_t (*term_cls)(struct H5FS_section_class_t *); /* Routine to terminate class-specific settings */ 109 110 /* Object methods */ 111 herr_t (*add)(H5FS_section_info_t **, unsigned *, 112 void *); /* Routine called when section is about to be added to manager */ 113 herr_t (*serialize)(const struct H5FS_section_class_t *, const H5FS_section_info_t *, 114 uint8_t *); /* Routine to serialize a "live" section into a buffer */ 115 H5FS_section_info_t *(*deserialize)( 116 const struct H5FS_section_class_t *, const uint8_t *, haddr_t, hsize_t, 117 unsigned *); /* Routine to deserialize a buffer into a "live" section */ 118 htri_t (*can_merge)(const H5FS_section_info_t *, const H5FS_section_info_t *, 119 void *); /* Routine to determine if two nodes are mergable */ 120 herr_t (*merge)(H5FS_section_info_t **, H5FS_section_info_t *, void *); /* Routine to merge two nodes */ 121 htri_t (*can_shrink)(const H5FS_section_info_t *, 122 void *); /* Routine to determine if node can shrink container */ 123 herr_t (*shrink)(H5FS_section_info_t **, void *); /* Routine to shrink container */ 124 herr_t (*free)(H5FS_section_info_t *); /* Routine to free node */ 125 herr_t (*valid)(const struct H5FS_section_class_t *, 126 const H5FS_section_info_t *); /* Routine to check if a section is valid */ 127 H5FS_section_info_t *(*split)(H5FS_section_info_t *, hsize_t); /* Routine to create the split section */ 128 herr_t (*debug)(const H5FS_section_info_t *, FILE *, int, 129 int); /* Routine to dump debugging information about a section */ 130 } H5FS_section_class_t; 131 132 /* State of section ("live" or "serialized") */ 133 typedef enum H5FS_section_state_t { 134 H5FS_SECT_LIVE, /* Section has "live" memory references */ 135 H5FS_SECT_SERIALIZED /* Section is in "serialized" form */ 136 } H5FS_section_state_t; 137 138 /* Free space section info */ 139 struct H5FS_section_info_t { 140 haddr_t addr; /* Offset of free space section in the address space */ 141 hsize_t size; /* Size of free space section */ 142 unsigned type; /* Type of free space section (i.e. class) */ 143 H5FS_section_state_t state; /* Whether the section is in "serialized" or "live" form */ 144 }; 145 146 /* Free space client IDs for identifying user of free space */ 147 typedef enum H5FS_client_t { 148 H5FS_CLIENT_FHEAP_ID = 0, /* Free space is used by fractal heap */ 149 H5FS_CLIENT_FILE_ID, /* Free space is used by file */ 150 H5FS_NUM_CLIENT_ID /* Number of free space client IDs (must be last) */ 151 } H5FS_client_t; 152 153 /* Free space creation parameters */ 154 typedef struct H5FS_create_t { 155 H5FS_client_t client; /* Client's ID */ 156 unsigned shrink_percent; /* Percent of "normal" serialized size to shrink serialized space at */ 157 unsigned expand_percent; /* Percent of "normal" serialized size to expand serialized space at */ 158 unsigned max_sect_addr; /* Size of address space free sections are within (log2 of actual value) */ 159 hsize_t max_sect_size; /* Maximum size of section to track */ 160 } H5FS_create_t; 161 162 /* Free space statistics info */ 163 typedef struct H5FS_stat_t { 164 hsize_t tot_space; /* Total amount of space tracked */ 165 hsize_t tot_sect_count; /* Total # of sections tracked */ 166 hsize_t serial_sect_count; /* # of serializable sections tracked */ 167 hsize_t ghost_sect_count; /* # of un-serializable sections tracked */ 168 haddr_t addr; /* Address of free space header on disk */ 169 hsize_t hdr_size; /* Size of the free-space header on disk */ 170 haddr_t sect_addr; /* Address of the section info in the file */ 171 hsize_t alloc_sect_size; /* Allocated size of the section info in the file */ 172 hsize_t sect_size; /* Size of the section info in the file */ 173 } H5FS_stat_t; 174 175 /* Typedef for iteration operations */ 176 typedef herr_t (*H5FS_operator_t)(H5FS_section_info_t *sect, void *operator_data /*in,out*/); 177 178 /*****************************/ 179 /* Library-private Variables */ 180 /*****************************/ 181 182 /* Declare a free list to manage the H5FS_section_class_t sequence information */ 183 H5FL_SEQ_EXTERN(H5FS_section_class_t); 184 185 /***************************************/ 186 /* Library-private Function Prototypes */ 187 /***************************************/ 188 189 /* Package initialization routine */ 190 H5_DLL herr_t H5FS_init(void); 191 192 /* Free space manager routines */ 193 H5_DLL H5FS_t *H5FS_create(H5F_t *f, haddr_t *fs_addr, const H5FS_create_t *fs_create, uint16_t nclasses, 194 const H5FS_section_class_t *classes[], void *cls_init_udata, hsize_t alignment, 195 hsize_t threshold); 196 H5_DLL H5FS_t *H5FS_open(H5F_t *f, haddr_t fs_addr, uint16_t nclasses, const H5FS_section_class_t *classes[], 197 void *cls_init_udata, hsize_t alignment, hsize_t threshold); 198 H5_DLL herr_t H5FS_size(const H5FS_t *fspace, hsize_t *meta_size); 199 H5_DLL herr_t H5FS_delete(H5F_t *f, haddr_t fs_addr); 200 H5_DLL herr_t H5FS_close(H5F_t *f, H5FS_t *fspace); 201 H5_DLL herr_t H5FS_alloc_hdr(H5F_t *f, H5FS_t *fspace, haddr_t *fs_addr); 202 H5_DLL herr_t H5FS_alloc_sect(H5F_t *f, H5FS_t *fspace); 203 H5_DLL herr_t H5FS_free(H5F_t *f, H5FS_t *fspace, hbool_t free_file_space); 204 205 /* Free space section routines */ 206 H5_DLL herr_t H5FS_sect_add(H5F_t *f, H5FS_t *fspace, H5FS_section_info_t *node, unsigned flags, 207 void *op_data); 208 H5_DLL htri_t H5FS_sect_try_merge(H5F_t *f, H5FS_t *fspace, H5FS_section_info_t *sect, unsigned flags, 209 void *op_data); 210 H5_DLL htri_t H5FS_sect_try_extend(H5F_t *f, H5FS_t *fspace, haddr_t addr, hsize_t size, 211 hsize_t extra_requested, unsigned flags, void *op_data); 212 H5_DLL herr_t H5FS_sect_remove(H5F_t *f, H5FS_t *fspace, H5FS_section_info_t *node); 213 H5_DLL htri_t H5FS_sect_find(H5F_t *f, H5FS_t *fspace, hsize_t request, H5FS_section_info_t **node); 214 H5_DLL herr_t H5FS_sect_iterate(H5F_t *f, H5FS_t *fspace, H5FS_operator_t op, void *op_data); 215 H5_DLL herr_t H5FS_sect_stats(const H5FS_t *fspace, hsize_t *tot_space, hsize_t *nsects); 216 H5_DLL herr_t H5FS_sect_change_class(H5F_t *f, H5FS_t *fspace, H5FS_section_info_t *sect, uint16_t new_class); 217 H5_DLL htri_t H5FS_sect_try_shrink_eoa(H5F_t *f, H5FS_t *fspace, void *op_data); 218 219 /* Statistics routine */ 220 H5_DLL herr_t H5FS_stat_info(const H5F_t *f, const H5FS_t *frsp, H5FS_stat_t *stats); 221 H5_DLL herr_t H5FS_get_sect_count(const H5FS_t *frsp, hsize_t *tot_sect_count); 222 223 /* free space manager settling routines */ 224 H5_DLL herr_t H5FS_vfd_alloc_hdr_and_section_info_if_needed(H5F_t *f, H5FS_t *fspace, haddr_t *fs_addr_ptr); 225 226 /* Debugging routines for dumping file structures */ 227 H5_DLL herr_t H5FS_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth); 228 H5_DLL herr_t H5FS_sects_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth, haddr_t fs_addr, 229 haddr_t client_addr); 230 H5_DLL herr_t H5FS_sect_debug(const H5FS_t *fspace, const H5FS_section_info_t *sect, FILE *stream, int indent, 231 int fwidth); 232 233 #endif /* H5FSprivate_H */ 234