summaryrefslogtreecommitdiffstats
path: root/src/spdk/ocf/inc/ocf_metadata.h
blob: 5ecfbcaef5c09f5b10f55a7effb7aa2338d484e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright(c) 2012-2018 Intel Corporation
 * SPDX-License-Identifier: BSD-3-Clause-Clear
 */

#ifndef __OCF_METADATA_H__
#define __OCF_METADATA_H__

/**
 * @file
 * @brief OCF metadata helper function
 *
 * Those functions can be used by volume implementation.
 */

/**
 * @brief Atomic metadata for extended sector
 *
 * @warning The size of this structure has to be equal 8 bytes
 */
struct ocf_atomic_metadata {
	/** Core line of core (in cache line size unit) which are cached */
	uint64_t core_line : 46;

	/** Core sequence number to which this line belongs to*/
	uint32_t core_seq_no : 16;

	/** Set bit indicates that given sector is valid (is cached) */
	uint32_t valid : 1;

	/** Set bit indicates that sector i dirty */
	uint32_t dirty : 1;
} __attribute__((packed));

#define OCF_ATOMIC_METADATA_SIZE	sizeof(struct ocf_atomic_metadata)

/**
 * @brief Get metadata entry (cache mapping) for specified sector of cache
 * device
 *
 * Metadata has sector granularity. It might be used by volume which
 * supports atomic writes - (write of data and metadata in one buffer)
 *
 * @param[in] cache OCF cache instance
 * @param[in] addr Sector address in bytes
 * @param[out] entry Metadata entry
 *
 * @retval 0 Metadata retrieved successfully
 * @retval Non-zero Error
 */
int ocf_metadata_get_atomic_entry(ocf_cache_t cache, uint64_t addr,
		struct ocf_atomic_metadata *entry);

/**
 * @brief Metadata probe status
 */
struct ocf_metadata_probe_status {
	/** Cache was graceful stopped */
	bool clean_shutdown;

	/** Cache contains dirty data */
	bool cache_dirty;

	/** Loaded name of cache instance */
	char cache_name[OCF_CACHE_NAME_SIZE];
};

/**
 * @brief Metadata probe completion callback
 *
 * @param[in] priv Completion context
 * @param[in] error Error code (zero on success)
 * @param[in] status Structure describing metadata probe status
 */
typedef void (*ocf_metadata_probe_end_t)(void *priv, int error,
		struct ocf_metadata_probe_status *status);

/**
 * @brief Probe cache device
 *
 * @param[in] ctx handle to object designating ocf context
 * @param[in] volume Cache volume
 * @param[in] cmpl Completion callback
 * @param[in] priv Completion context
 */
void ocf_metadata_probe(ocf_ctx_t ctx, ocf_volume_t volume,
		ocf_metadata_probe_end_t cmpl, void *priv);

/**
 * @brief Metadata probe for cores completion callback
 *
 * @param[in] priv Completion context
 * @param[in] error Error code (zero on success)
 * @param[in] num_cores Number of cores in cache metadata
 */
typedef void (*ocf_metadata_probe_cores_end_t)(void *priv, int error,
		unsigned int num_cores);

/**
 * @brief Probe cache device for associated cores
 *
 * @param[in] ctx handle to object designating ocf context
 * @param[in] volume Cache volume
 * @param[in,out] uuids Array of uuids
 * @param[in] uuid_count Size of @uuid array
 * @param[in] cmpl Completion callback
 * @param[in] priv Completion context
 */
void ocf_metadata_probe_cores(ocf_ctx_t ctx, ocf_volume_t volume,
		struct ocf_volume_uuid *uuids, uint32_t uuid_count,
		ocf_metadata_probe_cores_end_t cmpl, void *priv);

/**
 * @brief Check if sectors in cache line before given address are invalid
 *
 * It might be used by volume which supports
 * atomic writes - (write of data and metadata in one buffer)
 *
 * @param[in] cache OCF cache instance
 * @param[in] addr Sector address in bytes
 *
 * @retval 0 Not all sectors before given address are invalid
 * @retval Non-zero Number of sectors before given address
 */
int ocf_metadata_check_invalid_before(ocf_cache_t cache, uint64_t addr);

/**
 * @brief Check if sectors in cache line after given end address are invalid
 *
 * It might be used by volume which supports
 * atomic writes - (write of data and metadata in one buffer)
 *
 * @param[in] cache OCF cache instance
 * @param[in] addr Sector address in bytes
 * @param[in] bytes IO size in bytes
 *
 * @retval 0 Not all sectors after given end address are invalid
 * @retval Non-zero Number of sectors after given end address
 */
int ocf_metadata_check_invalid_after(ocf_cache_t cache, uint64_t addr,
		uint32_t bytes);

#endif /* __OCF_METADATA_H__ */