]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/lib/blobfs/tree.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / lib / blobfs / tree.h
CommitLineData
7c673cae
FG
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
11fdf7f2
TL
34#ifndef SPDK_TREE_H_
35#define SPDK_TREE_H_
7c673cae 36
11fdf7f2
TL
37struct cache_buffer {
38 uint8_t *buf;
39 uint64_t offset;
40 uint32_t buf_size;
41 uint32_t bytes_filled;
42 uint32_t bytes_flushed;
43 bool in_progress;
44};
7c673cae 45
11fdf7f2 46extern uint32_t g_fs_cache_buffer_shift;
7c673cae 47
11fdf7f2
TL
48#define CACHE_BUFFER_SHIFT_DEFAULT 18
49#define CACHE_BUFFER_SIZE (1U << g_fs_cache_buffer_shift)
50#define NEXT_CACHE_BUFFER_OFFSET(offset) \
51 (((offset + CACHE_BUFFER_SIZE) >> g_fs_cache_buffer_shift) << g_fs_cache_buffer_shift)
7c673cae 52
11fdf7f2
TL
53#define CACHE_TREE_SHIFT 6
54#define CACHE_TREE_WIDTH (1U << CACHE_TREE_SHIFT)
55#define CACHE_TREE_LEVEL_SHIFT(level) (g_fs_cache_buffer_shift + (level) * CACHE_TREE_SHIFT)
56#define CACHE_TREE_LEVEL_SIZE(level) (1ULL << CACHE_TREE_LEVEL_SHIFT(level))
57#define CACHE_TREE_LEVEL_MASK(level) (CACHE_TREE_LEVEL_SIZE(level) - 1)
58#define CACHE_TREE_INDEX(level, offset) ((offset >> CACHE_TREE_LEVEL_SHIFT(level)) & (CACHE_TREE_WIDTH - 1))
7c673cae 59
11fdf7f2
TL
60struct cache_tree {
61 uint8_t level;
62 uint64_t present_mask;
63 union {
64 struct cache_buffer *buffer[CACHE_TREE_WIDTH];
65 struct cache_tree *tree[CACHE_TREE_WIDTH];
66 } u;
7c673cae
FG
67};
68
f67539c2 69void cache_buffer_free(struct cache_buffer *cache_buffer);
7c673cae 70
f67539c2
TL
71struct cache_tree *tree_insert_buffer(struct cache_tree *root, struct cache_buffer *buffer);
72void tree_free_buffers(struct cache_tree *tree);
73struct cache_buffer *tree_find_buffer(struct cache_tree *tree, uint64_t offset);
74struct cache_buffer *tree_find_filled_buffer(struct cache_tree *tree, uint64_t offset);
75void tree_remove_buffer(struct cache_tree *tree, struct cache_buffer *buffer);
7c673cae 76
11fdf7f2 77#endif /* SPDK_TREE_H_ */