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