Coverage Report

Created: 2024-06-18 06:29

/src/hdf5/src/H5VLnative_group.c
Line
Count
Source (jump to first uncovered line)
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 COPYING 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
 * Purpose:     Group callbacks for the native VOL connector
15
 *
16
 */
17
18
/****************/
19
/* Module Setup */
20
/****************/
21
22
#define H5G_FRIEND /* Suppress error about including H5Gpkg    */
23
24
/***********/
25
/* Headers */
26
/***********/
27
#include "H5private.h"   /* Generic Functions                        */
28
#include "H5Eprivate.h"  /* Error handling                           */
29
#include "H5Gpkg.h"      /* Groups                                   */
30
#include "H5Iprivate.h"  /* IDs                                      */
31
#include "H5Oprivate.h"  /* Object headers                           */
32
#include "H5VLprivate.h" /* Virtual Object Layer                     */
33
34
#include "H5VLnative_private.h" /* Native VOL connector                     */
35
36
/****************/
37
/* Local Macros */
38
/****************/
39
40
/******************/
41
/* Local Typedefs */
42
/******************/
43
44
/********************/
45
/* Local Prototypes */
46
/********************/
47
48
/*********************/
49
/* Package Variables */
50
/*********************/
51
52
/*****************************/
53
/* Library Private Variables */
54
/*****************************/
55
56
/*******************/
57
/* Local Variables */
58
/*******************/
59
60
/*-------------------------------------------------------------------------
61
 * Function:    H5VL__native_group_create
62
 *
63
 * Purpose:     Handles the group create callback
64
 *
65
 * Return:      Success:    group pointer
66
 *              Failure:    NULL
67
 *
68
 *-------------------------------------------------------------------------
69
 */
70
void *
71
H5VL__native_group_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id,
72
                          hid_t gcpl_id, hid_t H5_ATTR_UNUSED gapl_id, hid_t H5_ATTR_UNUSED dxpl_id,
73
                          void H5_ATTR_UNUSED **req)
74
0
{
75
0
    H5G_loc_t loc;        /* Location to create group     */
76
0
    H5G_t    *grp = NULL; /* New group created            */
77
0
    void     *ret_value;
78
79
0
    FUNC_ENTER_PACKAGE
80
81
    /* Set up the location */
82
0
    if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0)
83
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object");
84
85
    /* if name is NULL then this is from H5Gcreate_anon */
86
0
    if (name == NULL) {
87
0
        H5G_obj_create_t gcrt_info; /* Information for group creation */
88
89
        /* Set up group creation info */
90
0
        gcrt_info.gcpl_id    = gcpl_id;
91
0
        gcrt_info.cache_type = H5G_NOTHING_CACHED;
92
0
        memset(&gcrt_info.cache, 0, sizeof(gcrt_info.cache));
93
94
        /* Create the new group & get its ID */
95
0
        if (NULL == (grp = H5G__create(loc.oloc->file, &gcrt_info)))
96
0
            HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, NULL, "unable to create group");
97
0
    } /* end if */
98
    /* otherwise it's from H5Gcreate */
99
0
    else {
100
        /* Create the new group & get its ID */
101
0
        if (NULL == (grp = H5G__create_named(&loc, name, lcpl_id, gcpl_id)))
102
0
            HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, NULL, "unable to create group");
103
0
    } /* end else */
104
105
0
    ret_value = (void *)grp;
106
107
0
done:
108
0
    if (name == NULL) {
109
        /* Release the group's object header, if it was created */
110
0
        if (grp) {
111
0
            H5O_loc_t *oloc; /* Object location for group */
112
113
            /* Get the new group's object location */
114
0
            if (NULL == (oloc = H5G_oloc(grp)))
115
0
                HDONE_ERROR(H5E_SYM, H5E_CANTGET, NULL, "unable to get object location of group");
116
117
            /* Decrement refcount on group's object header in memory */
118
0
            if (H5O_dec_rc_by_loc(oloc) < 0)
119
0
                HDONE_ERROR(H5E_SYM, H5E_CANTDEC, NULL,
120
0
                            "unable to decrement refcount on newly created object");
121
0
        } /* end if */
122
0
    }     /* end if */
123
124
0
    FUNC_LEAVE_NOAPI(ret_value)
125
0
} /* end H5VL__native_group_create() */
126
127
/*-------------------------------------------------------------------------
128
 * Function:    H5VL__native_group_open
129
 *
130
 * Purpose:     Handles the group open callback
131
 *
132
 * Return:      Success:    group pointer
133
 *              Failure:    NULL
134
 *
135
 *-------------------------------------------------------------------------
136
 */
137
void *
138
H5VL__native_group_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name,
139
                        hid_t H5_ATTR_UNUSED gapl_id, hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req)
140
8
{
141
8
    H5G_loc_t loc;        /* Location to open group   */
142
8
    H5G_t    *grp = NULL; /* New group opened         */
143
8
    void     *ret_value;
144
145
8
    FUNC_ENTER_PACKAGE
146
147
    /* Set up the location */
148
8
    if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0)
149
0
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object");
150
151
    /* Open the group */
152
8
    if ((grp = H5G__open_name(&loc, name)) == NULL)
153
0
        HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to open group");
154
155
8
    ret_value = (void *)grp;
156
157
8
done:
158
8
    FUNC_LEAVE_NOAPI(ret_value)
159
8
} /* end H5VL__native_group_open() */
160
161
/*-------------------------------------------------------------------------
162
 * Function:    H5VL__native_group_get
163
 *
164
 * Purpose:     Handles the group get callback
165
 *
166
 * Return:      SUCCEED/FAIL
167
 *
168
 *-------------------------------------------------------------------------
169
 */
170
herr_t
171
H5VL__native_group_get(void *obj, H5VL_group_get_args_t *args, hid_t H5_ATTR_UNUSED dxpl_id,
172
                       void H5_ATTR_UNUSED **req)
173
7
{
174
7
    herr_t ret_value = SUCCEED; /* Return value */
175
176
7
    FUNC_ENTER_PACKAGE
177
178
7
    switch (args->op_type) {
179
        /* H5Gget_create_plist */
180
0
        case H5VL_GROUP_GET_GCPL: {
181
0
            if ((args->args.get_gcpl.gcpl_id = H5G_get_create_plist((H5G_t *)obj)) < 0)
182
0
                HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't get creation property list for group");
183
184
0
            break;
185
0
        }
186
187
        /* H5Gget_info */
188
7
        case H5VL_GROUP_GET_INFO: {
189
7
            H5VL_group_get_info_args_t *get_info_args = &args->args.get_info;
190
7
            H5G_loc_t                   loc;
191
192
7
            if (H5G_loc_real(obj, get_info_args->loc_params.obj_type, &loc) < 0)
193
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object");
194
195
7
            if (get_info_args->loc_params.type == H5VL_OBJECT_BY_SELF) {
196
                /* H5Gget_info */
197
198
                /* Retrieve the group's information */
199
7
                if (H5G__obj_info(loc.oloc, get_info_args->ginfo) < 0)
200
1
                    HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve group info");
201
7
            } /* end if */
202
0
            else if (get_info_args->loc_params.type == H5VL_OBJECT_BY_NAME) {
203
                /* H5Gget_info_by_name */
204
205
                /* Retrieve the group's information */
206
0
                if (H5G__get_info_by_name(&loc, get_info_args->loc_params.loc_data.loc_by_name.name,
207
0
                                          get_info_args->ginfo) < 0)
208
0
                    HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve group info");
209
0
            } /* end else-if */
210
0
            else if (get_info_args->loc_params.type == H5VL_OBJECT_BY_IDX) {
211
                /* H5Gget_info_by_idx */
212
213
                /* Retrieve the group's information */
214
0
                if (H5G__get_info_by_idx(&loc, get_info_args->loc_params.loc_data.loc_by_idx.name,
215
0
                                         get_info_args->loc_params.loc_data.loc_by_idx.idx_type,
216
0
                                         get_info_args->loc_params.loc_data.loc_by_idx.order,
217
0
                                         get_info_args->loc_params.loc_data.loc_by_idx.n,
218
0
                                         get_info_args->ginfo) < 0)
219
0
                    HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't retrieve group info");
220
0
            } /* end else-if */
221
0
            else
222
0
                HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "unknown get info parameters");
223
6
            break;
224
7
        }
225
226
6
        default:
227
0
            HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from group");
228
7
    } /* end switch */
229
230
7
done:
231
7
    FUNC_LEAVE_NOAPI(ret_value)
232
7
} /* end H5VL__native_group_get() */
233
234
/*-------------------------------------------------------------------------
235
 * Function:    H5VL__native_group_specific
236
 *
237
 * Purpose:     Handles the group specific callback
238
 *
239
 * Return:      SUCCEED/FAIL
240
 *
241
 *-------------------------------------------------------------------------
242
 */
243
herr_t
244
H5VL__native_group_specific(void *obj, H5VL_group_specific_args_t *args, hid_t H5_ATTR_UNUSED dxpl_id,
245
                            void H5_ATTR_UNUSED **req)
246
0
{
247
0
    H5G_t *grp       = (H5G_t *)obj;
248
0
    herr_t ret_value = SUCCEED; /* Return value */
249
250
0
    FUNC_ENTER_PACKAGE
251
252
0
    switch (args->op_type) {
253
        /* H5Fmount */
254
0
        case H5VL_GROUP_MOUNT: {
255
0
            H5G_loc_t loc;
256
257
0
            if (H5G_loc_real(grp, H5I_GROUP, &loc) < 0)
258
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group object");
259
260
0
            if (H5F_mount(&loc, args->args.mount.name, args->args.mount.child_file,
261
0
                          args->args.mount.fmpl_id) < 0)
262
0
                HGOTO_ERROR(H5E_FILE, H5E_MOUNT, FAIL, "unable to mount file");
263
264
0
            break;
265
0
        }
266
267
        /* H5Funmount */
268
0
        case H5VL_GROUP_UNMOUNT: {
269
0
            H5G_loc_t loc;
270
271
0
            if (H5G_loc_real(grp, H5I_GROUP, &loc) < 0)
272
0
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group object");
273
274
0
            if (H5F_unmount(&loc, args->args.unmount.name) < 0)
275
0
                HGOTO_ERROR(H5E_FILE, H5E_UNMOUNT, FAIL, "unable to unmount file");
276
277
0
            break;
278
0
        }
279
280
        /* H5Gflush */
281
0
        case H5VL_GROUP_FLUSH: {
282
            /* Currently, H5Oflush causes H5Fclose to trigger an assertion failure in metadata cache.
283
             * Leave this situation for the future solution */
284
0
            if (H5F_HAS_FEATURE(grp->oloc.file, H5FD_FEAT_HAS_MPI))
285
0
                HGOTO_ERROR(H5E_SYM, H5E_UNSUPPORTED, FAIL, "H5Oflush isn't supported for parallel");
286
287
0
            if (H5O_flush_common(&grp->oloc, args->args.flush.grp_id) < 0)
288
0
                HGOTO_ERROR(H5E_SYM, H5E_CANTFLUSH, FAIL, "unable to flush group");
289
290
0
            break;
291
0
        }
292
293
        /* H5Grefresh */
294
0
        case H5VL_GROUP_REFRESH: {
295
0
            if ((H5O_refresh_metadata(&grp->oloc, args->args.refresh.grp_id)) < 0)
296
0
                HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, FAIL, "unable to refresh group");
297
298
0
            break;
299
0
        }
300
301
0
        default:
302
0
            HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid specific operation");
303
0
    } /* end switch */
304
305
0
done:
306
0
    FUNC_LEAVE_NOAPI(ret_value)
307
0
} /* end H5VL__native_group_specific() */
308
309
/*-------------------------------------------------------------------------
310
 * Function:    H5VL__native_group_optional
311
 *
312
 * Purpose:     Handles the group optional callback
313
 *
314
 * Return:      SUCCEED/FAIL
315
 *
316
 *-------------------------------------------------------------------------
317
 */
318
herr_t
319
H5VL__native_group_optional(void H5_ATTR_UNUSED *obj, H5VL_optional_args_t *args,
320
                            hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req)
321
0
{
322
#ifndef H5_NO_DEPRECATED_SYMBOLS
323
    H5VL_native_group_optional_args_t *opt_args = args->args; /* Pointer to native operation's arguments */
324
#endif                                                        /* H5_NO_DEPRECATED_SYMBOLS */
325
0
    herr_t ret_value = SUCCEED;                               /* Return value */
326
327
0
    FUNC_ENTER_PACKAGE
328
329
0
    switch (args->op_type) {
330
#ifndef H5_NO_DEPRECATED_SYMBOLS
331
        /* H5Giterate (deprecated) */
332
        case H5VL_NATIVE_GROUP_ITERATE_OLD: {
333
            H5VL_native_group_iterate_old_t *iter_args = &opt_args->iterate_old;
334
            H5G_link_iterate_t               lnk_op; /* Link operator                    */
335
            H5G_loc_t                        grp_loc;
336
337
            /* Get the location struct for the object */
338
            if (H5G_loc_real(obj, iter_args->loc_params.obj_type, &grp_loc) < 0)
339
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object");
340
341
            /* Set up link iteration callback struct */
342
            lnk_op.op_type        = H5G_LINK_OP_OLD;
343
            lnk_op.op_func.op_old = iter_args->op;
344
345
            /* Call the actual iteration routine */
346
            if ((ret_value = H5G_iterate(&grp_loc, iter_args->loc_params.loc_data.loc_by_name.name,
347
                                         H5_INDEX_NAME, H5_ITER_INC, iter_args->idx, iter_args->last_obj,
348
                                         &lnk_op, iter_args->op_data)) < 0)
349
                HERROR(H5E_SYM, H5E_BADITER, "error iterating over group's links");
350
351
            break;
352
        }
353
354
        /* H5Gget_objinfo (deprecated) */
355
        case H5VL_NATIVE_GROUP_GET_OBJINFO: {
356
            H5VL_native_group_get_objinfo_t *goi_args = &opt_args->get_objinfo;
357
            H5G_loc_t                        grp_loc;
358
359
            /* Get the location struct for the object */
360
            if (H5G_loc_real(obj, goi_args->loc_params.obj_type, &grp_loc) < 0)
361
                HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object");
362
363
            /* Call the actual group objinfo routine */
364
            if (H5G__get_objinfo(&grp_loc, goi_args->loc_params.loc_data.loc_by_name.name,
365
                                 goi_args->follow_link, goi_args->statbuf) < 0)
366
                HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "cannot stat object");
367
368
            break;
369
        }
370
#endif /* H5_NO_DEPRECATED_SYMBOLS */
371
372
0
        default:
373
0
            HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid optional operation");
374
0
    } /* end switch */
375
376
0
done:
377
0
    FUNC_LEAVE_NOAPI(ret_value)
378
0
} /* end H5VL__native_group_optional() */
379
380
/*-------------------------------------------------------------------------
381
 * Function:    H5VL__native_group_close
382
 *
383
 * Purpose:     Handles the group close callback
384
 *
385
 * Return:      Success:    SUCCEED
386
 *              Failure:    FAIL (group will not be closed)
387
 *
388
 *-------------------------------------------------------------------------
389
 */
390
herr_t
391
H5VL__native_group_close(void *grp, hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req)
392
84
{
393
84
    herr_t ret_value = SUCCEED; /* Return value */
394
395
84
    FUNC_ENTER_PACKAGE
396
397
84
    if (H5G_close((H5G_t *)grp) < 0)
398
0
        HGOTO_ERROR(H5E_SYM, H5E_CLOSEERROR, FAIL, "can't close group");
399
400
84
done:
401
84
    FUNC_LEAVE_NOAPI(ret_value)
402
84
} /* end H5VL__native_group_close() */