1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright 2023 Red Hat 4 */ 5 6 #ifndef VDO_DEDUPE_H 7 #define VDO_DEDUPE_H 8 9 #include <linux/list.h> 10 #include <linux/timer.h> 11 12 #include "indexer.h" 13 14 #include "admin-state.h" 15 #include "constants.h" 16 #include "statistics.h" 17 #include "types.h" 18 #include "wait-queue.h" 19 20 struct dedupe_context { 21 struct hash_zone *zone; 22 struct uds_request request; 23 struct list_head list_entry; 24 struct funnel_queue_entry queue_entry; 25 u64 submission_jiffies; 26 struct data_vio *requestor; 27 atomic_t state; 28 }; 29 30 struct hash_lock; 31 32 struct hash_zone { 33 /* Which hash zone this is */ 34 zone_count_t zone_number; 35 36 /* The administrative state of the zone */ 37 struct admin_state state; 38 39 /* The thread ID for this zone */ 40 thread_id_t thread_id; 41 42 /* Mapping from record name fields to hash_locks */ 43 struct int_map *hash_lock_map; 44 45 /* List containing all unused hash_locks */ 46 struct list_head lock_pool; 47 48 /* 49 * Statistics shared by all hash locks in this zone. Only modified on the hash zone thread, 50 * but queried by other threads. 51 */ 52 struct hash_lock_statistics statistics; 53 54 /* Array of all hash_locks */ 55 struct hash_lock *lock_array; 56 57 /* These fields are used to manage the dedupe contexts */ 58 struct list_head available; 59 struct list_head pending; 60 struct funnel_queue *timed_out_complete; 61 struct timer_list timer; 62 struct vdo_completion completion; 63 unsigned int active; 64 atomic_t timer_state; 65 66 /* The dedupe contexts for querying the index from this zone */ 67 struct dedupe_context contexts[MAXIMUM_VDO_USER_VIOS]; 68 }; 69 70 struct hash_zones; 71 72 struct pbn_lock * __must_check vdo_get_duplicate_lock(struct data_vio *data_vio); 73 74 void vdo_acquire_hash_lock(struct vdo_completion *completion); 75 void vdo_continue_hash_lock(struct vdo_completion *completion); 76 void vdo_release_hash_lock(struct data_vio *data_vio); 77 void vdo_clean_failed_hash_lock(struct data_vio *data_vio); 78 void vdo_share_compressed_write_lock(struct data_vio *data_vio, 79 struct pbn_lock *pbn_lock); 80 81 int __must_check vdo_make_hash_zones(struct vdo *vdo, struct hash_zones **zones_ptr); 82 83 void vdo_free_hash_zones(struct hash_zones *zones); 84 85 void vdo_drain_hash_zones(struct hash_zones *zones, struct vdo_completion *parent); 86 87 void vdo_get_dedupe_statistics(struct hash_zones *zones, struct vdo_statistics *stats); 88 89 struct hash_zone * __must_check vdo_select_hash_zone(struct hash_zones *zones, 90 const struct uds_record_name *name); 91 92 void vdo_dump_hash_zones(struct hash_zones *zones); 93 94 const char *vdo_get_dedupe_index_state_name(struct hash_zones *zones); 95 96 u64 vdo_get_dedupe_index_timeout_count(struct hash_zones *zones); 97 98 int vdo_message_dedupe_index(struct hash_zones *zones, const char *name); 99 100 void vdo_set_dedupe_state_normal(struct hash_zones *zones); 101 102 void vdo_start_dedupe_index(struct hash_zones *zones, bool create_flag); 103 104 void vdo_resume_hash_zones(struct hash_zones *zones, struct vdo_completion *parent); 105 106 void vdo_finish_dedupe_index(struct hash_zones *zones); 107 108 /* Interval (in milliseconds) from submission until switching to fast path and skipping UDS. */ 109 extern unsigned int vdo_dedupe_index_timeout_interval; 110 111 /* 112 * Minimum time interval (in milliseconds) between timer invocations to check for requests waiting 113 * for UDS that should now time out. 114 */ 115 extern unsigned int vdo_dedupe_index_min_timer_interval; 116 117 void vdo_set_dedupe_index_timeout_interval(unsigned int value); 118 void vdo_set_dedupe_index_min_timer_interval(unsigned int value); 119 120 #endif /* VDO_DEDUPE_H */ 121