xref: /linux/drivers/md/dm-vdo/indexer/index.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2023 Red Hat
4  */
5 
6 #ifndef UDS_INDEX_H
7 #define UDS_INDEX_H
8 
9 #include "index-layout.h"
10 #include "index-session.h"
11 #include "open-chapter.h"
12 #include "volume.h"
13 #include "volume-index.h"
14 
15 /*
16  * The index is a high-level structure which represents the totality of the UDS index. It manages
17  * the queues for incoming requests and dispatches them to the appropriate sub-components like the
18  * volume or the volume index. It also manages administrative tasks such as saving and loading the
19  * index.
20  *
21  * The index is divided into a number of independent zones and assigns each request to a zone based
22  * on its name. Most sub-components are similarly divided into zones as well so that requests in
23  * each zone usually operate without interference or coordination between zones.
24  */
25 
26 typedef void (*index_callback_fn)(struct uds_request *request);
27 
28 struct index_zone {
29 	struct uds_index *index;
30 	struct open_chapter_zone *open_chapter;
31 	struct open_chapter_zone *writing_chapter;
32 	u64 oldest_virtual_chapter;
33 	u64 newest_virtual_chapter;
34 	unsigned int id;
35 };
36 
37 struct uds_index {
38 	bool has_saved_open_chapter;
39 	bool need_to_save;
40 	struct index_load_context *load_context;
41 	struct index_layout *layout;
42 	struct volume_index *volume_index;
43 	struct volume *volume;
44 	unsigned int zone_count;
45 	struct index_zone **zones;
46 
47 	u64 oldest_virtual_chapter;
48 	u64 newest_virtual_chapter;
49 
50 	u64 last_save;
51 	u64 prev_save;
52 	struct chapter_writer *chapter_writer;
53 
54 	index_callback_fn callback;
55 	struct uds_request_queue *triage_queue;
56 	struct uds_request_queue *zone_queues[];
57 };
58 
59 enum request_stage {
60 	STAGE_TRIAGE,
61 	STAGE_INDEX,
62 	STAGE_MESSAGE,
63 };
64 
65 int __must_check uds_make_index(struct uds_configuration *config,
66 				enum uds_open_index_type open_type,
67 				struct index_load_context *load_context,
68 				index_callback_fn callback, struct uds_index **new_index);
69 
70 int __must_check uds_save_index(struct uds_index *index);
71 
72 void uds_free_index(struct uds_index *index);
73 
74 int __must_check uds_replace_index_storage(struct uds_index *index,
75 					   struct block_device *bdev);
76 
77 void uds_get_index_stats(struct uds_index *index, struct uds_index_stats *counters);
78 
79 void uds_enqueue_request(struct uds_request *request, enum request_stage stage);
80 
81 void uds_wait_for_idle_index(struct uds_index *index);
82 
83 #endif /* UDS_INDEX_H */
84