H5FDpublic.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 /*
00017  * Programmer:  Robb Matzke <matzke@llnl.gov>
00018  *              Monday, July 26, 1999
00019  */
00020 #ifndef _H5FDpublic_H
00021 #define _H5FDpublic_H
00022 
00023 #include "H5public.h"
00024 #include "H5Fpublic.h"          /*for H5F_close_degree_t */
00025 
00026 #define H5_HAVE_VFL 1 /*define a convenient app feature test*/
00027 #define H5FD_VFD_DEFAULT 0   /* Default VFL driver value */
00028 
00029 /*
00030  * Types of allocation requests. The values larger than H5FD_MEM_DEFAULT
00031  * should not change other than adding new types to the end. These numbers
00032  * might appear in files.
00033  */
00034 typedef enum H5FD_mem_t {
00035     H5FD_MEM_NOLIST     = -1,                   /*must be negative*/
00036     H5FD_MEM_DEFAULT    = 0,                    /*must be zero*/
00037     H5FD_MEM_SUPER      = 1,
00038     H5FD_MEM_BTREE      = 2,
00039     H5FD_MEM_DRAW       = 3,
00040     H5FD_MEM_GHEAP      = 4,
00041     H5FD_MEM_LHEAP      = 5,
00042     H5FD_MEM_OHDR       = 6,
00043 
00044     H5FD_MEM_NTYPES                             /*must be last*/
00045 } H5FD_mem_t;
00046 
00047 /* Map "fractal heap" header blocks to 'ohdr' type file memory, since its
00048  * a fair amount of work to add a new kind of file memory and they are similar
00049  * enough to object headers and probably too minor to deserve their own type.
00050  *
00051  * Map "fractal heap" indirect blocks to 'ohdr' type file memory, since they
00052  * are similar to fractal heap header blocks.
00053  *
00054  * Map "fractal heap" direct blocks to 'lheap' type file memory, since they
00055  * will be replacing local heaps.
00056  *
00057  * Map "fractal heap" 'huge' objects to 'draw' type file memory, since they
00058  * represent large objects that are directly stored in the file.
00059  *
00060  *      -QAK
00061  */
00062 #define H5FD_MEM_FHEAP_HDR      H5FD_MEM_OHDR
00063 #define H5FD_MEM_FHEAP_IBLOCK   H5FD_MEM_OHDR
00064 #define H5FD_MEM_FHEAP_DBLOCK   H5FD_MEM_LHEAP
00065 #define H5FD_MEM_FHEAP_HUGE_OBJ H5FD_MEM_DRAW
00066 
00067 /* Map "free space" header blocks to 'ohdr' type file memory, since its
00068  * a fair amount of work to add a new kind of file memory and they are similar
00069  * enough to object headers and probably too minor to deserve their own type.
00070  *
00071  * Map "free space" serialized sections to 'lheap' type file memory, since they
00072  * are similar enough to local heap info.
00073  *
00074  *      -QAK
00075  */
00076 #define H5FD_MEM_FSPACE_HDR     H5FD_MEM_OHDR
00077 #define H5FD_MEM_FSPACE_SINFO   H5FD_MEM_LHEAP
00078 
00079 /* Map "shared object header message" master table to 'ohdr' type file memory,
00080  * since its a fair amount of work to add a new kind of file memory and they are
00081  * similar enough to object headers and probably too minor to deserve their own
00082  * type.
00083  *
00084  * Map "shared object header message" indices to 'btree' type file memory,
00085  * since they are similar enough to B-tree nodes.
00086  *
00087  *      -QAK
00088  */
00089 #define H5FD_MEM_SOHM_TABLE     H5FD_MEM_OHDR
00090 #define H5FD_MEM_SOHM_INDEX     H5FD_MEM_BTREE
00091 
00092 /*
00093  * A free-list map which maps all types of allocation requests to a single
00094  * free list.  This is useful for drivers that don't really care about
00095  * keeping different requests segregated in the underlying file and which
00096  * want to make most efficient reuse of freed memory.  The use of the
00097  * H5FD_MEM_SUPER free list is arbitrary.
00098  */
00099 #define H5FD_FLMAP_SINGLE {                                                   \
00100     H5FD_MEM_SUPER,                     /*default*/                           \
00101     H5FD_MEM_SUPER,                     /*super*/                             \
00102     H5FD_MEM_SUPER,                     /*btree*/                             \
00103     H5FD_MEM_SUPER,                     /*draw*/                              \
00104     H5FD_MEM_SUPER,                     /*gheap*/                             \
00105     H5FD_MEM_SUPER,                     /*lheap*/                             \
00106     H5FD_MEM_SUPER                      /*ohdr*/                              \
00107 }
00108 
00109 /*
00110  * A free-list map which segregates requests into `raw' or `meta' data
00111  * pools.
00112  */
00113 #define H5FD_FLMAP_DICHOTOMY {                                                \
00114     H5FD_MEM_SUPER,                     /*default*/                           \
00115     H5FD_MEM_SUPER,                     /*super*/                             \
00116     H5FD_MEM_SUPER,                     /*btree*/                             \
00117     H5FD_MEM_DRAW,                      /*draw*/                              \
00118     H5FD_MEM_SUPER,                     /*gheap*/                             \
00119     H5FD_MEM_SUPER,                     /*lheap*/                             \
00120     H5FD_MEM_SUPER                      /*ohdr*/                              \
00121 }
00122 
00123 /*
00124  * The default free list map which causes each request type to use it's own
00125  * free-list.
00126  */
00127 #define H5FD_FLMAP_DEFAULT {                                                  \
00128     H5FD_MEM_DEFAULT,                   /*default*/                           \
00129     H5FD_MEM_DEFAULT,                   /*super*/                             \
00130     H5FD_MEM_DEFAULT,                   /*btree*/                             \
00131     H5FD_MEM_DEFAULT,                   /*draw*/                              \
00132     H5FD_MEM_DEFAULT,                   /*gheap*/                             \
00133     H5FD_MEM_DEFAULT,                   /*lheap*/                             \
00134     H5FD_MEM_DEFAULT                    /*ohdr*/                              \
00135 }
00136 
00137 
00138 /* Define VFL driver features that can be enabled on a per-driver basis */
00139 /* These are returned with the 'query' function pointer in H5FD_class_t */
00140     /*
00141      * Defining the H5FD_FEAT_AGGREGATE_METADATA for a VFL driver means that
00142      * the library will attempt to allocate a larger block for metadata and
00143      * then sub-allocate each metadata request from that larger block.
00144      */
00145 #define H5FD_FEAT_AGGREGATE_METADATA    0x00000001
00146     /*
00147      * Defining the H5FD_FEAT_ACCUMULATE_METADATA for a VFL driver means that
00148      * the library will attempt to cache metadata as it is written to the file
00149      * and build up a larger block of metadata to eventually pass to the VFL
00150      * 'write' routine.
00151      *
00152      * Distinguish between updating the metadata accumulator on writes and
00153      * reads.  This is particularly (perhaps only, even) important for MPI-I/O
00154      * where we guarantee that writes are collective, but reads may not be.
00155      * If we were to allow the metadata accumulator to be written during a
00156      * read operation, the application would hang.
00157      */
00158 #define H5FD_FEAT_ACCUMULATE_METADATA_WRITE     0x00000002
00159 #define H5FD_FEAT_ACCUMULATE_METADATA_READ      0x00000004
00160 #define H5FD_FEAT_ACCUMULATE_METADATA   (H5FD_FEAT_ACCUMULATE_METADATA_WRITE|H5FD_FEAT_ACCUMULATE_METADATA_READ)
00161     /*
00162      * Defining the H5FD_FEAT_DATA_SIEVE for a VFL driver means that
00163      * the library will attempt to cache raw data as it is read from/written to
00164      * a file in a "data seive" buffer.  See Rajeev Thakur's papers:
00165      *  http://www.mcs.anl.gov/~thakur/papers/romio-coll.ps.gz
00166      *  http://www.mcs.anl.gov/~thakur/papers/mpio-high-perf.ps.gz
00167      */
00168 #define H5FD_FEAT_DATA_SIEVE            0x00000008
00169     /*
00170      * Defining the H5FD_FEAT_AGGREGATE_SMALLDATA for a VFL driver means that
00171      * the library will attempt to allocate a larger block for "small" raw data
00172      * and then sub-allocate "small" raw data requests from that larger block.
00173      */
00174 #define H5FD_FEAT_AGGREGATE_SMALLDATA   0x00000010
00175 
00176 
00177 /* Forward declaration */
00178 typedef struct H5FD_t H5FD_t;
00179 
00180 /* Class information for each file driver */
00181 typedef struct H5FD_class_t {
00182     const char *name;
00183     haddr_t maxaddr;
00184     H5F_close_degree_t fc_degree;
00185     hsize_t (*sb_size)(H5FD_t *file);
00186     herr_t  (*sb_encode)(H5FD_t *file, char *name/*out*/,
00187                          unsigned char *p/*out*/);
00188     herr_t  (*sb_decode)(H5FD_t *f, const char *name, const unsigned char *p);
00189     size_t  fapl_size;
00190     void *  (*fapl_get)(H5FD_t *file);
00191     void *  (*fapl_copy)(const void *fapl);
00192     herr_t  (*fapl_free)(void *fapl);
00193     size_t  dxpl_size;
00194     void *  (*dxpl_copy)(const void *dxpl);
00195     herr_t  (*dxpl_free)(void *dxpl);
00196     H5FD_t *(*open)(const char *name, unsigned flags, hid_t fapl,
00197                     haddr_t maxaddr);
00198     herr_t  (*close)(H5FD_t *file);
00199     int     (*cmp)(const H5FD_t *f1, const H5FD_t *f2);
00200     herr_t  (*query)(const H5FD_t *f1, unsigned long *flags);
00201     herr_t  (*get_type_map)(const H5FD_t *file, H5FD_mem_t *type_map);
00202     haddr_t (*alloc)(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, hsize_t size);
00203     herr_t  (*free)(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id,
00204                     haddr_t addr, hsize_t size);
00205     haddr_t (*get_eoa)(const H5FD_t *file, H5FD_mem_t type);
00206     herr_t  (*set_eoa)(H5FD_t *file, H5FD_mem_t type, haddr_t addr);
00207     haddr_t (*get_eof)(const H5FD_t *file);
00208     herr_t  (*get_handle)(H5FD_t *file, hid_t fapl, void**file_handle);
00209     herr_t  (*read)(H5FD_t *file, H5FD_mem_t type, hid_t dxpl,
00210                     haddr_t addr, size_t size, void *buffer);
00211     herr_t  (*write)(H5FD_t *file, H5FD_mem_t type, hid_t dxpl,
00212                      haddr_t addr, size_t size, const void *buffer);
00213     herr_t  (*flush)(H5FD_t *file, hid_t dxpl_id, unsigned closing);
00214     herr_t  (*truncate)(H5FD_t *file, hid_t dxpl_id, hbool_t closing);
00215     herr_t  (*lock)(H5FD_t *file, unsigned char *oid, unsigned lock_type, hbool_t last);
00216     herr_t  (*unlock)(H5FD_t *file, unsigned char *oid, hbool_t last);
00217     H5FD_mem_t fl_map[H5FD_MEM_NTYPES];
00218 } H5FD_class_t;
00219 
00220 /* A free list is a singly-linked list of address/size pairs. */
00221 typedef struct H5FD_free_t {
00222     haddr_t             addr;
00223     hsize_t             size;
00224     struct H5FD_free_t  *next;
00225 } H5FD_free_t;
00226 
00227 /*
00228  * The main datatype for each driver. Public fields common to all drivers
00229  * are declared here and the driver appends private fields in memory.
00230  */
00231 struct H5FD_t {
00232     hid_t               driver_id;      /*driver ID for this file   */
00233     const H5FD_class_t *cls;            /*constant class info       */
00234     unsigned long       fileno;         /* File 'serial' number     */
00235     unsigned long       feature_flags;  /* VFL Driver feature Flags */
00236     haddr_t             maxaddr;        /* For this file, overrides class */
00237     haddr_t             base_addr;      /* Base address for HDF5 data w/in file */
00238 
00239     /* Space allocation management fields */
00240     hsize_t             threshold;      /* Threshold for alignment  */
00241     hsize_t             alignment;      /* Allocation alignment     */
00242 };
00243 
00244 #ifdef __cplusplus
00245 extern "C" {
00246 #endif
00247 
00248 /* Function prototypes */
00249 H5_DLL hid_t H5FDregister(const H5FD_class_t *cls);
00250 H5_DLL herr_t H5FDunregister(hid_t driver_id);
00251 H5_DLL H5FD_t *H5FDopen(const char *name, unsigned flags, hid_t fapl_id,
00252                         haddr_t maxaddr);
00253 H5_DLL herr_t H5FDclose(H5FD_t *file);
00254 H5_DLL int H5FDcmp(const H5FD_t *f1, const H5FD_t *f2);
00255 H5_DLL int H5FDquery(const H5FD_t *f, unsigned long *flags);
00256 H5_DLL haddr_t H5FDalloc(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, hsize_t size);
00257 H5_DLL herr_t H5FDfree(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id,
00258                        haddr_t addr, hsize_t size);
00259 H5_DLL haddr_t H5FDget_eoa(H5FD_t *file, H5FD_mem_t type);
00260 H5_DLL herr_t H5FDset_eoa(H5FD_t *file, H5FD_mem_t type, haddr_t eoa);
00261 H5_DLL haddr_t H5FDget_eof(H5FD_t *file);
00262 H5_DLL herr_t H5FDget_vfd_handle(H5FD_t *file, hid_t fapl, void**file_handle);
00263 H5_DLL herr_t H5FDread(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id,
00264                        haddr_t addr, size_t size, void *buf/*out*/);
00265 H5_DLL herr_t H5FDwrite(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id,
00266                         haddr_t addr, size_t size, const void *buf);
00267 H5_DLL herr_t H5FDflush(H5FD_t *file, hid_t dxpl_id, unsigned closing);
00268 H5_DLL herr_t H5FDtruncate(H5FD_t *file, hid_t dxpl_id, hbool_t closing);
00269 
00270 #ifdef __cplusplus
00271 }
00272 #endif
00273 #endif
00274