Coverage Report

Created: 2026-11-23 00:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5AC.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
 * Created:             H5AC.c
16
 *
17
 * Purpose:             Functions in this file implement a cache for
18
 *                      things which exist on disk.  All "things" associated
19
 *                      with a particular HDF file share the same cache; each
20
 *                      HDF file has it's own cache.
21
 *
22
 *-------------------------------------------------------------------------
23
 */
24
25
/****************/
26
/* Module Setup */
27
/****************/
28
29
#include "H5ACmodule.h" /* This source code file is part of the H5AC module */
30
#define H5C_FRIEND      /* Suppress error about including H5Cpkg            */
31
#define H5F_FRIEND      /* Suppress error about including H5Fpkg            */
32
33
/***********/
34
/* Headers */
35
/***********/
36
#include "H5private.h"   /* Generic Functions                        */
37
#include "H5ACpkg.h"     /* Metadata cache                           */
38
#include "H5Clog.h"      /* Cache logging                            */
39
#include "H5Cpkg.h"      /* Cache                                    */
40
#include "H5CXprivate.h" /* API Contexts                             */
41
#include "H5Eprivate.h"  /* Error handling                           */
42
#include "H5Fpkg.h"      /* Files                                    */
43
#include "H5FLprivate.h" /* Free Lists                               */
44
#include "H5Pprivate.h"  /* Property lists                           */
45
#include "H5SLprivate.h" /* Skip Lists                               */
46
47
/****************/
48
/* Local Macros */
49
/****************/
50
51
/******************/
52
/* Local Typedefs */
53
/******************/
54
55
/********************/
56
/* Local Prototypes */
57
/********************/
58
59
static herr_t H5AC__check_if_write_permitted(const H5F_t *f, bool *write_permitted_ptr);
60
static herr_t H5AC__ext_config_2_int_config(const H5AC_cache_config_t *ext_conf_ptr,
61
                                            H5C_auto_size_ctl_t       *int_conf_ptr);
62
#if H5AC_DO_TAGGING_SANITY_CHECKS
63
static herr_t H5AC__verify_tag(const H5AC_class_t *type);
64
#endif /* H5AC_DO_TAGGING_SANITY_CHECKS */
65
66
/*********************/
67
/* Package Variables */
68
/*********************/
69
70
/* Package initialization variable */
71
bool H5_PKG_INIT_VAR = false;
72
73
/*****************************/
74
/* Library Private Variables */
75
/*****************************/
76
77
#ifdef H5_HAVE_PARALLEL
78
/* Environment variable for collective API sanity checks */
79
bool H5_coll_api_sanity_check_g = false;
80
#endif /* H5_HAVE_PARALLEL */
81
82
/*******************/
83
/* Local Variables */
84
/*******************/
85
86
/* Metadata entry class list */
87
88
/* Remember to add new type ID to the H5AC_type_t enum in H5ACprivate.h when
89
 *      adding a new class.
90
 */
91
92
static const H5AC_class_t *const H5AC_class_s[] = {
93
    H5AC_BT,               /* ( 0) B-tree nodes                    */
94
    H5AC_SNODE,            /* ( 1) symbol table nodes              */
95
    H5AC_LHEAP_PRFX,       /* ( 2) local heap prefix               */
96
    H5AC_LHEAP_DBLK,       /* ( 3) local heap data block           */
97
    H5AC_GHEAP,            /* ( 4) global heap                     */
98
    H5AC_OHDR,             /* ( 5) object header                   */
99
    H5AC_OHDR_CHK,         /* ( 6) object header chunk             */
100
    H5AC_BT2_HDR,          /* ( 7) v2 B-tree header                */
101
    H5AC_BT2_INT,          /* ( 8) v2 B-tree internal node         */
102
    H5AC_BT2_LEAF,         /* ( 9) v2 B-tree leaf node             */
103
    H5AC_FHEAP_HDR,        /* (10) fractal heap header             */
104
    H5AC_FHEAP_DBLOCK,     /* (11) fractal heap direct block       */
105
    H5AC_FHEAP_IBLOCK,     /* (12) fractal heap indirect block     */
106
    H5AC_FSPACE_HDR,       /* (13) free space header               */
107
    H5AC_FSPACE_SINFO,     /* (14) free space sections             */
108
    H5AC_SOHM_TABLE,       /* (15) shared object header message master table */
109
    H5AC_SOHM_LIST,        /* (16) shared message index stored as a list */
110
    H5AC_EARRAY_HDR,       /* (17) extensible array header         */
111
    H5AC_EARRAY_IBLOCK,    /* (18) extensible array index block    */
112
    H5AC_EARRAY_SBLOCK,    /* (19) extensible array super block    */
113
    H5AC_EARRAY_DBLOCK,    /* (20) extensible array data block     */
114
    H5AC_EARRAY_DBLK_PAGE, /* (21) extensible array data block page */
115
    H5AC_FARRAY_HDR,       /* (22) fixed array header              */
116
    H5AC_FARRAY_DBLOCK,    /* (23) fixed array data block          */
117
    H5AC_FARRAY_DBLK_PAGE, /* (24) fixed array data block page     */
118
    H5AC_SUPERBLOCK,       /* (25) file superblock                 */
119
    H5AC_DRVRINFO,         /* (26) driver info block (supplements superblock) */
120
    H5AC_EPOCH_MARKER,     /* (27) epoch marker - always internal to cache */
121
    H5AC_PROXY_ENTRY,      /* (28) cache entry proxy               */
122
    H5AC_PREFETCHED_ENTRY  /* (29) prefetched entry - always internal to cache */
123
};
124
125
/*-------------------------------------------------------------------------
126
 * Function:    H5AC_init
127
 *
128
 * Purpose:     Initialize the interface from some other layer.
129
 *
130
 * Return:      Success:        non-negative
131
 *              Failure:        negative
132
 *
133
 *-------------------------------------------------------------------------
134
 */
135
herr_t
136
H5AC_init(void)
137
0
{
138
0
    herr_t ret_value = SUCCEED; /* Return value */
139
140
0
    FUNC_ENTER_NOAPI(FAIL)
141
    /* FUNC_ENTER() does all the work */
142
143
0
done:
144
0
    FUNC_LEAVE_NOAPI(ret_value)
145
0
} /* end H5AC_init() */
146
147
/*-------------------------------------------------------------------------
148
 * Function:    H5AC__init_package
149
 *
150
 * Purpose:     Initialize interface-specific information
151
 *
152
 * Return:      Non-negative on success/Negative on failure
153
 *
154
 *-------------------------------------------------------------------------
155
 */
156
herr_t
157
H5AC__init_package(void)
158
6
{
159
6
    FUNC_ENTER_PACKAGE_NOERR
160
161
#ifdef H5_HAVE_PARALLEL
162
    /* check whether to enable strict collective function calling
163
     * sanity checks using MPI barriers
164
     */
165
    {
166
        const char *s; /* String for environment variables */
167
168
        s = getenv("H5_COLL_API_SANITY_CHECK");
169
        if (s && isdigit(*s)) {
170
            long env_val               = strtol(s, NULL, 0);
171
            H5_coll_api_sanity_check_g = (0 == env_val) ? false : true;
172
        }
173
    }
174
#endif /* H5_HAVE_PARALLEL */
175
176
6
    FUNC_LEAVE_NOAPI(SUCCEED)
177
6
} /* end H5AC__init_package() */
178
179
/*-------------------------------------------------------------------------
180
 * Function:    H5AC_term_package
181
 *
182
 * Purpose:     Terminate this interface.
183
 *
184
 * Return:      Success:        Positive if anything was done that might
185
 *                              affect other interfaces; zero otherwise.
186
 *              Failure:        Negative.
187
 *
188
 *-------------------------------------------------------------------------
189
 */
190
int
191
H5AC_term_package(void)
192
36
{
193
36
    FUNC_ENTER_NOAPI_NOINIT_NOERR
194
195
6
    if (H5_PKG_INIT_VAR)
196
        /* Reset interface initialization flag */
197
6
        H5_PKG_INIT_VAR = false;
198
199
6
    FUNC_LEAVE_NOAPI(0)
200
36
} /* end H5AC_term_package() */
201
202
/*-------------------------------------------------------------------------
203
 *
204
 * Function:    H5AC_cache_image_pending()
205
 *
206
 * Purpose:     Debugging function that tests to see if the load of a
207
 *              metadata cache image load is pending (i.e. will be executed
208
 *              on the next protect or insert)
209
 *
210
 *              Returns true if a cache image load is pending, and false
211
 *              if not.  Throws an assertion failure on error.
212
 *
213
 * Return:      true if a cache image load is pending, and false otherwise.
214
 *
215
 *-------------------------------------------------------------------------
216
 */
217
bool
218
H5AC_cache_image_pending(const H5F_t *f)
219
0
{
220
0
    H5C_t *cache_ptr;
221
0
    bool   ret_value = false; /* Return value */
222
223
0
    FUNC_ENTER_NOAPI_NOINIT_NOERR
224
225
    /* Sanity checks */
226
0
    assert(f);
227
0
    assert(f->shared);
228
0
    cache_ptr = f->shared->cache;
229
230
0
    ret_value = H5C_cache_image_pending(cache_ptr);
231
232
0
    FUNC_LEAVE_NOAPI(ret_value)
233
0
} /* H5AC_cache_image_pending() */
234
235
/*-------------------------------------------------------------------------
236
 * Function:    H5AC_create
237
 *
238
 * Purpose:     Initialize the cache just after a file is opened.  The
239
 *              SIZE_HINT is the number of cache slots desired.  If you
240
 *              pass an invalid value then H5AC_NSLOTS is used.  You can
241
 *              turn off caching by using 1 for the SIZE_HINT value.
242
 *
243
 * Return:      Success:        Number of slots actually used.
244
 *
245
 *              Failure:        Negative
246
 *
247
 *-------------------------------------------------------------------------
248
 */
249
herr_t
250
H5AC_create(const H5F_t *f, H5AC_cache_config_t *config_ptr, H5AC_cache_image_config_t *image_config_ptr)
251
3.83k
{
252
#ifdef H5_HAVE_PARALLEL
253
    char        prefix[H5C__PREFIX_LEN] = "";
254
    H5AC_aux_t *aux_ptr                 = NULL;
255
#endif /* H5_HAVE_PARALLEL */
256
3.83k
    struct H5C_cache_image_ctl_t int_ci_config = H5C__DEFAULT_CACHE_IMAGE_CTL;
257
3.83k
    herr_t                       ret_value     = SUCCEED; /* Return value */
258
259
3.83k
    FUNC_ENTER_NOAPI(FAIL)
260
261
    /* Check arguments */
262
3.83k
    assert(f);
263
3.83k
    assert(NULL == f->shared->cache);
264
3.83k
    assert(config_ptr != NULL);
265
3.83k
    assert(image_config_ptr != NULL);
266
3.83k
    assert(image_config_ptr->version == H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION);
267
3.83k
    HDcompile_assert(NELMTS(H5AC_class_s) == H5AC_NTYPES);
268
3.83k
    HDcompile_assert(H5C__MAX_NUM_TYPE_IDS == H5AC_NTYPES);
269
270
    /* Validate configurations */
271
3.83k
    if (H5AC_validate_config(config_ptr) < 0)
272
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Bad cache configuration");
273
3.83k
    if (H5AC_validate_cache_image_config(image_config_ptr) < 0)
274
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Bad cache image configuration");
275
276
#ifdef H5_HAVE_PARALLEL
277
    if (H5F_HAS_FEATURE(f, H5FD_FEAT_HAS_MPI)) {
278
        MPI_Comm mpi_comm;
279
        int      mpi_rank;
280
        int      mpi_size;
281
282
        if (MPI_COMM_NULL == (mpi_comm = H5F_mpi_get_comm(f)))
283
            HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "can't get MPI communicator");
284
285
        if ((mpi_rank = H5F_mpi_get_rank(f)) < 0)
286
            HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "can't get mpi rank");
287
288
        if ((mpi_size = H5F_mpi_get_size(f)) < 0)
289
            HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "can't get mpi size");
290
291
        if (NULL == (aux_ptr = H5FL_CALLOC(H5AC_aux_t)))
292
            HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "Can't allocate H5AC auxiliary structure");
293
294
        aux_ptr->mpi_comm                = mpi_comm;
295
        aux_ptr->mpi_rank                = mpi_rank;
296
        aux_ptr->mpi_size                = mpi_size;
297
        aux_ptr->write_permitted         = false;
298
        aux_ptr->dirty_bytes_threshold   = H5AC__DEFAULT_DIRTY_BYTES_THRESHOLD;
299
        aux_ptr->dirty_bytes             = 0;
300
        aux_ptr->metadata_write_strategy = H5AC__DEFAULT_METADATA_WRITE_STRATEGY;
301
#ifdef H5AC_DEBUG_DIRTY_BYTES_CREATION
302
        aux_ptr->dirty_bytes_propagations      = 0;
303
        aux_ptr->unprotect_dirty_bytes         = 0;
304
        aux_ptr->unprotect_dirty_bytes_updates = 0;
305
        aux_ptr->insert_dirty_bytes            = 0;
306
        aux_ptr->insert_dirty_bytes_updates    = 0;
307
        aux_ptr->move_dirty_bytes              = 0;
308
        aux_ptr->move_dirty_bytes_updates      = 0;
309
#endif /* H5AC_DEBUG_DIRTY_BYTES_CREATION */
310
        aux_ptr->d_slist_ptr         = NULL;
311
        aux_ptr->c_slist_ptr         = NULL;
312
        aux_ptr->candidate_slist_ptr = NULL;
313
        aux_ptr->write_done          = NULL;
314
        aux_ptr->sync_point_done     = NULL;
315
        aux_ptr->p0_image_len        = 0;
316
317
        snprintf(prefix, sizeof(prefix), "%d:", mpi_rank);
318
319
        if (mpi_rank == 0) {
320
            if (NULL == (aux_ptr->d_slist_ptr = H5SL_create(H5SL_TYPE_HADDR, NULL)))
321
                HGOTO_ERROR(H5E_CACHE, H5E_CANTCREATE, FAIL, "can't create dirtied entry list");
322
323
            if (NULL == (aux_ptr->c_slist_ptr = H5SL_create(H5SL_TYPE_HADDR, NULL)))
324
                HGOTO_ERROR(H5E_CACHE, H5E_CANTCREATE, FAIL, "can't create cleaned entry list");
325
        } /* end if */
326
327
        /* construct the candidate skip list for all processes.
328
         * when the distributed strategy is selected as all processes
329
         * will use it in the case of a flush.
330
         */
331
        if (NULL == (aux_ptr->candidate_slist_ptr = H5SL_create(H5SL_TYPE_HADDR, NULL)))
332
            HGOTO_ERROR(H5E_CACHE, H5E_CANTCREATE, FAIL, "can't create candidate entry list");
333
334
        if (aux_ptr->mpi_rank == 0)
335
            f->shared->cache = H5C_create(H5AC__DEFAULT_MAX_CACHE_SIZE, H5AC__DEFAULT_MIN_CLEAN_SIZE,
336
                                          (H5AC_NTYPES - 1), H5AC_class_s, H5AC__check_if_write_permitted,
337
                                          true, H5AC__log_flushed_entry, (void *)aux_ptr);
338
        else
339
            f->shared->cache =
340
                H5C_create(H5AC__DEFAULT_MAX_CACHE_SIZE, H5AC__DEFAULT_MIN_CLEAN_SIZE, (H5AC_NTYPES - 1),
341
                           H5AC_class_s, H5AC__check_if_write_permitted, true, NULL, (void *)aux_ptr);
342
    } /* end if */
343
    else {
344
#endif /* H5_HAVE_PARALLEL */
345
        /* The default max cache size and min clean size will frequently be
346
         * overwritten shortly by the subsequent set resize config call.
347
         *                                             -- JRM
348
         */
349
3.83k
        f->shared->cache =
350
3.83k
            H5C_create(H5AC__DEFAULT_MAX_CACHE_SIZE, H5AC__DEFAULT_MIN_CLEAN_SIZE, (H5AC_NTYPES - 1),
351
3.83k
                       H5AC_class_s, H5AC__check_if_write_permitted, true, NULL, NULL);
352
#ifdef H5_HAVE_PARALLEL
353
    }  /* end else */
354
#endif /* H5_HAVE_PARALLEL */
355
356
3.83k
    if (NULL == f->shared->cache)
357
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "memory allocation failed");
358
359
#ifdef H5_HAVE_PARALLEL
360
    if (aux_ptr != NULL)
361
        if (H5C_set_prefix(f->shared->cache, prefix) < 0)
362
            HGOTO_ERROR(H5E_CACHE, H5E_CANTALLOC, FAIL, "H5C_set_prefix() failed");
363
#endif /* H5_HAVE_PARALLEL */
364
365
    /* Turn on metadata cache logging, if being used
366
     * This will be JSON until we create a special API call. Trace output
367
     * is generated when logging is controlled by the struct.
368
     */
369
3.83k
    if (H5F_USE_MDC_LOGGING(f))
370
0
        if (H5C_log_set_up(f->shared->cache, H5F_MDC_LOG_LOCATION(f), H5C_LOG_STYLE_JSON,
371
0
                           H5F_START_MDC_LOG_ON_ACCESS(f)) < 0)
372
0
            HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "mdc logging setup failed");
373
374
    /* Set the cache parameters */
375
3.83k
    if (H5AC_set_cache_auto_resize_config(f->shared->cache, config_ptr) < 0)
376
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTSET, FAIL, "auto resize configuration failed");
377
378
    /* Don't need to get the current H5C image config here since the
379
     * cache has just been created, and thus f->shared->cache->image_ctl
380
     * must still set to its initial value (H5C__DEFAULT_CACHE_IMAGE_CTL).
381
     * Note that this not true as soon as control returns to the application
382
     * program, as some test code modifies f->shared->cache->image_ctl.
383
     */
384
3.83k
    int_ci_config.version            = image_config_ptr->version;
385
3.83k
    int_ci_config.generate_image     = image_config_ptr->generate_image;
386
3.83k
    int_ci_config.save_resize_status = image_config_ptr->save_resize_status;
387
3.83k
    int_ci_config.entry_ageout       = image_config_ptr->entry_ageout;
388
3.83k
    if (H5C_set_cache_image_config(f, f->shared->cache, &int_ci_config) < 0)
389
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTSET, FAIL, "auto resize configuration failed");
390
391
3.83k
done:
392
    /* If currently logging, generate a message */
393
3.83k
    if (f->shared->cache->log_info->logging)
394
0
        if (H5C_log_write_create_cache_msg(f->shared->cache, ret_value) < 0)
395
0
            HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
396
397
#ifdef H5_HAVE_PARALLEL
398
    /* if there is a failure, try to tidy up the auxiliary structure */
399
    if (ret_value < 0) {
400
        if (aux_ptr != NULL) {
401
            if (aux_ptr->d_slist_ptr != NULL)
402
                H5SL_close(aux_ptr->d_slist_ptr);
403
            if (aux_ptr->c_slist_ptr != NULL)
404
                H5SL_close(aux_ptr->c_slist_ptr);
405
            if (aux_ptr->candidate_slist_ptr != NULL)
406
                H5SL_close(aux_ptr->candidate_slist_ptr);
407
            aux_ptr = H5FL_FREE(H5AC_aux_t, aux_ptr);
408
        } /* end if */
409
    }     /* end if */
410
#endif    /* H5_HAVE_PARALLEL */
411
412
3.83k
    FUNC_LEAVE_NOAPI(ret_value)
413
3.83k
} /* H5AC_create() */
414
415
/*-------------------------------------------------------------------------
416
 * Function:    H5AC_dest
417
 *
418
 * Purpose:     Flushes all data to disk and destroys the cache.
419
 *              This function fails if any object are protected since the
420
 *              resulting file might not be consistent.
421
 *
422
 * Return:      Non-negative on success/Negative on failure
423
 *
424
 *-------------------------------------------------------------------------
425
 */
426
herr_t
427
H5AC_dest(H5F_t *f)
428
3.83k
{
429
3.83k
    bool log_enabled;  /* true if logging was set up */
430
3.83k
    bool curr_logging; /* true if currently logging */
431
#ifdef H5_HAVE_PARALLEL
432
    H5AC_aux_t *aux_ptr = NULL;
433
#endif                          /* H5_HAVE_PARALLEL */
434
3.83k
    herr_t ret_value = SUCCEED; /* Return value */
435
436
3.83k
    FUNC_ENTER_NOAPI(FAIL)
437
438
    /* Sanity check */
439
3.83k
    assert(f);
440
3.83k
    assert(f->shared);
441
3.83k
    assert(f->shared->cache);
442
443
#if H5AC_DUMP_STATS_ON_CLOSE
444
    /* Dump debugging info */
445
    H5AC_stats(f);
446
#endif /* H5AC_DUMP_STATS_ON_CLOSE */
447
448
    /* Check if log messages are being emitted */
449
3.83k
    if (H5C_get_logging_status(f->shared->cache, &log_enabled, &curr_logging) < 0)
450
0
        HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to get logging status");
451
452
    /* Tear down logging */
453
3.83k
    if (log_enabled) {
454
0
        if (curr_logging)
455
0
            if (H5C_log_write_destroy_cache_msg(f->shared->cache) < 0)
456
0
                HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
457
458
0
        if (H5C_log_tear_down(f->shared->cache) < 0)
459
0
            HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "metadata cache logging tear-down failed");
460
0
    } /* end if */
461
462
#ifdef H5_HAVE_PARALLEL
463
    /* destroying the cache, so clear all collective entries */
464
    if (H5C_clear_coll_entries(f->shared->cache, false) < 0)
465
        HGOTO_ERROR(H5E_CACHE, H5E_CANTSET, FAIL, "can't clear collective entries");
466
467
    aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(f->shared->cache);
468
    if (aux_ptr) {
469
        /* If the file was opened R/W, attempt to flush all entries
470
         * from rank 0 & Bcast clean list to other ranks.
471
         *
472
         * Must not flush in the R/O case, as this will trigger the
473
         * free space manager settle routines.
474
         *
475
         * Must also enable the skip list before the call to
476
         * H5AC__flush_entries() and disable it afterwards, as the
477
         * skip list will be disabled after the previous flush.
478
         *
479
         * Note that H5C_dest() does skip list setup and take down as well.
480
         * Unfortunately, we can't do the setup and take down just once,
481
         * as H5C_dest() is called directly in the test code.
482
         *
483
         * Fortunately, the cache should be clean or close to it at this
484
         * point, so the overhead should be minimal.
485
         */
486
        if (H5F_ACC_RDWR & H5F_INTENT(f)) {
487
            /* enable and load the skip list */
488
            if (H5C_set_slist_enabled(f->shared->cache, true, true) < 0)
489
                HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "can't enable skip list");
490
491
            if (H5AC__flush_entries(f) < 0)
492
                HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't flush");
493
494
            /* disable the skip list -- should be empty */
495
            if (H5C_set_slist_enabled(f->shared->cache, false, false) < 0)
496
                HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "can't disable skip list");
497
        } /* end if */
498
    }     /* end if */
499
#endif    /* H5_HAVE_PARALLEL */
500
501
    /* Destroy the cache */
502
3.83k
    if (H5C_dest(f) < 0)
503
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTFREE, FAIL, "can't destroy cache");
504
505
3.83k
    f->shared->cache = NULL;
506
507
#ifdef H5_HAVE_PARALLEL
508
    if (aux_ptr != NULL) {
509
        if (aux_ptr->d_slist_ptr != NULL) {
510
            assert(H5SL_count(aux_ptr->d_slist_ptr) == 0);
511
            H5SL_close(aux_ptr->d_slist_ptr);
512
        } /* end if */
513
514
        if (aux_ptr->c_slist_ptr != NULL) {
515
            assert(H5SL_count(aux_ptr->c_slist_ptr) == 0);
516
            H5SL_close(aux_ptr->c_slist_ptr);
517
        } /* end if */
518
519
        if (aux_ptr->candidate_slist_ptr != NULL) {
520
            assert(H5SL_count(aux_ptr->candidate_slist_ptr) == 0);
521
            H5SL_close(aux_ptr->candidate_slist_ptr);
522
        } /* end if */
523
524
        aux_ptr = H5FL_FREE(H5AC_aux_t, aux_ptr);
525
    }  /* end if */
526
#endif /* H5_HAVE_PARALLEL */
527
528
3.83k
done:
529
3.83k
    FUNC_LEAVE_NOAPI(ret_value)
530
3.83k
} /* H5AC_dest() */
531
532
/*-------------------------------------------------------------------------
533
 * Function:    H5AC_evict
534
 *
535
 * Purpose:     Evict all entries except the pinned entries
536
 *              in the cache.
537
 *
538
 * Return:      Non-negative on success/Negative on failure
539
 *
540
 *-------------------------------------------------------------------------
541
 */
542
herr_t
543
H5AC_evict(H5F_t *f)
544
0
{
545
0
    herr_t ret_value = SUCCEED; /* Return value */
546
547
0
    FUNC_ENTER_NOAPI(FAIL)
548
549
    /* Sanity check */
550
0
    assert(f);
551
0
    assert(f->shared);
552
0
    assert(f->shared->cache);
553
554
    /* Evict all entries in the cache except the pinned superblock entry */
555
0
    if (H5C_evict(f) < 0)
556
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTFREE, FAIL, "can't evict cache");
557
558
0
done:
559
    /* If currently logging, generate a message */
560
0
    if (f->shared->cache->log_info->logging)
561
0
        if (H5C_log_write_evict_cache_msg(f->shared->cache, ret_value) < 0)
562
0
            HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
563
564
0
    FUNC_LEAVE_NOAPI(ret_value)
565
0
} /* H5AC_evict() */
566
567
/*-------------------------------------------------------------------------
568
 * Function:    H5AC_expunge_entry
569
 *
570
 * Purpose:     Expunge the target entry from the cache without writing it
571
 *              to disk even if it is dirty.  The entry must not be either
572
 *              pinned or protected.
573
 *
574
 * Return:      Non-negative on success/Negative on failure
575
 *
576
 *-------------------------------------------------------------------------
577
 */
578
herr_t
579
H5AC_expunge_entry(H5F_t *f, const H5AC_class_t *type, haddr_t addr, unsigned flags)
580
820
{
581
820
    herr_t ret_value = SUCCEED; /* Return value */
582
583
820
    FUNC_ENTER_NOAPI(FAIL)
584
585
    /* Sanity checks */
586
820
    assert(f);
587
820
    assert(f->shared);
588
820
    assert(f->shared->cache);
589
820
    assert(type);
590
820
    assert(type->serialize);
591
820
    assert(H5_addr_defined(addr));
592
593
820
    if (H5C_expunge_entry(f, type, addr, flags) < 0)
594
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTEXPUNGE, FAIL, "H5C_expunge_entry() failed");
595
596
820
done:
597
    /* If currently logging, generate a message */
598
820
    if (f->shared->cache->log_info->logging)
599
0
        if (H5C_log_write_expunge_entry_msg(f->shared->cache, addr, type->id, ret_value) < 0)
600
0
            HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
601
602
820
    FUNC_LEAVE_NOAPI(ret_value)
603
820
} /* H5AC_expunge_entry() */
604
605
/*-------------------------------------------------------------------------
606
 * Function:    H5AC_flush
607
 *
608
 * Purpose:     Flush (and possibly destroy) the metadata cache associated
609
 *              with the specified file.
610
 *
611
 *              If the cache contains protected entries, the function will
612
 *              fail, as protected entries cannot be flushed.  However
613
 *              all unprotected entries should be flushed before the
614
 *              function returns failure.
615
 *
616
 * Return:      Non-negative on success/Negative on failure if there was a
617
 *              request to flush all items and something was protected.
618
 *
619
 *-------------------------------------------------------------------------
620
 */
621
herr_t
622
H5AC_flush(H5F_t *f)
623
0
{
624
0
    herr_t ret_value = SUCCEED; /* Return value */
625
626
0
    FUNC_ENTER_NOAPI(FAIL)
627
628
    /* Sanity checks */
629
0
    assert(f);
630
0
    assert(f->shared);
631
0
    assert(f->shared->cache);
632
633
#ifdef H5_HAVE_PARALLEL
634
    /* flushing the cache, so clear all collective entries */
635
    if (H5C_clear_coll_entries(f->shared->cache, false) < 0)
636
        HGOTO_ERROR(H5E_CACHE, H5E_CANTGET, FAIL, "H5C_clear_coll_entries() failed");
637
638
    /* Attempt to flush all entries from rank 0 & Bcast clean list to other ranks */
639
    if (H5AC__flush_entries(f) < 0)
640
        HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't flush");
641
#endif /* H5_HAVE_PARALLEL */
642
643
    /* Flush the cache */
644
    /* (Again, in parallel - writes out the superblock) */
645
0
    if (H5C_flush_cache(f, H5AC__NO_FLAGS_SET) < 0)
646
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't flush cache");
647
648
0
done:
649
    /* If currently logging, generate a message */
650
0
    if (f->shared->cache->log_info->logging)
651
0
        if (H5C_log_write_flush_cache_msg(f->shared->cache, ret_value) < 0)
652
0
            HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
653
654
0
    FUNC_LEAVE_NOAPI(ret_value)
655
0
} /* H5AC_flush() */
656
657
/*-------------------------------------------------------------------------
658
 * Function:    H5AC_get_entry_status
659
 *
660
 * Purpose:     Given a file address, determine whether the metadata
661
 *              cache contains an entry at that location.  If it does,
662
 *              also determine whether the entry is dirty, protected,
663
 *              pinned, etc. and return that information to the caller
664
 *              in *status.
665
 *
666
 *              If the specified entry doesn't exist, set *status_ptr
667
 *              to zero.
668
 *
669
 *              On error, the value of *status is undefined.
670
 *
671
 * Return:      Non-negative on success/Negative on failure
672
 *
673
 *-------------------------------------------------------------------------
674
 */
675
herr_t
676
H5AC_get_entry_status(const H5F_t *f, haddr_t addr, unsigned *status)
677
0
{
678
0
    bool   in_cache;     /* Entry @ addr is in the cache */
679
0
    bool   is_dirty;     /* Entry @ addr is in the cache and dirty */
680
0
    bool   is_protected; /* Entry @ addr is in the cache and protected */
681
0
    bool   is_pinned;    /* Entry @ addr is in the cache and pinned */
682
0
    bool   is_corked;
683
0
    bool   is_flush_dep_child;  /* Entry @ addr is in the cache and is a flush dependency child */
684
0
    bool   is_flush_dep_parent; /* Entry @ addr is in the cache and is a flush dependency parent */
685
0
    bool   image_is_up_to_date; /* Entry @ addr is in the cache and has an up to date image */
686
0
    herr_t ret_value = SUCCEED; /* Return value */
687
688
0
    FUNC_ENTER_NOAPI(FAIL)
689
690
0
    if ((f == NULL) || (!H5_addr_defined(addr)) || (status == NULL))
691
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad param(s) on entry");
692
693
0
    if (H5C_get_entry_status(f, addr, NULL, &in_cache, &is_dirty, &is_protected, &is_pinned, &is_corked,
694
0
                             &is_flush_dep_parent, &is_flush_dep_child, &image_is_up_to_date) < 0)
695
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_get_entry_status() failed");
696
697
0
    if (in_cache) {
698
0
        *status |= H5AC_ES__IN_CACHE;
699
0
        if (is_dirty)
700
0
            *status |= H5AC_ES__IS_DIRTY;
701
0
        if (is_protected)
702
0
            *status |= H5AC_ES__IS_PROTECTED;
703
0
        if (is_pinned)
704
0
            *status |= H5AC_ES__IS_PINNED;
705
0
        if (is_corked)
706
0
            *status |= H5AC_ES__IS_CORKED;
707
0
        if (is_flush_dep_parent)
708
0
            *status |= H5AC_ES__IS_FLUSH_DEP_PARENT;
709
0
        if (is_flush_dep_child)
710
0
            *status |= H5AC_ES__IS_FLUSH_DEP_CHILD;
711
0
        if (image_is_up_to_date)
712
0
            *status |= H5AC_ES__IMAGE_IS_UP_TO_DATE;
713
0
    } /* end if */
714
0
    else
715
0
        *status = 0;
716
717
0
done:
718
0
    FUNC_LEAVE_NOAPI(ret_value)
719
0
} /* H5AC_get_entry_status() */
720
721
/*-------------------------------------------------------------------------
722
 * Function:    H5AC_insert_entry
723
 *
724
 * Purpose:     Adds the specified thing to the cache.  The thing need not
725
 *              exist on disk yet, but it must have an address and disk
726
 *              space reserved.
727
 *
728
 * Return:      Non-negative on success/Negative on failure
729
 *
730
 *-------------------------------------------------------------------------
731
 */
732
herr_t
733
H5AC_insert_entry(H5F_t *f, const H5AC_class_t *type, haddr_t addr, void *thing, unsigned int flags)
734
0
{
735
0
    herr_t ret_value = SUCCEED; /* Return value */
736
737
0
    FUNC_ENTER_NOAPI(FAIL)
738
739
    /* Sanity checks */
740
0
    assert(f);
741
0
    assert(f->shared);
742
0
    assert(f->shared->cache);
743
0
    assert(type);
744
0
    assert(type->serialize);
745
0
    assert(H5_addr_defined(addr));
746
0
    assert(thing);
747
748
    /* Check for invalid access request */
749
0
    if (0 == (H5F_INTENT(f) & H5F_ACC_RDWR))
750
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "no write intent on file");
751
752
#if H5AC_DO_TAGGING_SANITY_CHECKS
753
    if (!H5C_get_ignore_tags(f->shared->cache) && H5AC__verify_tag(type) < 0)
754
        HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "Bad tag value");
755
#endif /* H5AC_DO_TAGGING_SANITY_CHECKS */
756
757
    /* Insert entry into metadata cache */
758
0
    if (H5C_insert_entry(f, type, addr, thing, flags) < 0)
759
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTINS, FAIL, "H5C_insert_entry() failed");
760
761
#ifdef H5_HAVE_PARALLEL
762
    {
763
        H5AC_aux_t *aux_ptr;
764
765
        if (NULL != (aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(f->shared->cache))) {
766
            /* Log the new entry */
767
            if (H5AC__log_inserted_entry((H5AC_info_t *)thing) < 0)
768
                HGOTO_ERROR(H5E_CACHE, H5E_CANTINS, FAIL, "H5AC__log_inserted_entry() failed");
769
770
            /* Check if we should try to flush */
771
            if (aux_ptr->dirty_bytes >= aux_ptr->dirty_bytes_threshold)
772
                if (H5AC__run_sync_point(f, H5AC_SYNC_POINT_OP__FLUSH_TO_MIN_CLEAN) < 0)
773
                    HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't run sync point");
774
        } /* end if */
775
    }
776
#endif /* H5_HAVE_PARALLEL */
777
778
0
done:
779
    /* If currently logging, generate a message */
780
0
    if (f->shared->cache->log_info->logging)
781
0
        if (H5C_log_write_insert_entry_msg(f->shared->cache, addr, type->id, flags,
782
0
                                           ((H5C_cache_entry_t *)thing)->size, ret_value) < 0)
783
0
            HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
784
785
0
    FUNC_LEAVE_NOAPI(ret_value)
786
0
} /* H5AC_insert_entry() */
787
788
/*-------------------------------------------------------------------------
789
 * Function:    H5AC_load_cache_image_on_next_protect
790
 *
791
 * Purpose:     Load the cache image block at the specified location,
792
 *              decode it, and insert its contents into the metadata
793
 *              cache.
794
 *
795
 * Return:      Non-negative on success/Negative on failure
796
 *
797
 *-------------------------------------------------------------------------
798
 */
799
herr_t
800
H5AC_load_cache_image_on_next_protect(H5F_t *f, haddr_t addr, hsize_t len, bool rw)
801
0
{
802
0
    herr_t ret_value = SUCCEED; /* Return value */
803
804
0
    FUNC_ENTER_NOAPI(FAIL)
805
806
    /* Sanity checks */
807
0
    assert(f);
808
0
    assert(f->shared);
809
0
    assert(f->shared->cache);
810
811
0
    if (H5C_load_cache_image_on_next_protect(f, addr, len, rw) < 0)
812
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTLOAD, FAIL, "call to H5C_load_cache_image_on_next_protect failed");
813
814
0
done:
815
0
    FUNC_LEAVE_NOAPI(ret_value)
816
0
} /* H5AC_load_cache_image_on_next_protect() */
817
818
/*-------------------------------------------------------------------------
819
 * Function:    H5AC_mark_entry_dirty
820
 *
821
 * Purpose:     Mark a pinned or protected entry as dirty.  The target
822
 *              entry MUST be either pinned, protected, or both.
823
 *
824
 * Return:      Non-negative on success/Negative on failure
825
 *
826
 *-------------------------------------------------------------------------
827
 */
828
herr_t
829
H5AC_mark_entry_dirty(void *thing)
830
0
{
831
0
    H5AC_info_t *entry_ptr = NULL;    /* Pointer to the cache entry */
832
0
    H5C_t       *cache_ptr = NULL;    /* Pointer to the entry's associated metadata cache */
833
0
    herr_t       ret_value = SUCCEED; /* Return value */
834
835
0
    FUNC_ENTER_NOAPI(FAIL)
836
837
    /* Sanity check */
838
0
    assert(thing);
839
840
    /* Set up entry & cache pointers */
841
0
    entry_ptr = (H5AC_info_t *)thing;
842
0
    cache_ptr = entry_ptr->cache_ptr;
843
844
#ifdef H5_HAVE_PARALLEL
845
    {
846
        H5AC_aux_t *aux_ptr;
847
848
        aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
849
        if ((!entry_ptr->is_dirty) && (!entry_ptr->is_protected) && (entry_ptr->is_pinned) &&
850
            (NULL != aux_ptr))
851
            if (H5AC__log_dirtied_entry(entry_ptr) < 0)
852
                HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKDIRTY, FAIL, "can't log dirtied entry");
853
    }
854
#endif /* H5_HAVE_PARALLEL */
855
856
0
    if (H5C_mark_entry_dirty(thing) < 0)
857
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKDIRTY, FAIL, "can't mark pinned or protected entry dirty");
858
859
0
done:
860
    /* If currently logging, generate a message */
861
0
    if (cache_ptr != NULL && cache_ptr->log_info != NULL)
862
0
        if (cache_ptr->log_info->logging)
863
0
            if (H5C_log_write_mark_entry_dirty_msg(cache_ptr, entry_ptr, ret_value) < 0)
864
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
865
866
0
    FUNC_LEAVE_NOAPI(ret_value)
867
0
} /* H5AC_mark_entry_dirty() */
868
869
/*-------------------------------------------------------------------------
870
 * Function:    H5AC_mark_entry_clean
871
 *
872
 * Purpose:     Mark a pinned entry as clean.  The target
873
 *              entry MUST be pinned.
874
 *
875
 * Return:      Non-negative on success/Negative on failure
876
 *
877
 *-------------------------------------------------------------------------
878
 */
879
herr_t
880
H5AC_mark_entry_clean(void *thing)
881
0
{
882
0
    H5AC_info_t *entry_ptr = NULL;    /* Pointer to the cache entry */
883
0
    H5C_t       *cache_ptr = NULL;    /* Pointer to the entry's associated metadata cache */
884
0
    herr_t       ret_value = SUCCEED; /* Return value */
885
886
0
    FUNC_ENTER_NOAPI(FAIL)
887
888
    /* Sanity check */
889
0
    assert(thing);
890
891
0
    entry_ptr = (H5AC_info_t *)thing;
892
0
    cache_ptr = entry_ptr->cache_ptr;
893
894
#ifdef H5_HAVE_PARALLEL
895
    {
896
        H5AC_aux_t *aux_ptr;
897
898
        aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
899
        if ((!entry_ptr->is_dirty) && (!entry_ptr->is_protected) && (entry_ptr->is_pinned) &&
900
            (NULL != aux_ptr))
901
            if (H5AC__log_cleaned_entry(entry_ptr) < 0)
902
                HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKCLEAN, FAIL, "can't log cleaned entry");
903
    }
904
#endif /* H5_HAVE_PARALLEL */
905
906
0
    if (H5C_mark_entry_clean(thing) < 0)
907
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKCLEAN, FAIL, "can't mark pinned or protected entry clean");
908
909
0
done:
910
    /* If currently logging, generate a message */
911
0
    if (cache_ptr != NULL && cache_ptr->log_info != NULL)
912
0
        if (cache_ptr->log_info->logging)
913
0
            if (H5C_log_write_mark_entry_clean_msg(cache_ptr, entry_ptr, ret_value) < 0)
914
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
915
916
0
    FUNC_LEAVE_NOAPI(ret_value)
917
0
} /* H5AC_mark_entry_clean() */
918
919
/*-------------------------------------------------------------------------
920
 * Function:    H5AC_mark_entry_unserialized
921
 *
922
 * Purpose:     Mark a pinned or protected entry as unserialized.  The target
923
 *              entry MUST be either pinned, protected, or both.
924
 *
925
 * Return:      Non-negative on success/Negative on failure
926
 *
927
 *-------------------------------------------------------------------------
928
 */
929
herr_t
930
H5AC_mark_entry_unserialized(void *thing)
931
0
{
932
0
    H5AC_info_t *entry_ptr = NULL;    /* Pointer to the cache entry */
933
0
    H5C_t       *cache_ptr = NULL;    /* Pointer to the entry's associated metadata cache */
934
0
    herr_t       ret_value = SUCCEED; /* Return value */
935
936
0
    FUNC_ENTER_NOAPI(FAIL)
937
938
    /* Sanity check */
939
0
    assert(thing);
940
941
    /* Set up entry & cache pointers */
942
0
    entry_ptr = (H5AC_info_t *)thing;
943
0
    cache_ptr = entry_ptr->cache_ptr;
944
945
0
    if (H5C_mark_entry_unserialized(thing) < 0)
946
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKUNSERIALIZED, FAIL, "can't mark entry unserialized");
947
948
0
done:
949
    /* If currently logging, generate a message */
950
0
    if (cache_ptr != NULL && cache_ptr->log_info != NULL)
951
0
        if (cache_ptr->log_info->logging)
952
0
            if (H5C_log_write_mark_unserialized_entry_msg(cache_ptr, entry_ptr, ret_value) < 0)
953
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
954
955
0
    FUNC_LEAVE_NOAPI(ret_value)
956
0
} /* H5AC_mark_entry_unserialized() */
957
958
/*-------------------------------------------------------------------------
959
 * Function:    H5AC_mark_entry_serialized
960
 *
961
 * Purpose:     Mark a pinned entry as serialized.  The target
962
 *              entry MUST be pinned.
963
 *
964
 * Return:      Non-negative on success/Negative on failure
965
 *
966
 *-------------------------------------------------------------------------
967
 */
968
herr_t
969
H5AC_mark_entry_serialized(void *thing)
970
0
{
971
0
    H5AC_info_t *entry_ptr = NULL;    /* Pointer to the cache entry */
972
0
    H5C_t       *cache_ptr = NULL;    /* Pointer to the entry's associated metadata cache */
973
0
    herr_t       ret_value = SUCCEED; /* Return value */
974
975
0
    FUNC_ENTER_NOAPI(FAIL)
976
977
    /* Sanity check */
978
0
    assert(thing);
979
980
0
    entry_ptr = (H5AC_info_t *)thing;
981
0
    cache_ptr = entry_ptr->cache_ptr;
982
983
0
    if (H5C_mark_entry_serialized(thing) < 0)
984
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKSERIALIZED, FAIL, "can't mark entry serialized");
985
986
0
done:
987
    /* If currently logging, generate a message */
988
0
    if (cache_ptr != NULL && cache_ptr->log_info != NULL)
989
0
        if (cache_ptr->log_info->logging)
990
0
            if (H5C_log_write_mark_serialized_entry_msg(cache_ptr, entry_ptr, ret_value) < 0)
991
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
992
993
0
    FUNC_LEAVE_NOAPI(ret_value)
994
0
} /* H5AC_mark_entry_serialized() */
995
996
/*-------------------------------------------------------------------------
997
 * Function:    H5AC_move_entry
998
 *
999
 * Purpose:     Use this function to notify the cache that an object's
1000
 *              file address changed.
1001
 *
1002
 * Return:      Non-negative on success/Negative on failure
1003
 *
1004
 *-------------------------------------------------------------------------
1005
 */
1006
herr_t
1007
H5AC_move_entry(H5F_t *f, const H5AC_class_t *type, haddr_t old_addr, haddr_t new_addr)
1008
0
{
1009
#ifdef H5_HAVE_PARALLEL
1010
    H5AC_aux_t *aux_ptr;
1011
#endif                          /* H5_HAVE_PARALLEL */
1012
0
    herr_t ret_value = SUCCEED; /* Return value */
1013
1014
0
    FUNC_ENTER_NOAPI(FAIL)
1015
1016
    /* Sanity checks */
1017
0
    assert(f);
1018
0
    assert(f->shared->cache);
1019
0
    assert(type);
1020
0
    assert(H5_addr_defined(old_addr));
1021
0
    assert(H5_addr_defined(new_addr));
1022
0
    assert(H5_addr_ne(old_addr, new_addr));
1023
1024
#ifdef H5_HAVE_PARALLEL
1025
    /* Log moving the entry */
1026
    if (NULL != (aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(f->shared->cache)))
1027
        if (H5AC__log_moved_entry(f, old_addr, new_addr) < 0)
1028
            HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "can't log moved entry");
1029
#endif /* H5_HAVE_PARALLEL */
1030
1031
0
    if (H5C_move_entry(f->shared->cache, type, old_addr, new_addr) < 0)
1032
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTMOVE, FAIL, "H5C_move_entry() failed");
1033
1034
#ifdef H5_HAVE_PARALLEL
1035
    /* Check if we should try to flush */
1036
    if (NULL != aux_ptr && aux_ptr->dirty_bytes >= aux_ptr->dirty_bytes_threshold)
1037
        if (H5AC__run_sync_point(f, H5AC_SYNC_POINT_OP__FLUSH_TO_MIN_CLEAN) < 0)
1038
            HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't run sync point");
1039
#endif /* H5_HAVE_PARALLEL */
1040
1041
0
done:
1042
    /* If currently logging, generate a message */
1043
0
    if (f->shared->cache->log_info->logging)
1044
0
        if (H5C_log_write_move_entry_msg(f->shared->cache, old_addr, new_addr, type->id, ret_value) < 0)
1045
0
            HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
1046
1047
0
    FUNC_LEAVE_NOAPI(ret_value)
1048
0
} /* H5AC_move_entry() */
1049
1050
/*-------------------------------------------------------------------------
1051
 * Function:    H5AC_pin_protected_entry()
1052
 *
1053
 * Purpose:     Pin a protected cache entry.  The entry must be protected
1054
 *              at the time of call, and must be unpinned.
1055
 *
1056
 * Return:      Non-negative on success/Negative on failure
1057
 *
1058
 *-------------------------------------------------------------------------
1059
 */
1060
herr_t
1061
H5AC_pin_protected_entry(void *thing)
1062
128k
{
1063
128k
    H5AC_info_t *entry_ptr = NULL;    /* Pointer to the cache entry */
1064
128k
    H5C_t       *cache_ptr = NULL;    /* Pointer to the entry's associated metadata cache */
1065
128k
    herr_t       ret_value = SUCCEED; /* Return value */
1066
1067
128k
    FUNC_ENTER_NOAPI(FAIL)
1068
1069
    /* Sanity check */
1070
128k
    assert(thing);
1071
1072
128k
    entry_ptr = (H5AC_info_t *)thing;
1073
128k
    cache_ptr = entry_ptr->cache_ptr;
1074
128k
    assert(cache_ptr);
1075
1076
    /* Pin entry */
1077
128k
    if (H5C_pin_protected_entry(thing) < 0)
1078
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTPIN, FAIL, "can't pin entry");
1079
1080
128k
done:
1081
    /* If currently logging, generate a message */
1082
128k
    if (cache_ptr != NULL && cache_ptr->log_info != NULL)
1083
128k
        if (cache_ptr->log_info->logging)
1084
0
            if (H5C_log_write_pin_entry_msg(cache_ptr, entry_ptr, ret_value) < 0)
1085
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
1086
1087
128k
    FUNC_LEAVE_NOAPI(ret_value)
1088
128k
} /* H5AC_pin_protected_entry() */
1089
1090
/*-------------------------------------------------------------------------
1091
 *
1092
 * Function:    H5AC_prep_for_file_close
1093
 *
1094
 * Purpose:     This function should be called just prior to the cache
1095
 *              flushes at file close.
1096
 *
1097
 *              The objective of the call is to allow the metadata cache
1098
 *              to do any preparatory work prior to generation of a
1099
 *              cache image.
1100
 *
1101
 * Return:      Non-negative on success/Negative on failure
1102
 *
1103
 *-------------------------------------------------------------------------
1104
 */
1105
herr_t
1106
H5AC_prep_for_file_close(H5F_t *f)
1107
3.83k
{
1108
3.83k
    herr_t ret_value = SUCCEED; /* Return value */
1109
1110
3.83k
    FUNC_ENTER_NOAPI(FAIL)
1111
1112
    /* Sanity checks */
1113
3.83k
    assert(f);
1114
3.83k
    assert(f->shared);
1115
3.83k
    assert(f->shared->cache);
1116
1117
3.83k
    if (H5C_prep_for_file_close(f) < 0)
1118
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "cache prep for file close failed");
1119
1120
3.83k
done:
1121
3.83k
    FUNC_LEAVE_NOAPI(ret_value)
1122
3.83k
} /* H5AC_prep_for_file_close() */
1123
1124
/*-------------------------------------------------------------------------
1125
 *
1126
 * Function:    H5AC_prep_for_file_flush
1127
 *
1128
 * Purpose:     Handle any setup required prior to metadata cache flush.
1129
 *
1130
 *              This function should be called just prior to the first
1131
 *              call to H5AC_flush() during a file flush.
1132
 *
1133
 *              Initially, this means setting up the skip list prior to the
1134
 *              flush.  We do this in a separate call because
1135
 *              H5F__flush_phase2() make repeated calls to H5AC_flush().
1136
 *              Handling this detail in separate calls allows us to avoid
1137
 *              the overhead of setting up and taking down the skip list
1138
 *              repeatedly.
1139
 *
1140
 * Return:      Non-negative on success/Negative on failure
1141
 *
1142
 *-------------------------------------------------------------------------
1143
 */
1144
herr_t
1145
H5AC_prep_for_file_flush(H5F_t *f)
1146
0
{
1147
0
    herr_t ret_value = SUCCEED; /* Return value */
1148
1149
0
    FUNC_ENTER_NOAPI(FAIL)
1150
1151
    /* Sanity checks */
1152
0
    assert(f);
1153
0
    assert(f->shared);
1154
0
    assert(f->shared->cache);
1155
1156
0
    if (H5C_set_slist_enabled(f->shared->cache, true, true) < 0)
1157
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "can't enable skip list");
1158
1159
0
done:
1160
0
    FUNC_LEAVE_NOAPI(ret_value)
1161
0
} /* H5AC_prep_for_file_flush() */
1162
1163
/*-------------------------------------------------------------------------
1164
 *
1165
 * Function:    H5AC_secure_from_file_flush
1166
 *
1167
 * Purpose:     This function should be called just after the last
1168
 *              call to H5AC_flush() during a file flush.
1169
 *
1170
 *              The objective of the call is to allow the metadata cache
1171
 *              to do any necessary necessary cleanup work after a cache
1172
 *              flush.
1173
 *
1174
 *              Initially, this means taking down the skip list after the
1175
 *              flush.  We do this in a separate call because
1176
 *              H5F__flush_phase2() make repeated calls to H5AC_flush().
1177
 *              Handling this detail in separate calls allows us to avoid
1178
 *              the overhead of setting up and taking down the skip list
1179
 *              repeatedly.
1180
 *
1181
 * Return:      Non-negative on success/Negative on failure
1182
 *
1183
 *-------------------------------------------------------------------------
1184
 */
1185
herr_t
1186
H5AC_secure_from_file_flush(H5F_t *f)
1187
0
{
1188
0
    herr_t ret_value = SUCCEED; /* Return value */
1189
1190
0
    FUNC_ENTER_NOAPI(FAIL)
1191
1192
    /* Sanity checks */
1193
0
    assert(f);
1194
0
    assert(f->shared);
1195
0
    assert(f->shared->cache);
1196
1197
0
    if (H5C_set_slist_enabled(f->shared->cache, false, false) < 0)
1198
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "can't disable skip list");
1199
1200
0
done:
1201
0
    FUNC_LEAVE_NOAPI(ret_value)
1202
0
} /* H5AC_secure_from_file_flush() */
1203
1204
/*-------------------------------------------------------------------------
1205
 *
1206
 * Function:    H5AC_create_flush_dependency()
1207
 *
1208
 * Purpose:     Create a flush dependency between two entries in the metadata
1209
 *              cache.
1210
 *
1211
 * Return:      Non-negative on success/Negative on failure
1212
 *
1213
 *-------------------------------------------------------------------------
1214
 */
1215
herr_t
1216
H5AC_create_flush_dependency(void *parent_thing, void *child_thing)
1217
0
{
1218
0
    H5AC_info_t *entry_ptr = NULL;    /* Pointer to the cache entry */
1219
0
    H5C_t       *cache_ptr = NULL;    /* Pointer to the entry's associated metadata cache */
1220
0
    herr_t       ret_value = SUCCEED; /* Return value */
1221
1222
0
    FUNC_ENTER_NOAPI(FAIL)
1223
1224
    /* Sanity check */
1225
0
    assert(parent_thing);
1226
0
    assert(child_thing);
1227
1228
0
    entry_ptr = (H5AC_info_t *)parent_thing;
1229
0
    cache_ptr = entry_ptr->cache_ptr;
1230
0
    assert(cache_ptr);
1231
1232
    /* Create the flush dependency */
1233
0
    if (H5C_create_flush_dependency(parent_thing, child_thing) < 0)
1234
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTDEPEND, FAIL, "H5C_create_flush_dependency() failed");
1235
1236
0
done:
1237
    /* If currently logging, generate a message */
1238
0
    if (cache_ptr != NULL && cache_ptr->log_info != NULL)
1239
0
        if (cache_ptr->log_info->logging)
1240
0
            if (H5C_log_write_create_fd_msg(cache_ptr, (H5AC_info_t *)parent_thing,
1241
0
                                            (H5AC_info_t *)child_thing, ret_value) < 0)
1242
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
1243
1244
0
    FUNC_LEAVE_NOAPI(ret_value)
1245
0
} /* H5AC_create_flush_dependency() */
1246
1247
/*-------------------------------------------------------------------------
1248
 * Function:    H5AC_protect
1249
 *
1250
 * Purpose:     If the target entry is not in the cache, load it.  If
1251
 *              necessary, attempt to evict one or more entries to keep
1252
 *              the cache within its maximum size.
1253
 *
1254
 *              Mark the target entry as protected, and return its address
1255
 *              to the caller.  The caller must call H5AC_unprotect() when
1256
 *              finished with the entry.
1257
 *
1258
 *              While it is protected, the entry may not be either evicted
1259
 *              or flushed -- nor may it be accessed by another call to
1260
 *              H5AC_protect.  Any attempt to do so will result in a failure.
1261
 *
1262
 * Return:      Success:        Ptr to the object.
1263
 *              Failure:        NULL
1264
 *
1265
 *-------------------------------------------------------------------------
1266
 */
1267
void *
1268
H5AC_protect(H5F_t *f, const H5AC_class_t *type, haddr_t addr, void *udata, unsigned flags)
1269
2.20M
{
1270
2.20M
    void *thing     = NULL; /* Pointer to native data structure for entry */
1271
2.20M
    void *ret_value = NULL; /* Return value */
1272
1273
2.20M
    FUNC_ENTER_NOAPI(NULL)
1274
1275
    /* Sanity check */
1276
2.20M
    assert(f);
1277
2.20M
    assert(f->shared);
1278
2.20M
    assert(f->shared->cache);
1279
2.20M
    assert(type);
1280
2.20M
    assert(type->serialize);
1281
2.20M
    assert(H5_addr_defined(addr));
1282
1283
    /* Check for unexpected flags -- H5C__FLUSH_COLLECTIVELY_FLAG
1284
     * only permitted in the parallel case.
1285
     */
1286
#ifdef H5_HAVE_PARALLEL
1287
    assert(0 == (flags &
1288
                 (unsigned)(~(H5C__READ_ONLY_FLAG | H5C__FLUSH_LAST_FLAG | H5C__FLUSH_COLLECTIVELY_FLAG))));
1289
#else  /* H5_HAVE_PARALLEL */
1290
2.20M
    assert(0 == (flags & (unsigned)(~(H5C__READ_ONLY_FLAG | H5C__FLUSH_LAST_FLAG))));
1291
2.20M
#endif /* H5_HAVE_PARALLEL */
1292
1293
    /* Check for invalid access request */
1294
2.20M
    if ((0 == (H5F_INTENT(f) & H5F_ACC_RDWR)) && (0 == (flags & H5C__READ_ONLY_FLAG)))
1295
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, NULL, "no write intent on file");
1296
1297
#if H5AC_DO_TAGGING_SANITY_CHECKS
1298
    if (!H5C_get_ignore_tags(f->shared->cache) && H5AC__verify_tag(type) < 0)
1299
        HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, NULL, "Bad tag value");
1300
#endif /* H5AC_DO_TAGGING_SANITY_CHECKS */
1301
1302
2.20M
    if (NULL == (thing = H5C_protect(f, type, addr, udata, flags)))
1303
7.60k
        HGOTO_ERROR(H5E_CACHE, H5E_CANTPROTECT, NULL, "H5C_protect() failed");
1304
1305
    /* Set return value */
1306
2.19M
    ret_value = thing;
1307
1308
2.20M
done:
1309
    /* If currently logging, generate a message */
1310
2.20M
    {
1311
2.20M
        herr_t fake_ret_value = (NULL == ret_value) ? FAIL : SUCCEED;
1312
1313
2.20M
        if (f->shared->cache->log_info->logging)
1314
0
            if (H5C_log_write_protect_entry_msg(f->shared->cache, (H5AC_info_t *)thing, type->id, flags,
1315
0
                                                fake_ret_value) < 0)
1316
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, NULL, "unable to emit log message");
1317
2.20M
    }
1318
1319
2.20M
    FUNC_LEAVE_NOAPI(ret_value)
1320
2.20M
} /* H5AC_protect() */
1321
1322
/*-------------------------------------------------------------------------
1323
 * Function:    H5AC_resize_entry
1324
 *
1325
 * Purpose:     Resize a pinned or protected entry.
1326
 *
1327
 * Return:      Non-negative on success/Negative on failure
1328
 *
1329
 *-------------------------------------------------------------------------
1330
 */
1331
herr_t
1332
H5AC_resize_entry(void *thing, size_t new_size)
1333
0
{
1334
0
    H5AC_info_t *entry_ptr = NULL;    /* Pointer to the cache entry */
1335
0
    H5C_t       *cache_ptr = NULL;    /* Pointer to the entry's associated metadata cache */
1336
0
    herr_t       ret_value = SUCCEED; /* Return value */
1337
1338
0
    FUNC_ENTER_NOAPI(FAIL)
1339
1340
    /* Sanity check */
1341
0
    assert(thing);
1342
1343
0
    entry_ptr = (H5AC_info_t *)thing;
1344
0
    cache_ptr = entry_ptr->cache_ptr;
1345
0
    assert(cache_ptr);
1346
1347
#ifdef H5_HAVE_PARALLEL
1348
    /* Log the generation of dirty bytes of metadata iff:
1349
     *
1350
     * 1) The entry is clean on entry, and this resize will dirty it
1351
     *    (i.e. the current and new sizes are different), and
1352
     *
1353
     * 2) This is a parallel computation -- which it is if the aux_ptr
1354
     *    is non-null.
1355
     *
1356
     * A few points to note about this section of the code:
1357
     *
1358
     * 1) This call must occur before the call to H5C_resize_entry() since
1359
     *    H5AC__log_dirtied_entry() expects the target entry to be clean
1360
     *    on entry.
1361
     *
1362
     * 2) This code has some basic issues in terms of the number of bytes
1363
     *    added to the dirty bytes count.
1364
     *
1365
     *    First, it adds the initial entry size to aux_ptr->dirty_bytes,
1366
     *    not the final size.  Note that this code used to use the final
1367
     *    size, but code to support this has been removed from
1368
     *    H5AC__log_dirtied_entry() for reasons unknown since I wrote this
1369
     *    code.
1370
     *
1371
     *    As long as all ranks do the same thing here, this probably doesn't
1372
     *    matter much, although it will delay initiation of sync points.
1373
     *
1374
     *    A more interesting point is that this code will not increment
1375
     *    aux_ptr->dirty_bytes if a dirty entry is resized.  At first glance
1376
     *    this seems major, as particularly with the older file formats,
1377
     *    resizes can be quite large.  However, this is probably not an
1378
     *    issue either, since such resizes will be accompanied by large
1379
     *    amounts of dirty metadata creation in other areas -- which will
1380
     *    cause aux_ptr->dirty_bytes to be incremented.
1381
     *
1382
     */
1383
1384
    if ((!entry_ptr->is_dirty) && (entry_ptr->size != new_size)) {
1385
1386
        /* the entry is clean, and will be marked dirty in the resize
1387
         * operation.
1388
         */
1389
        H5AC_aux_t *aux_ptr;
1390
1391
        aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr);
1392
1393
        if (NULL != aux_ptr) {
1394
1395
            if (H5AC__log_dirtied_entry(entry_ptr) < 0)
1396
                HGOTO_ERROR(H5E_CACHE, H5E_CANTMARKDIRTY, FAIL, "can't log dirtied entry");
1397
        }
1398
    }
1399
#endif /* H5_HAVE_PARALLEL */
1400
1401
    /* Resize the entry */
1402
0
    if (H5C_resize_entry(thing, new_size) < 0)
1403
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTRESIZE, FAIL, "can't resize entry");
1404
1405
0
done:
1406
    /* If currently logging, generate a message */
1407
0
    if (cache_ptr != NULL && cache_ptr->log_info != NULL)
1408
0
        if (cache_ptr->log_info->logging)
1409
0
            if (H5C_log_write_resize_entry_msg(cache_ptr, entry_ptr, new_size, ret_value) < 0)
1410
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
1411
1412
0
    FUNC_LEAVE_NOAPI(ret_value)
1413
0
} /* H5AC_resize_entry() */
1414
1415
/*-------------------------------------------------------------------------
1416
 * Function:    H5AC_unpin_entry()
1417
 *
1418
 * Purpose:     Unpin a cache entry.  The entry must be unprotected at
1419
 *              the time of call, and must be pinned.
1420
 *
1421
 * Return:      Non-negative on success/Negative on failure
1422
 *
1423
 *-------------------------------------------------------------------------
1424
 */
1425
herr_t
1426
H5AC_unpin_entry(void *thing)
1427
128k
{
1428
128k
    H5AC_info_t *entry_ptr = NULL;    /* Pointer to the cache entry */
1429
128k
    H5C_t       *cache_ptr = NULL;    /* Pointer to the entry's associated metadata cache */
1430
128k
    herr_t       ret_value = SUCCEED; /* Return value */
1431
1432
128k
    FUNC_ENTER_NOAPI(FAIL)
1433
1434
    /* Sanity check */
1435
128k
    assert(thing);
1436
1437
128k
    entry_ptr = (H5AC_info_t *)thing;
1438
128k
    cache_ptr = entry_ptr->cache_ptr;
1439
128k
    assert(cache_ptr);
1440
1441
    /* Unpin the entry */
1442
128k
    if (H5C_unpin_entry(thing) < 0)
1443
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPIN, FAIL, "can't unpin entry");
1444
1445
128k
done:
1446
    /* If currently logging, generate a message */
1447
128k
    if (cache_ptr != NULL && cache_ptr->log_info != NULL)
1448
128k
        if (cache_ptr->log_info->logging)
1449
0
            if (H5C_log_write_unpin_entry_msg(cache_ptr, entry_ptr, ret_value) < 0)
1450
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
1451
1452
128k
    FUNC_LEAVE_NOAPI(ret_value)
1453
128k
} /* H5AC_unpin_entry() */
1454
1455
/*-------------------------------------------------------------------------
1456
 * Function:    H5AC_destroy_flush_dependency()
1457
 *
1458
 * Purpose:     Destroy a flush dependency between two entries.
1459
 *
1460
 * Return:      Non-negative on success/Negative on failure
1461
 *
1462
 *-------------------------------------------------------------------------
1463
 */
1464
herr_t
1465
H5AC_destroy_flush_dependency(void *parent_thing, void *child_thing)
1466
0
{
1467
0
    H5AC_info_t *entry_ptr = NULL;    /* Pointer to the cache entry */
1468
0
    H5C_t       *cache_ptr = NULL;    /* Pointer to the entry's associated metadata cache */
1469
0
    herr_t       ret_value = SUCCEED; /* Return value */
1470
1471
0
    FUNC_ENTER_NOAPI(FAIL)
1472
1473
    /* Sanity check */
1474
0
    assert(parent_thing);
1475
0
    assert(child_thing);
1476
1477
0
    entry_ptr = (H5AC_info_t *)parent_thing;
1478
0
    cache_ptr = entry_ptr->cache_ptr;
1479
0
    assert(cache_ptr);
1480
1481
    /* Destroy the flush dependency */
1482
0
    if (H5C_destroy_flush_dependency(parent_thing, child_thing) < 0)
1483
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTUNDEPEND, FAIL, "H5C_destroy_flush_dependency() failed");
1484
1485
0
done:
1486
    /* If currently logging, generate a message */
1487
0
    if (cache_ptr != NULL && cache_ptr->log_info != NULL)
1488
0
        if (cache_ptr->log_info->logging)
1489
0
            if (H5C_log_write_destroy_fd_msg(cache_ptr, (H5AC_info_t *)parent_thing,
1490
0
                                             (H5AC_info_t *)child_thing, ret_value) < 0)
1491
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
1492
1493
0
    FUNC_LEAVE_NOAPI(ret_value)
1494
0
} /* H5AC_destroy_flush_dependency() */
1495
1496
/*-------------------------------------------------------------------------
1497
 * Function:    H5AC_unprotect
1498
 *
1499
 * Purpose:     Undo an H5AC_protect() call -- specifically, mark the
1500
 *              entry as unprotected, remove it from the protected list,
1501
 *              and give it back to the replacement policy.
1502
 *
1503
 *              The TYPE and ADDR arguments must be the same as those in
1504
 *              the corresponding call to H5AC_protect() and the THING
1505
 *              argument must be the value returned by that call to
1506
 *              H5AC_protect().
1507
 *
1508
 *              If the deleted flag is true, simply remove the target entry
1509
 *              from the cache, clear it, and free it without writing it to
1510
 *              disk.
1511
 *
1512
 *              This version of the function is a complete re-write to
1513
 *              use the new metadata cache.  While there isn't all that
1514
 *              much difference between the old and new Purpose sections,
1515
 *              the original version is given below.
1516
 *
1517
 *              Original purpose section:
1518
 *
1519
 *              This function should be called to undo the effect of
1520
 *              H5AC_protect().  The TYPE and ADDR arguments should be the
1521
 *              same as the corresponding call to H5AC_protect() and the
1522
 *              THING argument should be the value returned by H5AC_protect().
1523
 *              If the DELETED flag is set, then this object has been deleted
1524
 *              from the file and should not be returned to the cache.
1525
 *
1526
 * Return:      Non-negative on success/Negative on failure
1527
 *
1528
 *-------------------------------------------------------------------------
1529
 */
1530
herr_t
1531
H5AC_unprotect(H5F_t *f, const H5AC_class_t *type, haddr_t addr, void *thing, unsigned flags)
1532
2.19M
{
1533
2.19M
    bool dirtied;
1534
2.19M
    bool deleted;
1535
#ifdef H5_HAVE_PARALLEL
1536
    H5AC_aux_t *aux_ptr = NULL;
1537
#endif                          /* H5_HAVE_PARALLEL */
1538
2.19M
    herr_t ret_value = SUCCEED; /* Return value */
1539
1540
2.19M
    FUNC_ENTER_NOAPI(FAIL)
1541
1542
    /* Sanity checks */
1543
2.19M
    assert(f);
1544
2.19M
    assert(f->shared);
1545
2.19M
    assert(f->shared->cache);
1546
2.19M
    assert(type);
1547
2.19M
    assert(type->deserialize);
1548
2.19M
    assert(type->image_len);
1549
2.19M
    assert(H5_addr_defined(addr));
1550
2.19M
    assert(thing);
1551
2.19M
    assert(((H5AC_info_t *)thing)->addr == addr);
1552
2.19M
    assert(((H5AC_info_t *)thing)->type == type);
1553
1554
2.19M
    dirtied =
1555
2.19M
        (bool)(((flags & H5AC__DIRTIED_FLAG) == H5AC__DIRTIED_FLAG) || (((H5AC_info_t *)thing)->dirtied));
1556
2.19M
    deleted = (bool)((flags & H5C__DELETED_FLAG) == H5C__DELETED_FLAG);
1557
1558
    /* Check if the size changed out from underneath us, if we're not deleting
1559
     *  the entry.
1560
     */
1561
2.19M
    if (dirtied && !deleted) {
1562
0
        size_t curr_size = 0;
1563
1564
0
        if ((type->image_len)(thing, &curr_size) < 0)
1565
0
            HGOTO_ERROR(H5E_CACHE, H5E_CANTGETSIZE, FAIL, "Can't get size of thing");
1566
1567
0
        if (((H5AC_info_t *)thing)->size != curr_size)
1568
0
            HGOTO_ERROR(H5E_CACHE, H5E_BADSIZE, FAIL, "size of entry changed");
1569
0
    } /* end if */
1570
1571
#ifdef H5_HAVE_PARALLEL
1572
    if (NULL != (aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(f->shared->cache))) {
1573
        if (dirtied && ((H5AC_info_t *)thing)->is_dirty == false)
1574
            if (H5AC__log_dirtied_entry((H5AC_info_t *)thing) < 0)
1575
                HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "can't log dirtied entry");
1576
1577
        if (deleted && aux_ptr->mpi_rank == 0) {
1578
            if (H5AC__log_deleted_entry((H5AC_info_t *)thing) < 0) {
1579
                /* If we fail to log the deleted entry, push an error but still
1580
                 * participate in a possible sync point ahead
1581
                 */
1582
                HDONE_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "H5AC__log_deleted_entry() failed");
1583
            }
1584
        }
1585
    }  /* end if */
1586
#endif /* H5_HAVE_PARALLEL */
1587
1588
2.19M
    if (H5C_unprotect(f, addr, thing, flags) < 0)
1589
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTUNPROTECT, FAIL, "H5C_unprotect() failed");
1590
1591
#ifdef H5_HAVE_PARALLEL
1592
    /* Check if we should try to flush */
1593
    if ((aux_ptr != NULL) && (aux_ptr->dirty_bytes >= aux_ptr->dirty_bytes_threshold))
1594
        if (H5AC__run_sync_point(f, H5AC_SYNC_POINT_OP__FLUSH_TO_MIN_CLEAN) < 0)
1595
            HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Can't run sync point");
1596
#endif /* H5_HAVE_PARALLEL */
1597
1598
2.19M
done:
1599
    /* If currently logging, generate a message */
1600
2.19M
    if (f->shared->cache->log_info->logging)
1601
0
        if (H5C_log_write_unprotect_entry_msg(f->shared->cache, addr, type->id, flags, ret_value) < 0)
1602
0
            HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
1603
1604
2.19M
    FUNC_LEAVE_NOAPI(ret_value)
1605
2.19M
} /* H5AC_unprotect() */
1606
1607
/*-------------------------------------------------------------------------
1608
 * Function:    H5AC_get_cache_auto_resize_config
1609
 *
1610
 * Purpose:     Wrapper function for H5C_get_cache_auto_resize_config().
1611
 *
1612
 * Return:      SUCCEED on success, and FAIL on failure.
1613
 *
1614
 *-------------------------------------------------------------------------
1615
 */
1616
herr_t
1617
H5AC_get_cache_auto_resize_config(const H5AC_t *cache_ptr, H5AC_cache_config_t *config_ptr)
1618
0
{
1619
0
    H5C_auto_size_ctl_t internal_config;
1620
0
    bool                evictions_enabled;
1621
0
    herr_t              ret_value = SUCCEED; /* Return value */
1622
1623
0
    FUNC_ENTER_NOAPI(FAIL)
1624
1625
    /* Check args */
1626
0
    if ((cache_ptr == NULL) || (config_ptr == NULL) ||
1627
0
        (config_ptr->version != H5AC__CURR_CACHE_CONFIG_VERSION))
1628
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad cache_ptr or config_ptr on entry");
1629
1630
    /* Retrieve the configuration */
1631
0
    if (H5C_get_cache_auto_resize_config((const H5C_t *)cache_ptr, &internal_config) < 0)
1632
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_get_cache_auto_resize_config() failed");
1633
0
    if (H5C_get_evictions_enabled((const H5C_t *)cache_ptr, &evictions_enabled) < 0)
1634
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_get_resize_enabled() failed");
1635
1636
    /* Set the information to return */
1637
0
    if (internal_config.rpt_fcn == NULL)
1638
0
        config_ptr->rpt_fcn_enabled = false;
1639
0
    else
1640
0
        config_ptr->rpt_fcn_enabled = true;
1641
0
    config_ptr->open_trace_file        = false;
1642
0
    config_ptr->close_trace_file       = false;
1643
0
    config_ptr->trace_file_name[0]     = '\0';
1644
0
    config_ptr->evictions_enabled      = evictions_enabled;
1645
0
    config_ptr->set_initial_size       = internal_config.set_initial_size;
1646
0
    config_ptr->initial_size           = internal_config.initial_size;
1647
0
    config_ptr->min_clean_fraction     = internal_config.min_clean_fraction;
1648
0
    config_ptr->max_size               = internal_config.max_size;
1649
0
    config_ptr->min_size               = internal_config.min_size;
1650
0
    config_ptr->epoch_length           = (long)(internal_config.epoch_length);
1651
0
    config_ptr->incr_mode              = internal_config.incr_mode;
1652
0
    config_ptr->lower_hr_threshold     = internal_config.lower_hr_threshold;
1653
0
    config_ptr->increment              = internal_config.increment;
1654
0
    config_ptr->apply_max_increment    = internal_config.apply_max_increment;
1655
0
    config_ptr->max_increment          = internal_config.max_increment;
1656
0
    config_ptr->decr_mode              = internal_config.decr_mode;
1657
0
    config_ptr->upper_hr_threshold     = internal_config.upper_hr_threshold;
1658
0
    config_ptr->flash_incr_mode        = internal_config.flash_incr_mode;
1659
0
    config_ptr->flash_multiple         = internal_config.flash_multiple;
1660
0
    config_ptr->flash_threshold        = internal_config.flash_threshold;
1661
0
    config_ptr->decrement              = internal_config.decrement;
1662
0
    config_ptr->apply_max_decrement    = internal_config.apply_max_decrement;
1663
0
    config_ptr->max_decrement          = internal_config.max_decrement;
1664
0
    config_ptr->epochs_before_eviction = (int)(internal_config.epochs_before_eviction);
1665
0
    config_ptr->apply_empty_reserve    = internal_config.apply_empty_reserve;
1666
0
    config_ptr->empty_reserve          = internal_config.empty_reserve;
1667
#ifdef H5_HAVE_PARALLEL
1668
    {
1669
        H5AC_aux_t *aux_ptr;
1670
1671
        if (NULL != (aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr))) {
1672
            config_ptr->dirty_bytes_threshold   = aux_ptr->dirty_bytes_threshold;
1673
            config_ptr->metadata_write_strategy = aux_ptr->metadata_write_strategy;
1674
        } /* end if */
1675
        else {
1676
#endif /* H5_HAVE_PARALLEL */
1677
0
            config_ptr->dirty_bytes_threshold   = H5AC__DEFAULT_DIRTY_BYTES_THRESHOLD;
1678
0
            config_ptr->metadata_write_strategy = H5AC__DEFAULT_METADATA_WRITE_STRATEGY;
1679
#ifdef H5_HAVE_PARALLEL
1680
        } /* end else */
1681
    }
1682
#endif /* H5_HAVE_PARALLEL */
1683
1684
0
done:
1685
0
    FUNC_LEAVE_NOAPI(ret_value)
1686
0
} /* H5AC_get_cache_auto_resize_config() */
1687
1688
/*-------------------------------------------------------------------------
1689
 * Function:    H5AC_get_cache_size
1690
 *
1691
 * Purpose:     Wrapper function for H5C_get_cache_size().
1692
 *
1693
 * Return:      SUCCEED on success, and FAIL on failure.
1694
 *
1695
 *-------------------------------------------------------------------------
1696
 */
1697
herr_t
1698
H5AC_get_cache_size(const H5AC_t *cache_ptr, size_t *max_size_ptr, size_t *min_clean_size_ptr,
1699
                    size_t *cur_size_ptr, uint32_t *cur_num_entries_ptr)
1700
0
{
1701
0
    herr_t ret_value = SUCCEED; /* Return value */
1702
1703
0
    FUNC_ENTER_NOAPI(FAIL)
1704
1705
0
    if (H5C_get_cache_size((const H5C_t *)cache_ptr, max_size_ptr, min_clean_size_ptr, cur_size_ptr,
1706
0
                           cur_num_entries_ptr) < 0)
1707
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_get_cache_size() failed");
1708
1709
0
done:
1710
0
    FUNC_LEAVE_NOAPI(ret_value)
1711
0
} /* H5AC_get_cache_size() */
1712
1713
/*-------------------------------------------------------------------------
1714
 * Function:    H5AC_get_cache_flush_in_progess
1715
 *
1716
 * Purpose:     Wrapper function for H5C_get_cache_flush_in_progress().
1717
 *
1718
 * Return:      SUCCEED on success, and FAIL on failure.
1719
 *
1720
 *-------------------------------------------------------------------------
1721
 */
1722
herr_t
1723
H5AC_get_cache_flush_in_progress(H5AC_t *cache_ptr, bool *flush_in_progress_ptr)
1724
0
{
1725
0
    herr_t ret_value = SUCCEED; /* Return value */
1726
1727
0
    FUNC_ENTER_NOAPI(FAIL)
1728
1729
0
    if (H5C_get_cache_flush_in_progress((H5C_t *)cache_ptr, flush_in_progress_ptr) < 0)
1730
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_get_cache_flush_in_progress() failed");
1731
1732
0
done:
1733
0
    FUNC_LEAVE_NOAPI(ret_value)
1734
0
} /* H5AC_get_cache_flush_in_progress() */
1735
1736
/*-------------------------------------------------------------------------
1737
 * Function:    H5AC_get_cache_hit_rate
1738
 *
1739
 * Purpose:     Wrapper function for H5C_get_cache_hit_rate().
1740
 *
1741
 * Return:      SUCCEED on success, and FAIL on failure.
1742
 *
1743
 *-------------------------------------------------------------------------
1744
 */
1745
herr_t
1746
H5AC_get_cache_hit_rate(const H5AC_t *cache_ptr, double *hit_rate_ptr)
1747
0
{
1748
0
    herr_t ret_value = SUCCEED; /* Return value */
1749
1750
0
    FUNC_ENTER_NOAPI(FAIL)
1751
1752
0
    if (H5C_get_cache_hit_rate((const H5C_t *)cache_ptr, hit_rate_ptr) < 0)
1753
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_get_cache_hit_rate() failed");
1754
1755
0
done:
1756
0
    FUNC_LEAVE_NOAPI(ret_value)
1757
0
} /* H5AC_get_cache_hit_rate() */
1758
1759
/*-------------------------------------------------------------------------
1760
 *
1761
 * Function:    H5AC_reset_cache_hit_rate_stats()
1762
 *
1763
 * Purpose:     Wrapper function for H5C_reset_cache_hit_rate_stats().
1764
 *
1765
 * Return:      SUCCEED on success, and FAIL on failure.
1766
 *
1767
 *-------------------------------------------------------------------------
1768
 */
1769
herr_t
1770
H5AC_reset_cache_hit_rate_stats(H5AC_t *cache_ptr)
1771
0
{
1772
0
    herr_t ret_value = SUCCEED; /* Return value */
1773
1774
0
    FUNC_ENTER_NOAPI(FAIL)
1775
1776
0
    if (H5C_reset_cache_hit_rate_stats((H5C_t *)cache_ptr) < 0)
1777
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_reset_cache_hit_rate_stats() failed");
1778
1779
0
done:
1780
0
    FUNC_LEAVE_NOAPI(ret_value)
1781
0
} /* H5AC_reset_cache_hit_rate_stats() */
1782
1783
/*-------------------------------------------------------------------------
1784
 * Function:    H5AC_set_cache_auto_resize_config
1785
 *
1786
 * Purpose:     Wrapper function for H5C_set_cache_auto_resize_config().
1787
 *
1788
 * Return:      SUCCEED on success, and FAIL on failure.
1789
 *
1790
 *-------------------------------------------------------------------------
1791
 */
1792
herr_t
1793
H5AC_set_cache_auto_resize_config(H5AC_t *cache_ptr, const H5AC_cache_config_t *config_ptr)
1794
3.83k
{
1795
3.83k
    H5C_auto_size_ctl_t internal_config;
1796
3.83k
    herr_t              ret_value = SUCCEED; /* Return value */
1797
1798
3.83k
    FUNC_ENTER_NOAPI(FAIL)
1799
1800
    /* Sanity checks */
1801
3.83k
    assert(cache_ptr);
1802
1803
3.83k
    if (cache_ptr == NULL)
1804
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "bad cache_ptr on entry");
1805
1806
    /* Validate external configuration */
1807
3.83k
    if (H5AC_validate_config(config_ptr) != SUCCEED)
1808
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Bad cache configuration");
1809
1810
    /* If the cache config struct is being used to control logging, perform
1811
     * the open/close operations. Note that this is the only place where the
1812
     * struct-based control opens and closes the log files so we also have
1813
     * to write start/stop messages.
1814
     */
1815
    /* close */
1816
3.83k
    if (config_ptr->close_trace_file)
1817
0
        if (H5C_log_tear_down((H5C_t *)cache_ptr) < 0)
1818
0
            HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "mdc logging tear-down failed");
1819
1820
    /* open */
1821
3.83k
    if (config_ptr->open_trace_file) {
1822
        /* Turn on metadata cache logging.
1823
         * This will be trace output until we create a special API call. JSON
1824
         * output is generated when logging is controlled by the H5P calls.
1825
         */
1826
0
        if (H5C_log_set_up((H5C_t *)cache_ptr, config_ptr->trace_file_name, H5C_LOG_STYLE_TRACE, true) < 0)
1827
0
            HGOTO_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "mdc logging setup failed");
1828
0
    }
1829
1830
    /* Convert external configuration to internal representation */
1831
3.83k
    if (H5AC__ext_config_2_int_config(config_ptr, &internal_config) < 0)
1832
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC__ext_config_2_int_config() failed");
1833
1834
    /* Set configuration */
1835
3.83k
    if (H5C_set_cache_auto_resize_config(cache_ptr, &internal_config) < 0)
1836
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_set_cache_auto_resize_config() failed");
1837
3.83k
    if (H5C_set_evictions_enabled(cache_ptr, config_ptr->evictions_enabled) < 0)
1838
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_set_evictions_enabled() failed");
1839
1840
#ifdef H5_HAVE_PARALLEL
1841
    {
1842
        H5AC_aux_t *aux_ptr;
1843
1844
        /* Set parallel configuration values */
1845
        /* (Which are only held in the H5AC layer -QAK) */
1846
        if (NULL != (aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(cache_ptr))) {
1847
            aux_ptr->dirty_bytes_threshold   = config_ptr->dirty_bytes_threshold;
1848
            aux_ptr->metadata_write_strategy = config_ptr->metadata_write_strategy;
1849
        } /* end if */
1850
    }
1851
#endif /* H5_HAVE_PARALLEL */
1852
1853
3.83k
done:
1854
    /* If currently logging, generate a message */
1855
3.83k
    if (cache_ptr->log_info->logging)
1856
0
        if (H5C_log_write_set_cache_config_msg(cache_ptr, config_ptr, ret_value) < 0)
1857
0
            HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
1858
1859
3.83k
    FUNC_LEAVE_NOAPI(ret_value)
1860
3.83k
} /* H5AC_set_cache_auto_resize_config() */
1861
1862
/*-------------------------------------------------------------------------
1863
 * Function:    H5AC_validate_config()
1864
 *
1865
 * Purpose:     Run a sanity check on the contents of the supplied
1866
 *              instance of H5AC_cache_config_t.
1867
 *
1868
 *              Do nothing and return SUCCEED if no errors are detected,
1869
 *              and flag an error and return FAIL otherwise.
1870
 *
1871
 *              At present, this function operates by packing the data
1872
 *              from the instance of H5AC_cache_config_t into an instance
1873
 *              of H5C_auto_size_ctl_t, and then calling
1874
 *              H5C_validate_resize_config().  As H5AC_cache_config_t and
1875
 *              H5C_auto_size_ctl_t diverge, we may have to change this.
1876
 *
1877
 * Return:      Non-negative on success/Negative on failure
1878
 *
1879
 *-------------------------------------------------------------------------
1880
 */
1881
herr_t
1882
H5AC_validate_config(const H5AC_cache_config_t *config_ptr)
1883
7.67k
{
1884
7.67k
    H5C_auto_size_ctl_t internal_config;
1885
7.67k
    herr_t              ret_value = SUCCEED; /* Return value */
1886
1887
7.67k
    FUNC_ENTER_NOAPI(FAIL)
1888
1889
    /* Check args */
1890
7.67k
    if (config_ptr == NULL)
1891
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "NULL config_ptr on entry");
1892
7.67k
    if (config_ptr->version != H5AC__CURR_CACHE_CONFIG_VERSION)
1893
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Unknown config version");
1894
1895
    /* don't bother to test trace_file_name unless open_trace_file is true */
1896
7.67k
    if (config_ptr->open_trace_file) {
1897
0
        size_t name_len;
1898
1899
        /* Can't really test the trace_file_name field without trying to
1900
         * open the file, so we will content ourselves with a couple of
1901
         * sanity checks on the length of the file name.
1902
         */
1903
0
        name_len = strlen(config_ptr->trace_file_name);
1904
0
        if (name_len == 0)
1905
0
            HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "config_ptr->trace_file_name is empty");
1906
0
        else if (name_len > H5AC__MAX_TRACE_FILE_NAME_LEN)
1907
0
            HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "config_ptr->trace_file_name too long");
1908
0
    } /* end if */
1909
1910
7.67k
    if ((config_ptr->evictions_enabled == false) &&
1911
0
        ((config_ptr->incr_mode != H5C_incr__off) || (config_ptr->flash_incr_mode != H5C_flash_incr__off) ||
1912
0
         (config_ptr->decr_mode != H5C_decr__off)))
1913
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Can't disable evictions while auto-resize is enabled");
1914
1915
7.67k
    if (config_ptr->dirty_bytes_threshold < H5AC__MIN_DIRTY_BYTES_THRESHOLD)
1916
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "dirty_bytes_threshold too small");
1917
7.67k
    else if (config_ptr->dirty_bytes_threshold > H5AC__MAX_DIRTY_BYTES_THRESHOLD)
1918
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "dirty_bytes_threshold too big");
1919
1920
7.67k
    if ((config_ptr->metadata_write_strategy != H5AC_METADATA_WRITE_STRATEGY__PROCESS_0_ONLY) &&
1921
7.67k
        (config_ptr->metadata_write_strategy != H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED))
1922
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "config_ptr->metadata_write_strategy out of range");
1923
1924
7.67k
    if (H5AC__ext_config_2_int_config(config_ptr, &internal_config) < 0)
1925
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5AC__ext_config_2_int_config() failed");
1926
1927
7.67k
    if (H5C_validate_resize_config(&internal_config, H5C_RESIZE_CFG__VALIDATE_ALL) < 0)
1928
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "error(s) in new config");
1929
1930
7.67k
done:
1931
7.67k
    FUNC_LEAVE_NOAPI(ret_value)
1932
7.67k
} /* H5AC_validate_config() */
1933
1934
/*-------------------------------------------------------------------------
1935
 * Function:    H5AC_validate_cache_image_config()
1936
 *
1937
 * Purpose:     Run a sanity check on the contents of the supplied
1938
 *              instance of H5AC_cache_image_config_t.
1939
 *
1940
 *              Do nothing and return SUCCEED if no errors are detected,
1941
 *              and flag an error and return FAIL otherwise.
1942
 *
1943
 *              At present, this function operates by packing the data
1944
 *              from the instance of H5AC_cache_image_config_t into an
1945
 *              instance of H5C_cache_image_ctl_t, and then calling
1946
 *              H5C_validate_cache_image_config().  If and when
1947
 *              H5AC_cache_image_config_t and H5C_cache_image_ctl_t
1948
 *              diverge, we may have to change this.
1949
 *
1950
 * Return:      Non-negative on success/Negative on failure
1951
 *
1952
 *-------------------------------------------------------------------------
1953
 */
1954
herr_t
1955
H5AC_validate_cache_image_config(H5AC_cache_image_config_t *config_ptr)
1956
3.83k
{
1957
3.83k
    H5C_cache_image_ctl_t internal_config = H5C__DEFAULT_CACHE_IMAGE_CTL;
1958
3.83k
    herr_t                ret_value       = SUCCEED; /* Return value */
1959
1960
3.83k
    FUNC_ENTER_NOAPI(FAIL)
1961
1962
    /* Check args */
1963
3.83k
    if (config_ptr == NULL)
1964
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "NULL config_ptr on entry");
1965
1966
3.83k
    if (config_ptr->version != H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION)
1967
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "Unknown image config version");
1968
1969
    /* don't need to get the current H5C image config here since the
1970
     * default values of fields not in the H5AC config will always be
1971
     * valid.
1972
     */
1973
3.83k
    internal_config.version            = config_ptr->version;
1974
3.83k
    internal_config.generate_image     = config_ptr->generate_image;
1975
3.83k
    internal_config.save_resize_status = config_ptr->save_resize_status;
1976
3.83k
    internal_config.entry_ageout       = config_ptr->entry_ageout;
1977
1978
3.83k
    if (H5C_validate_cache_image_config(&internal_config) < 0)
1979
0
        HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "error(s) in new cache image config");
1980
1981
3.83k
done:
1982
3.83k
    FUNC_LEAVE_NOAPI(ret_value)
1983
3.83k
} /* H5AC_validate_cache_image_config() */
1984
1985
/*-------------------------------------------------------------------------
1986
 *
1987
 * Function:    H5AC__check_if_write_permitted
1988
 *
1989
 * Purpose:     Determine if a write is permitted under the current
1990
 *              circumstances, and set *write_permitted_ptr accordingly.
1991
 *              As a general rule it is, but when we are running in parallel
1992
 *              mode with collective I/O, we must ensure that a read cannot
1993
 *              cause a write.
1994
 *
1995
 *              In the event of failure, the value of *write_permitted_ptr
1996
 *              is undefined.
1997
 *
1998
 * Return:      Non-negative on success/Negative on failure.
1999
 *
2000
 *-------------------------------------------------------------------------
2001
 */
2002
static herr_t
2003
H5AC__check_if_write_permitted(const H5F_t
2004
#ifndef H5_HAVE_PARALLEL
2005
                                   H5_ATTR_UNUSED
2006
#endif /* H5_HAVE_PARALLEL */
2007
                                       *f,
2008
                               bool    *write_permitted_ptr)
2009
11.0k
{
2010
#ifdef H5_HAVE_PARALLEL
2011
    H5AC_aux_t *aux_ptr = NULL;
2012
#endif /* H5_HAVE_PARALLEL */
2013
11.0k
    bool write_permitted = true;
2014
2015
11.0k
    FUNC_ENTER_PACKAGE_NOERR
2016
2017
#ifdef H5_HAVE_PARALLEL
2018
    /* Sanity checks */
2019
    assert(f != NULL);
2020
    assert(f->shared != NULL);
2021
    assert(f->shared->cache != NULL);
2022
    aux_ptr = (H5AC_aux_t *)H5C_get_aux_ptr(f->shared->cache);
2023
    if (aux_ptr != NULL) {
2024
        if ((aux_ptr->mpi_rank == 0) ||
2025
            (aux_ptr->metadata_write_strategy == H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED))
2026
            write_permitted = aux_ptr->write_permitted;
2027
        else
2028
            write_permitted = false;
2029
    }  /* end if */
2030
#endif /* H5_HAVE_PARALLEL */
2031
2032
11.0k
    *write_permitted_ptr = write_permitted;
2033
2034
11.0k
    FUNC_LEAVE_NOAPI(SUCCEED)
2035
11.0k
} /* H5AC__check_if_write_permitted() */
2036
2037
/*-------------------------------------------------------------------------
2038
 * Function:    H5AC__ext_config_2_int_config()
2039
 *
2040
 * Purpose:     Utility function to translate an instance of
2041
 *              H5AC_cache_config_t to an instance of H5C_auto_size_ctl_t.
2042
 *
2043
 *              Places translation in *int_conf_ptr and returns SUCCEED
2044
 *              if successful.  Returns FAIL on failure.
2045
 *
2046
 *              Does only minimal sanity checking.
2047
 *
2048
 * Return:      Non-negative on success/Negative on failure
2049
 *
2050
 *-------------------------------------------------------------------------
2051
 */
2052
static herr_t
2053
H5AC__ext_config_2_int_config(const H5AC_cache_config_t *ext_conf_ptr, H5C_auto_size_ctl_t *int_conf_ptr)
2054
11.5k
{
2055
11.5k
    herr_t ret_value = SUCCEED; /* Return value */
2056
2057
11.5k
    FUNC_ENTER_PACKAGE
2058
2059
11.5k
    if ((ext_conf_ptr == NULL) || (ext_conf_ptr->version != H5AC__CURR_CACHE_CONFIG_VERSION) ||
2060
11.5k
        (int_conf_ptr == NULL))
2061
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad ext_conf_ptr or inf_conf_ptr on entry");
2062
2063
11.5k
    int_conf_ptr->version = H5C__CURR_AUTO_SIZE_CTL_VER;
2064
11.5k
    if (ext_conf_ptr->rpt_fcn_enabled)
2065
0
        int_conf_ptr->rpt_fcn = H5C_def_auto_resize_rpt_fcn;
2066
11.5k
    else
2067
11.5k
        int_conf_ptr->rpt_fcn = NULL;
2068
2069
11.5k
    int_conf_ptr->set_initial_size   = ext_conf_ptr->set_initial_size;
2070
11.5k
    int_conf_ptr->initial_size       = ext_conf_ptr->initial_size;
2071
11.5k
    int_conf_ptr->min_clean_fraction = ext_conf_ptr->min_clean_fraction;
2072
11.5k
    int_conf_ptr->max_size           = ext_conf_ptr->max_size;
2073
11.5k
    int_conf_ptr->min_size           = ext_conf_ptr->min_size;
2074
11.5k
    int_conf_ptr->epoch_length       = (int64_t)(ext_conf_ptr->epoch_length);
2075
2076
11.5k
    int_conf_ptr->incr_mode           = ext_conf_ptr->incr_mode;
2077
11.5k
    int_conf_ptr->lower_hr_threshold  = ext_conf_ptr->lower_hr_threshold;
2078
11.5k
    int_conf_ptr->increment           = ext_conf_ptr->increment;
2079
11.5k
    int_conf_ptr->apply_max_increment = ext_conf_ptr->apply_max_increment;
2080
11.5k
    int_conf_ptr->max_increment       = ext_conf_ptr->max_increment;
2081
11.5k
    int_conf_ptr->flash_incr_mode     = ext_conf_ptr->flash_incr_mode;
2082
11.5k
    int_conf_ptr->flash_multiple      = ext_conf_ptr->flash_multiple;
2083
11.5k
    int_conf_ptr->flash_threshold     = ext_conf_ptr->flash_threshold;
2084
2085
11.5k
    int_conf_ptr->decr_mode              = ext_conf_ptr->decr_mode;
2086
11.5k
    int_conf_ptr->upper_hr_threshold     = ext_conf_ptr->upper_hr_threshold;
2087
11.5k
    int_conf_ptr->decrement              = ext_conf_ptr->decrement;
2088
11.5k
    int_conf_ptr->apply_max_decrement    = ext_conf_ptr->apply_max_decrement;
2089
11.5k
    int_conf_ptr->max_decrement          = ext_conf_ptr->max_decrement;
2090
11.5k
    int_conf_ptr->epochs_before_eviction = (int32_t)(ext_conf_ptr->epochs_before_eviction);
2091
11.5k
    int_conf_ptr->apply_empty_reserve    = ext_conf_ptr->apply_empty_reserve;
2092
11.5k
    int_conf_ptr->empty_reserve          = ext_conf_ptr->empty_reserve;
2093
2094
11.5k
done:
2095
11.5k
    FUNC_LEAVE_NOAPI(ret_value)
2096
11.5k
} /* H5AC__ext_config_2_int_config() */
2097
2098
/*------------------------------------------------------------------------------
2099
 * Function:    H5AC_ignore_tags()
2100
 *
2101
 * Purpose:     Override all assertion frameworks and force application of
2102
 *              global tag everywhere. This should really only be used in the
2103
 *              tests that need to access functions without going through
2104
 *              API paths.
2105
 *
2106
 * Return:      SUCCEED on success, FAIL otherwise.
2107
 *
2108
 *------------------------------------------------------------------------------
2109
 */
2110
herr_t
2111
H5AC_ignore_tags(const H5F_t *f)
2112
0
{
2113
0
    herr_t ret_value = SUCCEED;
2114
2115
0
    FUNC_ENTER_NOAPI(FAIL)
2116
2117
    /* Sanity checks */
2118
0
    assert(f);
2119
0
    assert(f->shared);
2120
0
    assert(f->shared->cache);
2121
2122
    /* Set up a new metadata tag */
2123
0
    if (H5C_ignore_tags(f->shared->cache) < 0)
2124
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTSET, FAIL, "H5C_ignore_tags() failed");
2125
2126
0
done:
2127
0
    FUNC_LEAVE_NOAPI(ret_value)
2128
0
} /* H5AC_ignore_tags() */
2129
2130
/*------------------------------------------------------------------------------
2131
 * Function:    H5AC_tag()
2132
 *
2133
 * Purpose:     Sets the metadata tag property in the provided property list.
2134
 *
2135
 * Return:      void
2136
 *
2137
 *------------------------------------------------------------------------------
2138
 */
2139
void
2140
H5AC_tag(haddr_t metadata_tag, haddr_t *prev_tag)
2141
7.46M
{
2142
7.46M
    FUNC_ENTER_NOAPI_NOINIT_NOERR
2143
2144
    /* Get the current tag value and return that (if prev_tag is NOT null) */
2145
7.46M
    if (prev_tag)
2146
3.73M
        *prev_tag = H5CX_get_tag();
2147
2148
    /* Set the provided tag */
2149
7.46M
    H5CX_set_tag(metadata_tag);
2150
2151
7.46M
    FUNC_LEAVE_NOAPI_VOID
2152
7.46M
} /* H5AC_tag */
2153
2154
/*------------------------------------------------------------------------------
2155
 * Function:    H5AC_retag_copied_metadata()
2156
 *
2157
 * Purpose:     Searches through cache index for all entries with the
2158
 *              H5AC__COPIED_TAG, indicating that it was created as a
2159
 *              result of an object copy, and applies the provided tag.
2160
 *
2161
 * Return:      SUCCEED on success, FAIL otherwise.
2162
 *
2163
 *------------------------------------------------------------------------------
2164
 */
2165
herr_t
2166
H5AC_retag_copied_metadata(const H5F_t *f, haddr_t metadata_tag)
2167
0
{
2168
0
    herr_t ret_value = SUCCEED; /* Return value */
2169
2170
0
    FUNC_ENTER_NOAPI(FAIL)
2171
2172
    /* Sanity checks */
2173
0
    assert(f);
2174
0
    assert(f->shared);
2175
2176
    /* Call cache-level function to re-tag entries with the COPIED tag */
2177
0
    if (H5C_retag_entries(f->shared->cache, H5AC__COPIED_TAG, metadata_tag) < 0)
2178
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTSET, FAIL, "Can't retag metadata");
2179
2180
0
done:
2181
0
    FUNC_LEAVE_NOAPI(ret_value)
2182
0
} /* H5AC_retag_copied_metadata() */
2183
2184
/*------------------------------------------------------------------------------
2185
 * Function:    H5AC_flush_tagged_metadata()
2186
 *
2187
 * Purpose:     Wrapper for cache level function which flushes all metadata
2188
 *              that contains the specific tag.
2189
 *
2190
 * Return:      SUCCEED on success, FAIL otherwise.
2191
 *
2192
 *------------------------------------------------------------------------------
2193
 */
2194
herr_t
2195
H5AC_flush_tagged_metadata(H5F_t *f, haddr_t metadata_tag)
2196
0
{
2197
    /* Variable Declarations */
2198
0
    herr_t ret_value = SUCCEED;
2199
2200
    /* Function Enter Macro */
2201
0
    FUNC_ENTER_NOAPI(FAIL)
2202
2203
    /* Assertions */
2204
0
    assert(f);
2205
0
    assert(f->shared);
2206
2207
    /* Call cache level function to flush metadata entries with specified tag */
2208
0
    if (H5C_flush_tagged_entries(f, metadata_tag) < 0)
2209
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Cannot flush metadata");
2210
2211
0
done:
2212
0
    FUNC_LEAVE_NOAPI(ret_value)
2213
0
} /* H5AC_flush_tagged_metadata */
2214
2215
/*------------------------------------------------------------------------------
2216
 * Function:    H5AC_evict_tagged_metadata()
2217
 *
2218
 * Purpose:     Wrapper for cache level function which evicts all metadata
2219
 *              that contains the specific tag.
2220
 *
2221
 *              The match_global parameter determines if the global file
2222
 *              data (e.g., global heaps, shared object header messages)
2223
 *              should be checked. This is false when closing objects
2224
 *              and true when flushing.
2225
 *
2226
 * Return:      SUCCEED on success, FAIL otherwise.
2227
 *------------------------------------------------------------------------------
2228
 */
2229
herr_t
2230
H5AC_evict_tagged_metadata(H5F_t *f, haddr_t metadata_tag, bool match_global)
2231
0
{
2232
    /* Variable Declarations */
2233
0
    herr_t ret_value = SUCCEED;
2234
2235
    /* Function Enter Macro */
2236
0
    FUNC_ENTER_NOAPI(FAIL)
2237
2238
    /* Assertions */
2239
0
    assert(f);
2240
0
    assert(f->shared);
2241
2242
    /* Call cache level function to evict metadata entries with specified tag */
2243
0
    if (H5C_evict_tagged_entries(f, metadata_tag, match_global) < 0)
2244
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Cannot evict metadata");
2245
2246
0
done:
2247
0
    FUNC_LEAVE_NOAPI(ret_value)
2248
0
} /* H5AC_evict_tagged_metadata() */
2249
2250
/*------------------------------------------------------------------------------
2251
 * Function:    H5AC_expunge_tag_type_metadata()
2252
 *
2253
 * Purpose:     Wrapper for cache level function which expunges entries with
2254
 *              a specific tag and type id.
2255
 *
2256
 * Return:      SUCCEED on success, FAIL otherwise.
2257
 *
2258
 *------------------------------------------------------------------------------
2259
 */
2260
herr_t
2261
H5AC_expunge_tag_type_metadata(H5F_t *f, haddr_t tag, int type_id, unsigned flags)
2262
0
{
2263
    /* Variable Declarations */
2264
0
    herr_t ret_value = SUCCEED;
2265
2266
    /* Function Enter Macro */
2267
0
    FUNC_ENTER_NOAPI(FAIL)
2268
2269
    /* Assertions */
2270
0
    assert(f);
2271
0
    assert(f->shared);
2272
2273
    /* Call cache level function to expunge entries with specified tag and type id */
2274
0
    if (H5C_expunge_tag_type_metadata(f, tag, type_id, flags) < 0)
2275
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTFLUSH, FAIL, "Cannot expunge tagged type entries");
2276
2277
0
done:
2278
0
    FUNC_LEAVE_NOAPI(ret_value)
2279
0
} /* H5AC_expunge_tag_type_metadata*/
2280
2281
/*------------------------------------------------------------------------------
2282
 * Function:    H5AC_get_tag()
2283
 *
2284
 * Purpose:     Get the tag for a metadata cache entry.
2285
 *
2286
 * Return:      SUCCEED/FAIL
2287
 *
2288
 *------------------------------------------------------------------------------
2289
 */
2290
herr_t
2291
H5AC_get_tag(const void *thing, haddr_t *tag)
2292
0
{
2293
    /* Variable Declarations */
2294
0
    herr_t ret_value = SUCCEED;
2295
2296
    /* Function Enter Macro */
2297
0
    FUNC_ENTER_NOAPI(FAIL)
2298
2299
    /* Assertions */
2300
0
    assert(thing);
2301
0
    assert(tag);
2302
2303
    /* Call cache level function to get the tag */
2304
0
    if (H5C_get_tag(thing, tag) < 0)
2305
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTTAG, FAIL, "Cannot get tag for metadata cache entry");
2306
2307
0
done:
2308
0
    FUNC_LEAVE_NOAPI(ret_value)
2309
0
} /* end H5AC_get_tag() */
2310
2311
/*-------------------------------------------------------------------------
2312
 * Function:    H5AC_cork
2313
 *
2314
 * Purpose:     To cork/uncork/get cork status for an object
2315
 *
2316
 * Return:      Non-negative on success/Negative on failure
2317
 *
2318
 *-------------------------------------------------------------------------
2319
 */
2320
herr_t
2321
H5AC_cork(H5F_t *f, haddr_t obj_addr, unsigned action, bool *corked)
2322
92.9k
{
2323
92.9k
    herr_t ret_value = SUCCEED; /* Return value */
2324
2325
92.9k
    FUNC_ENTER_NOAPI(FAIL)
2326
2327
    /* Sanity check */
2328
92.9k
    assert(f);
2329
92.9k
    assert(f->shared);
2330
92.9k
    assert(f->shared->cache);
2331
92.9k
    assert(H5_addr_defined(obj_addr));
2332
92.9k
    assert(action == H5AC__SET_CORK || action == H5AC__UNCORK || action == H5AC__GET_CORKED);
2333
2334
    /*  Skip the search on "tag_list" when there are no "corked" objects.
2335
     *  This is done to mitigate the slow down when closing objects.
2336
     *  Re-visit this optimization when we optimize tag info management
2337
     *  in the future.
2338
     */
2339
92.9k
    if (action == H5AC__GET_CORKED) {
2340
92.9k
        assert(corked);
2341
92.9k
        if (H5C_get_num_objs_corked(f->shared->cache) == 0) {
2342
92.9k
            *corked = false;
2343
92.9k
            HGOTO_DONE(SUCCEED);
2344
92.9k
        }
2345
92.9k
    }
2346
2347
0
    if (H5C_cork(f->shared->cache, obj_addr, action, corked) < 0)
2348
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Cannot perform the cork action");
2349
2350
92.9k
done:
2351
92.9k
    FUNC_LEAVE_NOAPI(ret_value)
2352
92.9k
} /* H5AC_cork() */
2353
2354
#if H5AC_DO_TAGGING_SANITY_CHECKS
2355
2356
/*-------------------------------------------------------------------------
2357
 *
2358
 * Function:    H5AC__verify_tag
2359
 *
2360
 * Purpose:     Performs sanity checking on an entry type and tag value
2361
 *              stored in a supplied dxpl_id.
2362
 *
2363
 * Return:      SUCCEED or FAIL.
2364
 *
2365
 *-------------------------------------------------------------------------
2366
 */
2367
static herr_t
2368
H5AC__verify_tag(const H5AC_class_t *type)
2369
{
2370
    haddr_t tag;                 /* Entry tag to validate */
2371
    herr_t  ret_value = SUCCEED; /* Return value */
2372
2373
    FUNC_ENTER_PACKAGE
2374
2375
    /* Get the current tag */
2376
    tag = H5CX_get_tag();
2377
2378
    /* Verify legal tag value */
2379
    if (H5C_verify_tag(type->id, tag) < 0)
2380
        HGOTO_ERROR(H5E_CACHE, H5E_CANTGET, FAIL, "tag verification failed");
2381
2382
done:
2383
    FUNC_LEAVE_NOAPI(ret_value)
2384
} /* H5AC__verify_tag */
2385
#endif /* H5AC_DO_TAGGING_SANITY_CHECKS */
2386
2387
/*-------------------------------------------------------------------------
2388
 * Function:    H5AC_get_entry_ring
2389
 *
2390
 * Purpose:     Given a file address, retrieve the ring for an entry at that
2391
 *              address.
2392
 *
2393
 *              On error, the value of *ring is not modified.
2394
 *
2395
 * Return:      Non-negative on success/Negative on failure
2396
 *
2397
 *-------------------------------------------------------------------------
2398
 */
2399
herr_t
2400
H5AC_get_entry_ring(const H5F_t *f, haddr_t addr, H5AC_ring_t *ring)
2401
0
{
2402
0
    herr_t ret_value = SUCCEED; /* Return value */
2403
2404
0
    FUNC_ENTER_NOAPI(FAIL)
2405
2406
    /* Sanity check */
2407
0
    assert(f);
2408
0
    assert(H5_addr_defined(addr));
2409
0
    assert(ring);
2410
2411
    /* Retrieve the ring value for the entry at address */
2412
0
    if (H5C_get_entry_ring(f, addr, ring) < 0)
2413
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTGET, FAIL, "Can't retrieve ring for entry");
2414
2415
0
done:
2416
0
    FUNC_LEAVE_NOAPI(ret_value)
2417
0
} /* H5AC_get_entry_ring() */
2418
2419
/*-------------------------------------------------------------------------
2420
 * Function:    H5AC_set_ring
2421
 *
2422
 * Purpose:     Routine to set the ring on a DXPL (for passing through
2423
 *              to the metadata cache).
2424
 *
2425
 * Return:      void
2426
 *
2427
 *-------------------------------------------------------------------------
2428
 */
2429
void
2430
H5AC_set_ring(H5AC_ring_t ring, H5AC_ring_t *orig_ring)
2431
11.4k
{
2432
11.4k
    FUNC_ENTER_NOAPI_NOINIT_NOERR
2433
2434
    /* Note: orig_ring can be NULL so don't check it with assert() */
2435
2436
    /* Get the current ring value and return that (if orig_ring is NOT null) */
2437
11.4k
    if (orig_ring)
2438
3.81k
        *orig_ring = H5CX_get_ring();
2439
2440
    /* Set the provided ring */
2441
11.4k
    H5CX_set_ring(ring);
2442
2443
11.4k
    FUNC_LEAVE_NOAPI_VOID
2444
11.4k
} /* end H5AC_set_ring() */
2445
2446
/*-------------------------------------------------------------------------
2447
 * Function:    H5AC_unsettle_entry_ring()
2448
 *
2449
 * Purpose:     Advise the metadata cache that the specified entry's metadata
2450
 *              cache manager ring is no longer settled (if it was on entry).
2451
 *
2452
 *              If the target metadata cache manager ring is already
2453
 *              unsettled, do nothing, and return SUCCEED.
2454
 *
2455
 *              If the target metadata cache manager ring is settled, and
2456
 *              we are not in the process of a file shutdown, mark
2457
 *              the ring as unsettled, and return SUCCEED.
2458
 *
2459
 *              If the target metadata cache  manager is settled, and we
2460
 *              are in the process of a file shutdown, post an error
2461
 *              message, and return FAIL.
2462
 *
2463
 *              Note that this function simply passes the call on to
2464
 *              the metadata cache proper, and returns the result.
2465
 *
2466
 * Return:      Success:        Non-negative
2467
 *              Failure:        Negative
2468
 *
2469
 *-------------------------------------------------------------------------
2470
 */
2471
herr_t
2472
H5AC_unsettle_entry_ring(void *_entry)
2473
0
{
2474
0
    H5AC_info_t *entry     = (H5AC_info_t *)_entry; /* Entry to remove */
2475
0
    herr_t       ret_value = SUCCEED;               /* Return value */
2476
2477
0
    FUNC_ENTER_NOAPI(FAIL)
2478
2479
    /* Sanity checks */
2480
0
    assert(entry);
2481
2482
    /* Unsettle the entry's ring */
2483
0
    if (H5C_unsettle_entry_ring(entry) < 0)
2484
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTREMOVE, FAIL, "can't remove entry");
2485
2486
0
done:
2487
0
    FUNC_LEAVE_NOAPI(ret_value)
2488
0
} /* H5AC_unsettle_entry_ring() */
2489
2490
/*-------------------------------------------------------------------------
2491
 * Function:    H5AC_unsettle_ring()
2492
 *
2493
 * Purpose:     Advise the metadata cache that the specified free space
2494
 *              manager ring is no longer settled (if it was on entry).
2495
 *
2496
 *              If the target free space manager ring is already
2497
 *              unsettled, do nothing, and return SUCCEED.
2498
 *
2499
 *              If the target free space manager ring is settled, and
2500
 *              we are not in the process of a file shutdown, mark
2501
 *              the ring as unsettled, and return SUCCEED.
2502
 *
2503
 *              If the target free space manager is settled, and we
2504
 *              are in the process of a file shutdown, post an error
2505
 *              message, and return FAIL.
2506
 *
2507
 *              Note that this function simply passes the call on to
2508
 *              the metadata cache proper, and returns the result.
2509
 *
2510
 * Return:      Non-negative on success/Negative on failure
2511
 *
2512
 *-------------------------------------------------------------------------
2513
 */
2514
herr_t
2515
H5AC_unsettle_ring(H5F_t *f, H5C_ring_t ring)
2516
0
{
2517
0
    herr_t ret_value = SUCCEED; /* Return value */
2518
2519
0
    FUNC_ENTER_NOAPI(FAIL)
2520
2521
0
    if (FAIL == (ret_value = H5C_unsettle_ring(f, ring)))
2522
0
        HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "H5C_unsettle_ring() failed");
2523
2524
0
done:
2525
0
    FUNC_LEAVE_NOAPI(ret_value)
2526
0
} /* H5AC_unsettle_ring() */
2527
2528
/*-------------------------------------------------------------------------
2529
 * Function:    H5AC_remove_entry()
2530
 *
2531
 * Purpose:     Remove an entry from the cache.  Must be not protected, pinned,
2532
 *              dirty, involved in flush dependencies, etc.
2533
 *
2534
 * Return:      Non-negative on success/Negative on failure
2535
 *
2536
 *-------------------------------------------------------------------------
2537
 */
2538
herr_t
2539
H5AC_remove_entry(void *_entry)
2540
0
{
2541
0
    H5AC_info_t *entry     = (H5AC_info_t *)_entry; /* Entry to remove */
2542
0
    H5C_t       *cache     = NULL;                  /* Pointer to the entry's associated metadata cache */
2543
0
    herr_t       ret_value = SUCCEED;               /* Return value */
2544
2545
0
    FUNC_ENTER_NOAPI(FAIL)
2546
2547
    /* Sanity checks */
2548
0
    assert(entry);
2549
0
    cache = entry->cache_ptr;
2550
0
    assert(cache);
2551
2552
    /* Remove the entry from the cache*/
2553
0
    if (H5C_remove_entry(entry) < 0)
2554
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTREMOVE, FAIL, "can't remove entry");
2555
2556
0
done:
2557
    /* If currently logging, generate a message */
2558
0
    if (cache != NULL && cache->log_info != NULL)
2559
0
        if (cache->log_info->logging)
2560
0
            if (H5C_log_write_remove_entry_msg(cache, entry, ret_value) < 0)
2561
0
                HDONE_ERROR(H5E_CACHE, H5E_LOGGING, FAIL, "unable to emit log message");
2562
2563
0
    FUNC_LEAVE_NOAPI(ret_value)
2564
0
} /* H5AC_remove_entry() */
2565
2566
/*-------------------------------------------------------------------------
2567
 * Function:    H5AC_get_mdc_image_info
2568
 *
2569
 * Purpose:     Wrapper function for H5C_get_mdc_image_info().
2570
 *
2571
 * Return:      SUCCEED on success, and FAIL on failure.
2572
 *
2573
 *-------------------------------------------------------------------------
2574
 */
2575
herr_t
2576
H5AC_get_mdc_image_info(const H5AC_t *cache_ptr, haddr_t *image_addr, hsize_t *image_len)
2577
0
{
2578
0
    herr_t ret_value = SUCCEED; /* Return value */
2579
2580
0
    FUNC_ENTER_NOAPI(FAIL)
2581
2582
0
    if (H5C_get_mdc_image_info((const H5C_t *)cache_ptr, image_addr, image_len) < 0)
2583
0
        HGOTO_ERROR(H5E_CACHE, H5E_CANTGET, FAIL, "can't retrieve cache image info");
2584
2585
0
done:
2586
0
    FUNC_LEAVE_NOAPI(ret_value)
2587
0
} /* H5AC_get_mdc_image_info() */