Coverage Report

Created: 2025-11-17 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5Pmapl.c
Line
Count
Source
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Copyright by The HDF Group.                                               *
3
 * All rights reserved.                                                      *
4
 *                                                                           *
5
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
6
 * terms governing use, modification, and redistribution, is contained in    *
7
 * the LICENSE file, which can be found at the root of the source code       *
8
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
9
 * If you do not have access to either file, you may request a copy from     *
10
 * help@hdfgroup.org.                                                        *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13
/*-------------------------------------------------------------------------
14
 *
15
 * Purpose:        Map access property list class routines
16
 *
17
 *-------------------------------------------------------------------------
18
 */
19
20
/****************/
21
/* Module Setup */
22
/****************/
23
24
#include "H5Pmodule.h" /* This source code file is part of the H5P module */
25
26
/***********/
27
/* Headers */
28
/***********/
29
#include "H5private.h"  /* Generic Functions                        */
30
#include "H5Mprivate.h" /* Maps                                     */
31
#include "H5Eprivate.h" /* Error handling                           */
32
#include "H5Ppkg.h"     /* Property lists                           */
33
34
/****************/
35
/* Local Macros */
36
/****************/
37
38
/* ========= Map Access properties ============ */
39
/* Definitions for key prefetch size */
40
2
#define H5M_ACS_KEY_PREFETCH_SIZE_SIZE sizeof(size_t)
41
2
#define H5M_ACS_KEY_PREFETCH_SIZE_DEF  (size_t)(16 * 1024)
42
2
#define H5M_ACS_KEY_PREFETCH_SIZE_ENC  H5P__encode_size_t
43
2
#define H5M_ACS_KEY_PREFETCH_SIZE_DEC  H5P__decode_size_t
44
/* Definition for key prefetch buffer size */
45
2
#define H5M_ACS_KEY_ALLOC_SIZE_SIZE sizeof(size_t)
46
2
#define H5M_ACS_KEY_ALLOC_SIZE_DEF  (size_t)(1024 * 1024)
47
2
#define H5M_ACS_KEY_ALLOC_SIZE_ENC  H5P__encode_size_t
48
2
#define H5M_ACS_KEY_ALLOC_SIZE_DEC  H5P__decode_size_t
49
50
/******************/
51
/* Local Typedefs */
52
/******************/
53
54
/********************/
55
/* Package Typedefs */
56
/********************/
57
58
/********************/
59
/* Local Prototypes */
60
/********************/
61
62
/* Property class callbacks */
63
static herr_t H5P__macc_reg_prop(H5P_genclass_t *pclass);
64
65
/*********************/
66
/* Package Variables */
67
/*********************/
68
69
/* Map access property list class library initialization object */
70
const H5P_libclass_t H5P_CLS_MACC[1] = {{
71
    "map access",        /* Class name for debugging     */
72
    H5P_TYPE_MAP_ACCESS, /* Class type                   */
73
74
    &H5P_CLS_LINK_ACCESS_g,   /* Parent class                 */
75
    &H5P_CLS_MAP_ACCESS_g,    /* Pointer to class             */
76
    &H5P_CLS_MAP_ACCESS_ID_g, /* Pointer to class ID          */
77
    &H5P_LST_MAP_ACCESS_ID_g, /* Pointer to default property list ID */
78
    H5P__macc_reg_prop,       /* Default property registration routine */
79
80
    NULL, /* Class creation callback      */
81
    NULL, /* Class creation callback info */
82
    NULL, /* Class copy callback          */
83
    NULL, /* Class copy callback info     */
84
    NULL, /* Class close callback         */
85
    NULL  /* Class close callback info    */
86
}};
87
88
/*****************************/
89
/* Library Private Variables */
90
/*****************************/
91
92
/*******************/
93
/* Local Variables */
94
/*******************/
95
96
/*-------------------------------------------------------------------------
97
 * Function:    H5P__macc_reg_prop
98
 *
99
 * Purpose:     Register the map access property list class's
100
 *              properties
101
 *
102
 * Return:      Non-negative on success/Negative on failure
103
 *-------------------------------------------------------------------------
104
 */
105
static herr_t
106
H5P__macc_reg_prop(H5P_genclass_t *pclass)
107
2
{
108
2
    size_t key_prefetch_size = H5M_ACS_KEY_PREFETCH_SIZE_DEF; /* Default key prefetch size for iteration */
109
2
    size_t key_alloc_size =
110
2
        H5M_ACS_KEY_ALLOC_SIZE_DEF; /* Default key prefetch allocation size for iteration */
111
2
    herr_t ret_value = SUCCEED;     /* Return value */
112
113
2
    FUNC_ENTER_PACKAGE
114
115
    /* Register the key prefetch size for iteration */
116
2
    if (H5P__register_real(pclass, H5M_ACS_KEY_PREFETCH_SIZE_NAME, H5M_ACS_KEY_PREFETCH_SIZE_SIZE,
117
2
                           &key_prefetch_size, NULL, NULL, NULL, H5M_ACS_KEY_PREFETCH_SIZE_ENC,
118
2
                           H5M_ACS_KEY_PREFETCH_SIZE_DEC, NULL, NULL, NULL, NULL) < 0)
119
0
        HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class");
120
121
    /* Register the key prefetch allocation size for iteration */
122
2
    if (H5P__register_real(pclass, H5M_ACS_KEY_ALLOC_SIZE_NAME, H5M_ACS_KEY_ALLOC_SIZE_SIZE, &key_alloc_size,
123
2
                           NULL, NULL, NULL, H5M_ACS_KEY_ALLOC_SIZE_ENC, H5M_ACS_KEY_ALLOC_SIZE_DEC, NULL,
124
2
                           NULL, NULL, NULL) < 0)
125
0
        HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class");
126
127
2
done:
128
2
    FUNC_LEAVE_NOAPI(ret_value)
129
2
} /* end H5P__macc_reg_prop() */
130
131
#ifdef H5_HAVE_MAP_API
132
133
/*-------------------------------------------------------------------------
134
 * Function:    H5Pset_map_iterate_hints
135
 *
136
 * Purpose:     H5Pset_map_iterate_hints adjusts the behavior of
137
 *              H5Miterate when prefetching keys for iteration. The
138
 *              KEY_PREFETCH_SIZE parameter specifies the number of keys
139
 *              to prefetch at a time during iteration. The KEY_ALLOC_SIZE
140
 *              parameter specifies the initial size of the buffer
141
 *              allocated to hold these prefetched keys. If this buffer is
142
 *              too small it will be reallocated to a larger size, though
143
 *              this may result in an additional I/O.
144
 *
145
 *              Move to DAOS VOL code? DSINC
146
 *
147
 * Return:      Non-negative on success/Negative on failure
148
 *-------------------------------------------------------------------------
149
 */
150
herr_t
151
H5Pset_map_iterate_hints(hid_t mapl_id, size_t key_prefetch_size, size_t key_alloc_size)
152
{
153
    H5P_genplist_t *plist;               /* Property list pointer */
154
    herr_t          ret_value = SUCCEED; /* return value */
155
156
    FUNC_ENTER_API(FAIL)
157
158
    /* Get the plist structure */
159
    if (NULL == (plist = H5P_object_verify(mapl_id, H5P_MAP_ACCESS, false)))
160
        HGOTO_ERROR(H5E_ID, H5E_BADID, FAIL, "can't find object for ID");
161
162
    /* Set sizes */
163
    if (H5P_set(plist, H5M_ACS_KEY_PREFETCH_SIZE_NAME, &key_prefetch_size) < 0)
164
        HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set key prefetch size");
165
    if (H5P_set(plist, H5M_ACS_KEY_ALLOC_SIZE_NAME, &key_alloc_size) < 0)
166
        HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set key allocation size");
167
168
done:
169
    FUNC_LEAVE_API(ret_value)
170
} /* end H5Pset_map_iterate_hints() */
171
172
/*-------------------------------------------------------------------------
173
 * Function:    H5Pget_map_iterate_hints
174
 *
175
 * Purpose:     Returns the map iterate hints, KEY_PREFETCH_SIZE and
176
 *              KEY_ALLOC_SIZE, as set by H5Pset_map_iterate_hints.
177
 *
178
 * Return:      Non-negative on success/Negative on failure
179
 *-------------------------------------------------------------------------
180
 */
181
herr_t
182
H5Pget_map_iterate_hints(hid_t mapl_id, size_t *key_prefetch_size /*out*/, size_t *key_alloc_size /*out*/)
183
{
184
    H5P_genplist_t *plist;               /* Property list pointer */
185
    herr_t          ret_value = SUCCEED; /* return value */
186
187
    FUNC_ENTER_API(FAIL)
188
189
    /* Get the plist structure */
190
    if (NULL == (plist = H5P_object_verify(mapl_id, H5P_MAP_ACCESS, true)))
191
        HGOTO_ERROR(H5E_ID, H5E_BADID, FAIL, "can't find object for ID");
192
193
    /* Get the properties */
194
    if (key_prefetch_size) {
195
        if (H5P_get(plist, H5M_ACS_KEY_PREFETCH_SIZE_NAME, key_prefetch_size) < 0)
196
            HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get key prefetch size");
197
    } /* end if */
198
    if (key_alloc_size) {
199
        if (H5P_get(plist, H5M_ACS_KEY_ALLOC_SIZE_NAME, key_alloc_size) < 0)
200
            HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get key allocation size");
201
    } /* end if */
202
203
done:
204
    FUNC_LEAVE_API(ret_value)
205
} /* end H5Pget_map_iterate_hints() */
206
#endif