1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright 2023 Red Hat
4 */
5
6#ifndef UDS_SPARSE_CACHE_H
7#define UDS_SPARSE_CACHE_H
8
9#include "geometry.h"
10#include "indexer.h"
11
12/*
13 * The sparse cache is a cache of entire chapter indexes from sparse chapters used for searching
14 * for names after all other search paths have failed. It contains only complete chapter indexes;
15 * record pages from sparse chapters and single index pages used for resolving hooks are kept in
16 * the regular page cache in the volume.
17 *
18 * The most important property of this cache is the absence of synchronization for read operations.
19 * Safe concurrent access to the cache by the zone threads is controlled by the triage queue and
20 * the barrier requests it issues to the zone queues. The set of cached chapters does not and must
21 * not change between the carefully coordinated calls to uds_update_sparse_cache() from the zone
22 * threads. Outside of updates, every zone will get the same result when calling
23 * uds_sparse_cache_contains() as every other zone.
24 */
25
26struct index_zone;
27struct sparse_cache;
28
29int __must_check uds_make_sparse_cache(const struct index_geometry *geometry,
30				       unsigned int capacity, unsigned int zone_count,
31				       struct sparse_cache **cache_ptr);
32
33void uds_free_sparse_cache(struct sparse_cache *cache);
34
35bool uds_sparse_cache_contains(struct sparse_cache *cache, u64 virtual_chapter,
36			       unsigned int zone_number);
37
38int __must_check uds_update_sparse_cache(struct index_zone *zone, u64 virtual_chapter);
39
40void uds_invalidate_sparse_cache(struct sparse_cache *cache);
41
42int __must_check uds_search_sparse_cache(struct index_zone *zone,
43					 const struct uds_record_name *name,
44					 u64 *virtual_chapter_ptr, u16 *record_page_ptr);
45
46#endif /* UDS_SPARSE_CACHE_H */
47