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://support.hdfgroup.org/ftp/HDF5/releases.  *
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 <koziol@ncsa.uiuc.edu>
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 /* Include package's public header */
29 #include "H5FSpublic.h"
30 
31 /* Private headers needed by this file */
32 #include "H5Fprivate.h"		/* File access				*/
33 #include "H5FLprivate.h"	/* Free Lists                           */
34 
35 /**************************/
36 /* Library Private Macros */
37 /**************************/
38 
39 /* Flags for H5FS_section_class_t 'flags' field */
40 #define H5FS_CLS_GHOST_OBJ      0x01    /* Objects in this class shouldn't be
41                                          *      serialized to the file.
42                                          */
43 #define H5FS_CLS_SEPAR_OBJ      0x02    /* Objects in this class shouldn't
44                                          *      participate in merge operations.
45                                          */
46 #define H5FS_CLS_MERGE_SYM      0x04    /* Objects in this class only merge
47                                          *      with other objects in this class.
48                                          */
49 #define H5FS_CLS_ADJUST_OK      0x08    /* Objects in this class can be merged
50                                          *      without requiring a can_adjust/adjust
51                                          *      callback pair.
52                                          */
53 
54 /* Flags for H5FS_add() */
55 #define H5FS_ADD_DESERIALIZING  0x01    /* Free space is being deserialized
56                                          */
57 #define H5FS_ADD_RETURNED_SPACE 0x02    /* Section was previously allocated
58                                          *      and is being returned to the
59                                          *      free space manager (usually
60                                          *      as a result of freeing an
61                                          *      object)
62                                          */
63 #define H5FS_ADD_SKIP_VALID     0x04    /* Don't check validity after adding
64                                          *      this section.  (state of the
65                                          *      managed sections is in flux)
66                                          */
67 
68 /* Flags for deserialize callback  */
69 #define H5FS_DESERIALIZE_NO_ADD  0x01   /* Don't add section to free space
70                                          *      manager after it's deserialized
71                                          *      (its only here for it's side-
72                                          *      effects).
73                                          */
74 
75 
76 /****************************/
77 /* Library Private Typedefs */
78 /****************************/
79 
80 /* Free space info (forward decl - defined in H5FSpkg.h) */
81 typedef struct H5FS_t H5FS_t;
82 
83 /* Forward declaration free space section info */
84 typedef struct H5FS_section_info_t H5FS_section_info_t;
85 
86 /* Free space section class info */
87 typedef struct H5FS_section_class_t {
88     /* Class variables */
89     const unsigned type;                /* Type of free space section */
90     size_t serial_size;                 /* Size of serialized form of section */
91     unsigned flags;                     /* Class flags */
92     void *cls_private;                  /* Class private information */
93 
94     /* Class methods */
95     herr_t (*init_cls)(struct H5FS_section_class_t *, void *);          /* Routine to initialize class-specific settings */
96     herr_t (*term_cls)(struct H5FS_section_class_t *);                  /* Routine to terminate class-specific settings */
97 
98     /* Object methods */
99     herr_t (*add)(H5FS_section_info_t *, unsigned *, void *);       /* Routine called when section is about to be added to manager */
100     herr_t (*serialize)(const struct H5FS_section_class_t *, const H5FS_section_info_t *, uint8_t *);        /* Routine to serialize a "live" section into a buffer */
101     H5FS_section_info_t *(*deserialize)(const struct H5FS_section_class_t *, hid_t dxpl_id, const uint8_t *, haddr_t, hsize_t, unsigned *);     /* Routine to deserialize a buffer into a "live" section */
102     htri_t (*can_merge)(const H5FS_section_info_t *, const H5FS_section_info_t *, void *);  /* Routine to determine if two nodes are mergable */
103     herr_t (*merge)(H5FS_section_info_t *, H5FS_section_info_t *, void *);      /* Routine to merge two nodes */
104     htri_t (*can_shrink)(const H5FS_section_info_t *, void *);        /* Routine to determine if node can shrink container */
105     herr_t (*shrink)(H5FS_section_info_t **, void *);   /* Routine to shrink container */
106     herr_t (*free)(H5FS_section_info_t *);              /* Routine to free node */
107     herr_t (*valid)(const struct H5FS_section_class_t *, const H5FS_section_info_t *);   /* Routine to check if a section is valid */
108     H5FS_section_info_t *(*split)(H5FS_section_info_t *, hsize_t);     /* Routine to create the split section */
109     herr_t (*debug)(const H5FS_section_info_t *, FILE *, int , int );   /* Routine to dump debugging information about a section */
110 } H5FS_section_class_t;
111 
112 /* State of section ("live" or "serialized") */
113 typedef enum H5FS_section_state_t {
114     H5FS_SECT_LIVE,             /* Section has "live" memory references */
115     H5FS_SECT_SERIALIZED        /* Section is in "serialized" form */
116 } H5FS_section_state_t;
117 
118 /* Free space section info */
119 struct H5FS_section_info_t {
120     haddr_t     addr;                   /* Offset of free space section in the address space */
121     hsize_t     size;                   /* Size of free space section */
122     unsigned    type;                   /* Type of free space section (i.e. class) */
123     H5FS_section_state_t state;         /* Whether the section is in "serialized" or "live" form */
124 };
125 
126 /* Free space client IDs for identifying user of free space */
127 typedef enum H5FS_client_t {
128     H5FS_CLIENT_FHEAP_ID = 0,	/* Free space is used by fractal heap */
129     H5FS_CLIENT_FILE_ID,	/* Free space is used by file */
130     H5FS_NUM_CLIENT_ID          /* Number of free space client IDs (must be last)   */
131 } H5FS_client_t;
132 
133 /* Free space creation parameters */
134 typedef struct H5FS_create_t {
135     H5FS_client_t client;               /* Client's ID */
136     unsigned shrink_percent;            /* Percent of "normal" serialized size to shrink serialized space at */
137     unsigned expand_percent;            /* Percent of "normal" serialized size to expand serialized space at */
138     unsigned max_sect_addr;             /* Size of address space free sections are within (log2 of actual value) */
139     hsize_t max_sect_size;              /* Maximum size of section to track */
140 } H5FS_create_t;
141 
142 /* Free space statistics info */
143 typedef struct H5FS_stat_t {
144     hsize_t tot_space;          /* Total amount of space tracked              */
145     hsize_t tot_sect_count;     /* Total # of sections tracked                */
146     hsize_t serial_sect_count;  /* # of serializable sections tracked         */
147     hsize_t ghost_sect_count;   /* # of un-serializable sections tracked      */
148     haddr_t addr;		/* Address of free space header on disk       */
149     hsize_t hdr_size;		/* Size of the free-space header on disk      */
150     haddr_t sect_addr;          /* Address of the section info in the file    */
151     hsize_t alloc_sect_size;    /* Allocated size of the section info in the file */
152     hsize_t sect_size;    	/* Size of the section info in the file       */
153 } H5FS_stat_t;
154 
155 /* Typedef for iteration operations */
156 typedef herr_t (*H5FS_operator_t)(H5FS_section_info_t *sect,
157         void *operator_data/*in,out*/);
158 
159 
160 /*****************************/
161 /* Library-private Variables */
162 /*****************************/
163 
164 /* Declare a free list to manage the H5FS_section_class_t sequence information */
165 H5FL_SEQ_EXTERN(H5FS_section_class_t);
166 
167 
168 /***************************************/
169 /* Library-private Function Prototypes */
170 /***************************************/
171 
172 /* Free space manager routines */
173 H5_DLL H5FS_t *H5FS_create(H5F_t *f, hid_t dxpl_id, haddr_t *fs_addr,
174     const H5FS_create_t *fs_create, size_t nclasses,
175     const H5FS_section_class_t *classes[], void *cls_init_udata, hsize_t alignment, hsize_t threshold);
176 H5_DLL H5FS_t *H5FS_open(H5F_t *f, hid_t dxpl_id, haddr_t fs_addr,
177     size_t nclasses, const H5FS_section_class_t *classes[], void *cls_init_udata, hsize_t alignment, hsize_t threshold);
178 H5_DLL herr_t H5FS_size(const H5F_t *f, const H5FS_t *fspace, hsize_t *meta_size);
179 H5_DLL herr_t H5FS_delete(H5F_t *f, hid_t dxpl_id, haddr_t fs_addr);
180 H5_DLL herr_t H5FS_close(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace);
181 
182 /* Free space section routines */
183 H5_DLL herr_t H5FS_sect_add(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace,
184     H5FS_section_info_t *node, unsigned flags, void *op_data);
185 H5_DLL htri_t H5FS_sect_try_extend(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace,
186     haddr_t addr, hsize_t size, hsize_t extra_requested);
187 H5_DLL herr_t H5FS_sect_remove(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace,
188     H5FS_section_info_t *node);
189 H5_DLL htri_t H5FS_sect_find(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace,
190     hsize_t request, H5FS_section_info_t **node);
191 H5_DLL herr_t H5FS_sect_iterate(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace, H5FS_operator_t op, void *op_data);
192 H5_DLL herr_t H5FS_sect_stats(const H5FS_t *fspace, hsize_t *tot_space,
193     hsize_t *nsects);
194 H5_DLL herr_t H5FS_sect_change_class(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace,
195     H5FS_section_info_t *sect, unsigned new_class);
196 H5_DLL htri_t H5FS_sect_try_shrink_eoa(const H5F_t *f, hid_t dxpl_id, const H5FS_t *fspace, void *op_data);
197 H5_DLL herr_t H5FS_sect_query_last_sect(const H5FS_t *fspace, haddr_t *sect_addr, hsize_t *sect_size);
198 
199 /* Statistics routine */
200 H5_DLL herr_t H5FS_stat_info(const H5F_t *f, const H5FS_t *frsp, H5FS_stat_t *stats);
201 
202 /* Debugging routines for dumping file structures */
203 H5_DLL herr_t H5FS_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr,
204     FILE *stream, int indent, int fwidth);
205 H5_DLL herr_t H5FS_sects_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr,
206     FILE *stream, int indent, int fwidth, haddr_t fs_addr, haddr_t client_addr);
207 H5_DLL herr_t H5FS_sect_debug(const H5FS_t *fspace, const H5FS_section_info_t *sect,
208     FILE *stream, int indent, int fwidth);
209 
210 #endif /* _H5FSprivate_H */
211 
212