]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/lib/ftl/ftl_rwb.h
bump version to 15.2.11-pve1
[ceph.git] / ceph / src / spdk / lib / ftl / ftl_rwb.h
CommitLineData
9f95a23c
TL
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
34#ifndef FTL_RWB_H
35#define FTL_RWB_H
36
37#include "spdk/stdinc.h"
38#include "spdk/queue.h"
39
40#include "ftl_io.h"
41#include "ftl_ppa.h"
42#include "ftl_trace.h"
43
44struct ftl_rwb;
45struct spdk_ftl_conf;
46struct ftl_rwb_batch;
47
48enum ftl_rwb_entry_type {
49 FTL_RWB_TYPE_INTERNAL,
50 FTL_RWB_TYPE_USER,
51 FTL_RWB_TYPE_MAX
52};
53
54/* Write buffer entry */
55struct ftl_rwb_entry {
56 /* Owner rwb */
57 struct ftl_rwb *rwb;
58
59 /* Batch containing the entry */
60 struct ftl_rwb_batch *batch;
61
62 /* Logical address */
63 uint64_t lba;
64
65 /* Physical address */
66 struct ftl_ppa ppa;
67
68 /* Position within the rwb's buffer */
69 unsigned int pos;
70
71 /* Data pointer */
72 void *data;
73
74 /* Metadata pointer */
75 void *md;
76
77 /* Data/state lock */
78 pthread_spinlock_t lock;
79
80 /* Flags */
81 unsigned int flags;
82
83 /* Indicates whether the entry is part of cache and is assigned a PPA */
84 bool valid;
85
86 /* Trace group id */
87 uint64_t trace;
88
89 /* Batch list entry */
90 LIST_ENTRY(ftl_rwb_entry) list_entry;
91};
92
93struct ftl_rwb *ftl_rwb_init(const struct spdk_ftl_conf *conf, size_t xfer_size,
94 size_t md_size, size_t num_punits);
95size_t ftl_rwb_get_active_batches(const struct ftl_rwb *rwb);
96void ftl_rwb_free(struct ftl_rwb *rwb);
97void ftl_rwb_batch_release(struct ftl_rwb_batch *batch);
98void ftl_rwb_push(struct ftl_rwb_entry *entry);
99size_t ftl_rwb_entry_cnt(const struct ftl_rwb *rwb);
100void ftl_rwb_set_limits(struct ftl_rwb *rwb, const size_t limit[FTL_RWB_TYPE_MAX]);
101void ftl_rwb_get_limits(struct ftl_rwb *rwb, size_t limit[FTL_RWB_TYPE_MAX]);
102size_t ftl_rwb_num_acquired(struct ftl_rwb *rwb, enum ftl_rwb_entry_type type);
103size_t ftl_rwb_num_batches(const struct ftl_rwb *rwb);
104size_t ftl_rwb_size(const struct ftl_rwb *rwb);
105struct ftl_rwb_entry *ftl_rwb_acquire(struct ftl_rwb *rwb, enum ftl_rwb_entry_type type);
106struct ftl_rwb_batch *ftl_rwb_pop(struct ftl_rwb *rwb);
107struct ftl_rwb_batch *ftl_rwb_first_batch(struct ftl_rwb *rwb);
108struct ftl_rwb_batch *ftl_rwb_next_batch(struct ftl_rwb_batch *batch);
109int ftl_rwb_batch_empty(struct ftl_rwb_batch *batch);
110struct ftl_rwb_entry *ftl_rwb_entry_from_offset(struct ftl_rwb *rwb, size_t offset);
111size_t ftl_rwb_batch_get_offset(const struct ftl_rwb_batch *batch);
112void ftl_rwb_batch_revert(struct ftl_rwb_batch *batch);
113struct ftl_rwb_entry *ftl_rwb_batch_first_entry(struct ftl_rwb_batch *batch);
114void *ftl_rwb_batch_get_data(struct ftl_rwb_batch *batch);
115void *ftl_rwb_batch_get_md(struct ftl_rwb_batch *batch);
116void ftl_rwb_disable_interleaving(struct ftl_rwb *rwb);
117
118static inline void
119_ftl_rwb_entry_set_valid(struct ftl_rwb_entry *entry, bool valid)
120{
121 __atomic_store_n(&entry->valid, valid, __ATOMIC_SEQ_CST);
122}
123
124static inline void
125ftl_rwb_entry_set_valid(struct ftl_rwb_entry *entry)
126{
127 _ftl_rwb_entry_set_valid(entry, true);
128}
129
130static inline void
131ftl_rwb_entry_invalidate(struct ftl_rwb_entry *entry)
132{
133 _ftl_rwb_entry_set_valid(entry, false);
134}
135
136static inline int
137ftl_rwb_entry_valid(struct ftl_rwb_entry *entry)
138{
139 return __atomic_load_n(&entry->valid, __ATOMIC_SEQ_CST);
140}
141
142static inline enum ftl_rwb_entry_type
143ftl_rwb_type_from_flags(int flags) {
144 return (flags & FTL_IO_INTERNAL) ? FTL_RWB_TYPE_INTERNAL : FTL_RWB_TYPE_USER;
145}
146
147static inline enum ftl_rwb_entry_type
148ftl_rwb_entry_type(const struct ftl_rwb_entry *entry) {
149 return ftl_rwb_type_from_flags(entry->flags);
150}
151
152static inline int
153ftl_rwb_entry_internal(const struct ftl_rwb_entry *entry)
154{
155 return ftl_rwb_entry_type(entry) == FTL_RWB_TYPE_INTERNAL;
156}
157
158#define ftl_rwb_foreach(entry, batch) \
159 for (entry = ftl_rwb_batch_first_entry(batch); \
160 entry; entry = LIST_NEXT(entry, list_entry))
161
162#define ftl_rwb_foreach_batch(batch, rwb) \
163 for (batch = ftl_rwb_first_batch(rwb); batch; \
164 batch = ftl_rwb_next_batch(batch))
165
166#endif /* FTL_RWB_H */