Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2016 Intel Corporation. All rights reserved.
3 : : * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
4 : : */
5 : :
6 : : #include "spdk/stdinc.h"
7 : :
8 : : #include "spdk/nvme.h"
9 : : #include "spdk/nvme_zns.h"
10 : : #include "spdk/vmd.h"
11 : : #include "spdk/env.h"
12 : : #include "spdk/string.h"
13 : : #include "spdk/log.h"
14 : : #include "spdk/likely.h"
15 : : #include "spdk/endian.h"
16 : : #include "spdk/dif.h"
17 : : #include "spdk/util.h"
18 : : #include "spdk/trace.h"
19 : :
20 : : #include "config-host.h"
21 : : #include "fio.h"
22 : : #include "optgroup.h"
23 : :
24 : : #ifdef for_each_rw_ddir
25 : : #define FIO_HAS_ZBD (FIO_IOOPS_VERSION >= 26)
26 : : #define FIO_HAS_FDP (FIO_IOOPS_VERSION >= 32)
27 : : #define FIO_HAS_MRT (FIO_IOOPS_VERSION >= 34)
28 : : #else
29 : : #define FIO_HAS_ZBD (0)
30 : : #define FIO_HAS_FDP (0)
31 : : #define FIO_HAS_MRT (0)
32 : : #endif
33 : :
34 : : /* FreeBSD is missing CLOCK_MONOTONIC_RAW,
35 : : * so alternative is provided. */
36 : : #ifndef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
37 : : #define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
38 : : #endif
39 : :
40 : : #define NVME_IO_ALIGN 4096
41 : :
42 : : static bool g_spdk_env_initialized;
43 : : static bool g_log_flag_error;
44 : : static int g_spdk_enable_sgl = 0;
45 : : static uint32_t g_spdk_sge_size = 4096;
46 : : static uint32_t g_spdk_bit_bucket_data_len = 0;
47 : : static uint32_t g_spdk_pract_flag;
48 : : static uint32_t g_spdk_prchk_flags;
49 : : static uint32_t g_spdk_md_per_io_size = 4096;
50 : : static uint16_t g_spdk_apptag;
51 : : static uint16_t g_spdk_apptag_mask;
52 : :
53 : : struct spdk_fio_options {
54 : : void *pad; /* off1 used in option descriptions may not be 0 */
55 : : int enable_wrr;
56 : : int arbitration_burst;
57 : : int low_weight;
58 : : int medium_weight;
59 : : int high_weight;
60 : : int wrr_priority;
61 : : int mem_size;
62 : : int shm_id;
63 : : int enable_sgl;
64 : : int sge_size;
65 : : int bit_bucket_data_len;
66 : : char *hostnqn;
67 : : int pi_act;
68 : : char *pi_chk;
69 : : int md_per_io_size;
70 : : int apptag;
71 : : int apptag_mask;
72 : : char *digest_enable;
73 : : int enable_vmd;
74 : : int initial_zone_reset;
75 : : int zone_append;
76 : : int print_qid_mappings;
77 : : int spdk_tracing;
78 : : char *log_flags;
79 : : };
80 : :
81 : : struct spdk_fio_request {
82 : : struct io_u *io;
83 : : /** Offset in current iovec, fio only uses 1 vector */
84 : : uint32_t iov_offset;
85 : :
86 : : /** Amount of data used for Bit Bucket SGL */
87 : : uint32_t bit_bucket_data_len;
88 : :
89 : : /** Context for NVMe PI */
90 : : struct spdk_dif_ctx dif_ctx;
91 : : /** Separate metadata buffer pointer */
92 : : void *md_buf;
93 : :
94 : : /** Dataset management range information */
95 : : struct spdk_nvme_dsm_range *dsm_range;
96 : :
97 : : struct spdk_fio_thread *fio_thread;
98 : : struct spdk_fio_qpair *fio_qpair;
99 : : };
100 : :
101 : : struct spdk_fio_ctrlr {
102 : : struct spdk_nvme_transport_id tr_id;
103 : : struct spdk_nvme_ctrlr_opts opts;
104 : : struct spdk_nvme_ctrlr *ctrlr;
105 : : TAILQ_ENTRY(spdk_fio_ctrlr) link;
106 : : };
107 : :
108 : : static TAILQ_HEAD(, spdk_fio_ctrlr) g_ctrlrs = TAILQ_HEAD_INITIALIZER(g_ctrlrs);
109 : : static int g_td_count;
110 : : static pthread_t g_ctrlr_thread_id = 0;
111 : : static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
112 : : static bool g_error;
113 : :
114 : : struct spdk_fio_qpair {
115 : : struct fio_file *f;
116 : : struct spdk_nvme_qpair *qpair;
117 : : struct spdk_nvme_ns *ns;
118 : : uint32_t io_flags;
119 : : bool zone_append_enabled;
120 : : bool nvme_pi_enabled;
121 : : /* True for DIF and false for DIX, and this is valid only if nvme_pi_enabled is true. */
122 : : bool extended_lba;
123 : : /* True for protection info transferred at start of metadata,
124 : : * false for protection info transferred at end of metadata, and
125 : : * this is valid only if nvme_pi_enabled is true.
126 : : */
127 : : bool md_start;
128 : : TAILQ_ENTRY(spdk_fio_qpair) link;
129 : : struct spdk_fio_ctrlr *fio_ctrlr;
130 : : };
131 : :
132 : : struct spdk_fio_thread {
133 : : struct thread_data *td;
134 : :
135 : : TAILQ_HEAD(, spdk_fio_qpair) fio_qpair;
136 : : struct spdk_fio_qpair *fio_qpair_current; /* the current fio_qpair to be handled. */
137 : :
138 : : struct io_u **iocq; /* io completion queue */
139 : : unsigned int iocq_count; /* number of iocq entries filled by last getevents */
140 : : unsigned int iocq_size; /* number of iocq entries allocated */
141 : : struct fio_file *current_f; /* fio_file given by user */
142 : :
143 : : };
144 : :
145 : : static void *
146 : 23 : spdk_fio_poll_ctrlrs(void *arg)
147 : : {
148 : : struct spdk_fio_ctrlr *fio_ctrlr;
149 : 7 : int oldstate;
150 : : int rc;
151 : :
152 : : /* Loop until the thread is cancelled */
153 : : while (true) {
154 : 80 : rc = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
155 [ - + ]: 80 : if (rc != 0) {
156 : 0 : SPDK_ERRLOG("Unable to set cancel state disabled on g_init_thread (%d): %s\n",
157 : : rc, spdk_strerror(rc));
158 : : }
159 : :
160 [ - + ]: 80 : pthread_mutex_lock(&g_mutex);
161 : :
162 [ + + ]: 127 : TAILQ_FOREACH(fio_ctrlr, &g_ctrlrs, link) {
163 : 47 : spdk_nvme_ctrlr_process_admin_completions(fio_ctrlr->ctrlr);
164 : : }
165 : :
166 [ - + ]: 80 : pthread_mutex_unlock(&g_mutex);
167 : :
168 : 80 : rc = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
169 [ - + ]: 80 : if (rc != 0) {
170 : 0 : SPDK_ERRLOG("Unable to set cancel state enabled on g_init_thread (%d): %s\n",
171 : : rc, spdk_strerror(rc));
172 : : }
173 : :
174 : : /* This is a pthread cancellation point and cannot be removed. */
175 : 80 : sleep(1);
176 : : }
177 : :
178 : : return NULL;
179 : : }
180 : :
181 : : static bool
182 : 23 : probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
183 : : struct spdk_nvme_ctrlr_opts *opts)
184 : : {
185 : 23 : struct thread_data *td = cb_ctx;
186 : 23 : struct spdk_fio_options *fio_options = td->eo;
187 : :
188 [ - + ]: 23 : if (fio_options->hostnqn) {
189 : 0 : snprintf(opts->hostnqn, sizeof(opts->hostnqn), "%s", fio_options->hostnqn);
190 : : }
191 : :
192 [ - + ]: 23 : if (fio_options->enable_wrr) {
193 : 0 : opts->arb_mechanism = SPDK_NVME_CC_AMS_WRR;
194 : 0 : opts->arbitration_burst = fio_options->arbitration_burst;
195 : 0 : opts->low_priority_weight = fio_options->low_weight;
196 : 0 : opts->medium_priority_weight = fio_options->medium_weight;
197 : 0 : opts->high_priority_weight = fio_options->high_weight;
198 : : }
199 : :
200 [ - + ]: 23 : if (fio_options->digest_enable) {
201 [ # # # # ]: 0 : if (strcasecmp(fio_options->digest_enable, "HEADER") == 0) {
202 : 0 : opts->header_digest = true;
203 [ # # # # ]: 0 : } else if (strcasecmp(fio_options->digest_enable, "DATA") == 0) {
204 : 0 : opts->data_digest = true;
205 [ # # # # ]: 0 : } else if (strcasecmp(fio_options->digest_enable, "BOTH") == 0) {
206 : 0 : opts->header_digest = true;
207 : 0 : opts->data_digest = true;
208 : : }
209 : : }
210 : :
211 : 23 : return true;
212 : : }
213 : :
214 : : static struct spdk_fio_ctrlr *
215 : 46 : get_fio_ctrlr(const struct spdk_nvme_transport_id *trid)
216 : : {
217 : : struct spdk_fio_ctrlr *fio_ctrlr;
218 : :
219 [ - + ]: 46 : TAILQ_FOREACH(fio_ctrlr, &g_ctrlrs, link) {
220 [ # # ]: 0 : if (spdk_nvme_transport_id_compare(trid, &fio_ctrlr->tr_id) == 0) {
221 : 0 : return fio_ctrlr;
222 : : }
223 : : }
224 : :
225 : 46 : return NULL;
226 : : }
227 : :
228 : : /**
229 : : * Returns the fio_qpair matching the given fio_file and has an associated ns
230 : : */
231 : : static struct spdk_fio_qpair *
232 : 1663808 : get_fio_qpair(struct spdk_fio_thread *fio_thread, struct fio_file *f)
233 : : {
234 : : struct spdk_fio_qpair *fio_qpair;
235 : :
236 [ + - ]: 1663808 : TAILQ_FOREACH(fio_qpair, &fio_thread->fio_qpair, link) {
237 [ + - + - ]: 1663808 : if ((fio_qpair->f == f) && fio_qpair->ns) {
238 : 1663808 : return fio_qpair;
239 : : }
240 : : }
241 : :
242 : 0 : return NULL;
243 : : }
244 : :
245 : : #if FIO_HAS_ZBD
246 : : /**
247 : : * Callback function to use while processing completions until completion-indicator turns non-zero
248 : : */
249 : : static void
250 : 0 : pcu_cb(void *ctx, const struct spdk_nvme_cpl *cpl)
251 : : {
252 : 0 : int *completed = ctx;
253 : :
254 [ # # # # ]: 0 : *completed = spdk_nvme_cpl_is_error(cpl) ? -1 : 1;
255 : 0 : }
256 : :
257 : : /**
258 : : * Process Completions Until the given 'completed' indicator turns non-zero or an error occurs
259 : : */
260 : : static int32_t
261 : 0 : pcu(struct spdk_nvme_qpair *qpair, int *completed)
262 : : {
263 : : int32_t ret;
264 : :
265 [ # # ]: 0 : while (!*completed) {
266 : 0 : ret = spdk_nvme_qpair_process_completions(qpair, 1);
267 [ # # ]: 0 : if (ret < 0) {
268 : 0 : log_err("spdk/nvme: process_compl(): ret: %d\n", ret);
269 : 0 : return ret;
270 : : }
271 : : }
272 : :
273 : 0 : return 0;
274 : : }
275 : : #endif
276 : :
277 : : static inline uint32_t
278 : 1663831 : _nvme_get_host_buffer_sector_size(struct spdk_nvme_ns *ns, uint32_t io_flags)
279 : : {
280 : 1663831 : bool md_excluded_from_xfer = false;
281 : : uint32_t md_size;
282 : : uint32_t ns_flags;
283 : :
284 : 1663831 : ns_flags = spdk_nvme_ns_get_flags(ns);
285 : 1663831 : md_size = spdk_nvme_ns_get_md_size(ns);
286 : :
287 : : /* For extended LBA format, if the metadata size is 8 bytes and PRACT is
288 : : * enabled(controller inserts/strips PI), we should reduce metadata size
289 : : * from block size.
290 : : */
291 : 3327662 : md_excluded_from_xfer = ((io_flags & SPDK_NVME_IO_FLAGS_PRACT) &&
292 [ # # ]: 0 : (ns_flags & SPDK_NVME_NS_EXTENDED_LBA_SUPPORTED) &&
293 [ - + - - : 1663831 : (ns_flags & SPDK_NVME_NS_DPS_PI_SUPPORTED) &&
- - ]
294 : : (md_size == 8));
295 : :
296 [ - + ]: 3327662 : return md_excluded_from_xfer ? spdk_nvme_ns_get_sector_size(ns) :
297 : 1663831 : spdk_nvme_ns_get_extended_sector_size(ns);
298 : : }
299 : :
300 : : static void
301 : 23 : attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
302 : : struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
303 : : {
304 : 23 : struct thread_data *td = cb_ctx;
305 : 23 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
306 : : struct spdk_fio_ctrlr *fio_ctrlr;
307 : : struct spdk_fio_qpair *fio_qpair;
308 : : struct spdk_nvme_ns *ns;
309 : : const struct spdk_nvme_ns_data *nsdata;
310 : 23 : struct fio_file *f = fio_thread->current_f;
311 : : uint32_t ns_id;
312 : : char *p;
313 : : long int tmp;
314 : : uint32_t block_size;
315 : 23 : struct spdk_fio_options *fio_options = td->eo;
316 : :
317 [ - + ]: 23 : p = strstr(f->file_name, "ns=");
318 [ + + ]: 23 : if (p != NULL) {
319 : 13 : tmp = spdk_strtol(p + 3, 10);
320 [ - + ]: 13 : if (tmp <= 0) {
321 : 0 : SPDK_ERRLOG("namespace id should be >=1, but was invalid: %ld\n", tmp);
322 : 0 : g_error = true;
323 : 0 : return;
324 : : }
325 : 13 : ns_id = (uint32_t)tmp;
326 : : } else {
327 : 10 : ns_id = spdk_nvme_ctrlr_get_first_active_ns(ctrlr);
328 [ - + ]: 10 : if (ns_id == 0) {
329 : : /* The ctrlr has no active namespaces and we didn't specify any so nothing to do. */
330 : 0 : return;
331 : : }
332 : : }
333 : :
334 : 23 : pthread_mutex_lock(&g_mutex);
335 : 23 : fio_ctrlr = get_fio_ctrlr(trid);
336 : : /* it is a new ctrlr and needs to be added */
337 [ + - ]: 23 : if (!fio_ctrlr) {
338 : : /* Create an fio_ctrlr and add it to the list */
339 : 23 : fio_ctrlr = calloc(1, sizeof(*fio_ctrlr));
340 [ - + ]: 23 : if (!fio_ctrlr) {
341 : 0 : SPDK_ERRLOG("Cannot allocate space for fio_ctrlr\n");
342 : 0 : g_error = true;
343 : 0 : pthread_mutex_unlock(&g_mutex);
344 : 0 : return;
345 : : }
346 : 23 : fio_ctrlr->opts = *opts;
347 : 23 : fio_ctrlr->ctrlr = ctrlr;
348 : 23 : fio_ctrlr->tr_id = *trid;
349 : 23 : TAILQ_INSERT_TAIL(&g_ctrlrs, fio_ctrlr, link);
350 : : }
351 : 23 : pthread_mutex_unlock(&g_mutex);
352 : :
353 : 23 : ns = spdk_nvme_ctrlr_get_ns(fio_ctrlr->ctrlr, ns_id);
354 [ - + ]: 23 : if (ns == NULL) {
355 : 0 : SPDK_ERRLOG("Cannot get namespace by ns_id=%d\n", ns_id);
356 : 0 : g_error = true;
357 : 0 : return;
358 : : }
359 : :
360 [ - + ]: 23 : if (!spdk_nvme_ns_is_active(ns)) {
361 : 0 : SPDK_ERRLOG("Inactive namespace by ns_id=%d\n", ns_id);
362 : 0 : g_error = true;
363 : 0 : return;
364 : : }
365 : 23 : nsdata = spdk_nvme_ns_get_data(ns);
366 : :
367 [ - + ]: 23 : TAILQ_FOREACH(fio_qpair, &fio_thread->fio_qpair, link) {
368 [ # # # # ]: 0 : if ((fio_qpair->f == f) ||
369 [ # # ]: 0 : ((spdk_nvme_transport_id_compare(trid, &fio_qpair->fio_ctrlr->tr_id) == 0) &&
370 : 0 : (spdk_nvme_ns_get_id(fio_qpair->ns) == ns_id))) {
371 : : /* Not the error case. Avoid duplicated connection */
372 : 0 : return;
373 : : }
374 : : }
375 : :
376 : : /* create a new qpair */
377 : 23 : fio_qpair = calloc(1, sizeof(*fio_qpair));
378 [ - + ]: 23 : if (!fio_qpair) {
379 : 0 : g_error = true;
380 : 0 : SPDK_ERRLOG("Cannot allocate space for fio_qpair\n");
381 : 0 : return;
382 : : }
383 : :
384 : 23 : f->engine_data = fio_qpair;
385 : 23 : fio_qpair->ns = ns;
386 : 23 : fio_qpair->f = f;
387 : 23 : fio_qpair->fio_ctrlr = fio_ctrlr;
388 : 23 : TAILQ_INSERT_TAIL(&fio_thread->fio_qpair, fio_qpair, link);
389 : :
390 [ - + ]: 23 : if (spdk_nvme_ns_get_flags(ns) & SPDK_NVME_NS_DPS_PI_SUPPORTED) {
391 [ # # ]: 0 : assert(spdk_nvme_ns_get_pi_type(ns) != SPDK_NVME_FMT_NVM_PROTECTION_DISABLE);
392 : 0 : fio_qpair->io_flags = g_spdk_pract_flag | g_spdk_prchk_flags;
393 : 0 : fio_qpair->nvme_pi_enabled = true;
394 : 0 : fio_qpair->md_start = nsdata->dps.md_start;
395 : 0 : fio_qpair->extended_lba = spdk_nvme_ns_supports_extended_lba(ns);
396 [ # # ]: 0 : fprintf(stdout, "PI type%u enabled with %s\n", spdk_nvme_ns_get_pi_type(ns),
397 [ # # # # ]: 0 : fio_qpair->extended_lba ? "extended lba" : "separate metadata");
398 : : }
399 : :
400 : 23 : block_size = _nvme_get_host_buffer_sector_size(ns, fio_qpair->io_flags);
401 [ + + ]: 92 : for_each_rw_ddir(ddir) {
402 [ + + + + : 69 : if (td->o.min_bs[ddir] % block_size != 0 || td->o.max_bs[ddir] % block_size != 0) {
- + - + ]
403 [ # # ]: 0 : if (spdk_nvme_ns_supports_extended_lba(ns)) {
404 : 0 : SPDK_ERRLOG("--bs or other block size related option has to be a multiple of (LBA data size + Metadata size)\n");
405 : : } else {
406 : 0 : SPDK_ERRLOG("--bs or other block size related option has to be a multiple of LBA data size\n");
407 : : }
408 : 0 : g_error = true;
409 : 0 : return;
410 : : }
411 : : }
412 : :
413 [ - + - - ]: 23 : if (fio_options->zone_append && spdk_nvme_ns_get_csi(ns) == SPDK_NVME_CSI_ZNS) {
414 [ # # ]: 0 : if (spdk_nvme_ctrlr_get_flags(ctrlr) & SPDK_NVME_CTRLR_ZONE_APPEND_SUPPORTED) {
415 [ # # # # ]: 0 : SPDK_DEBUGLOG(fio_nvme, "Using zone appends instead of writes on: '%s'\n",
416 : : f->file_name);
417 : 0 : fio_qpair->zone_append_enabled = true;
418 : : } else {
419 : 0 : SPDK_WARNLOG("Falling back to writes on: '%s' - ns lacks zone append cmd\n",
420 : : f->file_name);
421 : : }
422 : : }
423 : :
424 : : #if FIO_HAS_ZBD
425 [ - + - - ]: 23 : if (td_trim(td) && td->o.zone_mode == ZONE_MODE_ZBD) {
426 : 0 : td->io_ops->flags |= FIO_ASYNCIO_SYNC_TRIM;
427 : : }
428 : : #endif
429 : :
430 [ - + - - ]: 23 : if (fio_options->initial_zone_reset == 1 && spdk_nvme_ns_get_csi(ns) == SPDK_NVME_CSI_ZNS) {
431 : : #if FIO_HAS_ZBD
432 : : struct spdk_nvme_qpair *tmp_qpair;
433 : 0 : int completed = 0, err;
434 : :
435 : : /* qpair has not been allocated yet (it gets allocated in spdk_fio_open()).
436 : : * Create a temporary qpair in order to perform the initial zone reset.
437 : : */
438 [ # # ]: 0 : assert(!fio_qpair->qpair);
439 : :
440 : 0 : tmp_qpair = spdk_nvme_ctrlr_alloc_io_qpair(ctrlr, NULL, 0);
441 [ # # ]: 0 : if (!tmp_qpair) {
442 : 0 : SPDK_ERRLOG("Cannot allocate a temporary qpair\n");
443 : 0 : g_error = true;
444 : 0 : return;
445 : : }
446 : :
447 : 0 : err = spdk_nvme_zns_reset_zone(ns, tmp_qpair, 0x0, true, pcu_cb, &completed);
448 [ # # # # : 0 : if (err || pcu(tmp_qpair, &completed) || completed < 0) {
# # ]
449 : 0 : log_err("spdk/nvme: warn: initial_zone_reset: err: %d, cpl: %d\n",
450 : : err, completed);
451 : : }
452 : :
453 : 0 : spdk_nvme_ctrlr_free_io_qpair(tmp_qpair);
454 : : #else
455 : : log_err("spdk/nvme: ZBD/ZNS is not supported\n");
456 : : #endif
457 : : }
458 : :
459 : 23 : f->real_file_size = spdk_nvme_ns_get_size(fio_qpair->ns);
460 [ - + ]: 23 : if (f->real_file_size <= 0) {
461 : 0 : g_error = true;
462 : 0 : SPDK_ERRLOG("Cannot get namespace size by ns=%p\n", ns);
463 : 0 : return;
464 : : }
465 : :
466 : 23 : f->filetype = FIO_TYPE_BLOCK;
467 : 23 : fio_file_set_size_known(f);
468 : : }
469 : :
470 : : static void
471 : 23 : parse_prchk_flags(const char *prchk_str)
472 : : {
473 [ + - ]: 23 : if (!prchk_str) {
474 : 23 : return;
475 : : }
476 : :
477 [ # # # # ]: 0 : if (strstr(prchk_str, "GUARD") != NULL) {
478 : 0 : g_spdk_prchk_flags = SPDK_NVME_IO_FLAGS_PRCHK_GUARD;
479 : : }
480 [ # # # # ]: 0 : if (strstr(prchk_str, "REFTAG") != NULL) {
481 : 0 : g_spdk_prchk_flags |= SPDK_NVME_IO_FLAGS_PRCHK_REFTAG;
482 : : }
483 [ # # # # ]: 0 : if (strstr(prchk_str, "APPTAG") != NULL) {
484 : 0 : g_spdk_prchk_flags |= SPDK_NVME_IO_FLAGS_PRCHK_APPTAG;
485 : : }
486 : : }
487 : :
488 : : static void
489 : 23 : parse_pract_flag(int pract)
490 : : {
491 [ + - ]: 23 : if (pract == 1) {
492 : 23 : g_spdk_pract_flag = SPDK_NVME_IO_FLAGS_PRACT;
493 : : } else {
494 : 0 : g_spdk_pract_flag = 0;
495 : : }
496 : 23 : }
497 : :
498 : : static bool
499 : 0 : fio_redirected_to_dev_null(void)
500 : : {
501 : 0 : char path[PATH_MAX] = "";
502 : : ssize_t ret;
503 : :
504 : 0 : ret = readlink("/proc/self/fd/1", path, sizeof(path));
505 : :
506 [ # # # # ]: 0 : if (ret == -1 || strcmp(path, "/dev/null") != 0) {
507 : 0 : return false;
508 : : }
509 : :
510 : 0 : ret = readlink("/proc/self/fd/2", path, sizeof(path));
511 : :
512 [ # # # # ]: 0 : if (ret == -1 || strcmp(path, "/dev/null") != 0) {
513 : 0 : return false;
514 : : }
515 : :
516 : 0 : return true;
517 : : }
518 : :
519 : : static int
520 : 23 : spdk_fio_init(struct thread_data *td)
521 : : {
522 : 23 : int ret = 0;
523 : 23 : struct spdk_fio_options *fio_options = td->eo;
524 : :
525 [ - + ]: 23 : if (fio_options->spdk_tracing) {
526 : 0 : ret = spdk_trace_register_user_thread();
527 : : }
528 : :
529 : 23 : return ret;
530 : : }
531 : :
532 : : /* Called once at initialization. This is responsible for gathering the size of
533 : : * each "file", which in our case are in the form
534 : : * 'key=value [key=value] ... ns=value'
535 : : * For example, For local PCIe NVMe device - 'trtype=PCIe traddr=0000.04.00.0 ns=1'
536 : : * For remote exported by NVMe-oF target, 'trtype=RDMA adrfam=IPv4 traddr=192.168.100.8 trsvcid=4420 ns=1' */
537 : : static int
538 : 23 : spdk_fio_setup(struct thread_data *td)
539 : : {
540 : : struct spdk_fio_thread *fio_thread;
541 : 23 : struct spdk_fio_options *fio_options = td->eo;
542 : 7 : struct spdk_env_opts opts;
543 : : struct fio_file *f;
544 : : char *p;
545 : 23 : int rc = 0;
546 : 7 : struct spdk_nvme_transport_id trid;
547 : : struct spdk_fio_ctrlr *fio_ctrlr;
548 : : char *trid_info;
549 : : unsigned int i;
550 : :
551 : : /*
552 : : * If we're running in a daemonized FIO instance, it's possible
553 : : * fd 1/2 were re-used for something important by FIO. Newer fio
554 : : * versions are careful to redirect those to /dev/null, but if we're
555 : : * not, we'll abort early, so we don't accidentally write messages to
556 : : * an important file, etc.
557 : : */
558 [ - + - + : 23 : if (is_backend && !fio_redirected_to_dev_null()) {
- - ]
559 : 0 : char buf[1024];
560 : 0 : snprintf(buf, sizeof(buf),
561 : : "SPDK FIO plugin is in daemon mode, but stdout/stderr "
562 : : "aren't redirected to /dev/null. Aborting.");
563 : 0 : fio_server_text_output(FIO_LOG_ERR, buf, sizeof(buf));
564 : 0 : return -1;
565 : : }
566 : :
567 [ - + ]: 23 : if (!td->o.use_thread) {
568 : 0 : log_err("spdk: must set thread=1 when using spdk plugin\n");
569 : 0 : return 1;
570 : : }
571 : :
572 [ - + - + ]: 23 : if (g_log_flag_error) {
573 : : /* The first thread found an error when parsing log flags, so
574 : : * just return error immediately for all of the other threads.
575 : : */
576 : 0 : return 1;
577 : : }
578 : :
579 : 23 : pthread_mutex_lock(&g_mutex);
580 : :
581 : 23 : fio_thread = calloc(1, sizeof(*fio_thread));
582 [ - + ]: 23 : assert(fio_thread != NULL);
583 : :
584 : 23 : td->io_ops_data = fio_thread;
585 : 23 : fio_thread->td = td;
586 : :
587 : 23 : fio_thread->iocq_size = td->o.iodepth;
588 : 23 : fio_thread->iocq = calloc(fio_thread->iocq_size, sizeof(struct io_u *));
589 [ - + ]: 23 : assert(fio_thread->iocq != NULL);
590 : :
591 : 23 : TAILQ_INIT(&fio_thread->fio_qpair);
592 : :
593 [ + + + - ]: 23 : if (!g_spdk_env_initialized) {
594 : 23 : spdk_env_opts_init(&opts);
595 : 23 : opts.name = "fio";
596 : 23 : opts.mem_size = fio_options->mem_size;
597 : 23 : opts.shm_id = fio_options->shm_id;
598 : 23 : g_spdk_enable_sgl = fio_options->enable_sgl;
599 : 23 : g_spdk_sge_size = fio_options->sge_size;
600 : 23 : g_spdk_bit_bucket_data_len = fio_options->bit_bucket_data_len;
601 : 23 : parse_pract_flag(fio_options->pi_act);
602 : 23 : g_spdk_md_per_io_size = spdk_max(fio_options->md_per_io_size, 4096);
603 : 23 : g_spdk_apptag = (uint16_t)fio_options->apptag;
604 : 23 : g_spdk_apptag_mask = (uint16_t)fio_options->apptag_mask;
605 : 23 : parse_prchk_flags(fio_options->pi_chk);
606 [ - + ]: 23 : if (spdk_env_init(&opts) < 0) {
607 : 0 : SPDK_ERRLOG("Unable to initialize SPDK env\n");
608 : 0 : free(fio_thread->iocq);
609 : 0 : free(fio_thread);
610 : 0 : fio_thread = NULL;
611 : 0 : pthread_mutex_unlock(&g_mutex);
612 : 0 : return 1;
613 : : }
614 : :
615 [ - + ]: 23 : if (fio_options->log_flags) {
616 : 0 : char *tok = strtok(fio_options->log_flags, ",");
617 : : do {
618 : 0 : rc = spdk_log_set_flag(tok);
619 [ # # ]: 0 : if (rc < 0) {
620 : 0 : SPDK_ERRLOG("unknown log flag %s\n", tok);
621 : 0 : g_log_flag_error = true;
622 : 0 : return 1;
623 : : }
624 [ # # ]: 0 : } while ((tok = strtok(NULL, ",")) != NULL);
625 : : #ifdef DEBUG
626 : 0 : spdk_log_set_print_level(SPDK_LOG_DEBUG);
627 : : #endif
628 : : }
629 : :
630 : 23 : g_spdk_env_initialized = true;
631 : 23 : spdk_unaffinitize_thread();
632 : :
633 [ - + ]: 23 : if (fio_options->spdk_tracing) {
634 : 0 : spdk_trace_init("spdk_fio_tracepoints", 65536, td->o.numjobs);
635 : 0 : spdk_trace_enable_tpoint_group("nvme_pcie");
636 : 0 : spdk_trace_enable_tpoint_group("nvme_tcp");
637 : : }
638 : :
639 : : /* Spawn a thread to continue polling the controllers */
640 : 23 : rc = pthread_create(&g_ctrlr_thread_id, NULL, &spdk_fio_poll_ctrlrs, NULL);
641 [ - + ]: 23 : if (rc != 0) {
642 : 0 : SPDK_ERRLOG("Unable to spawn a thread to poll admin queues. They won't be polled.\n");
643 : : }
644 : :
645 [ + + - + ]: 23 : if (fio_options->enable_vmd && spdk_vmd_init()) {
646 : 0 : SPDK_ERRLOG("Failed to initialize VMD. Some NVMe devices can be unavailable.\n");
647 : : }
648 : : }
649 : 23 : pthread_mutex_unlock(&g_mutex);
650 : :
651 [ + - + + : 46 : for_each_file(td, f, i) {
+ - ]
652 : 23 : memset(&trid, 0, sizeof(trid));
653 : :
654 : 23 : trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
655 : :
656 [ - + ]: 23 : p = strstr(f->file_name, " ns=");
657 [ + + ]: 23 : if (p != NULL) {
658 [ - + ]: 13 : trid_info = strndup(f->file_name, p - f->file_name);
659 : : } else {
660 [ - + - + ]: 10 : trid_info = strndup(f->file_name, strlen(f->file_name));
661 : : }
662 : :
663 [ - + ]: 23 : if (!trid_info) {
664 : 0 : SPDK_ERRLOG("Failed to allocate space for trid_info\n");
665 : 0 : continue;
666 : : }
667 : :
668 : 23 : rc = spdk_nvme_transport_id_parse(&trid, trid_info);
669 [ - + ]: 23 : if (rc < 0) {
670 : 0 : SPDK_ERRLOG("Failed to parse given str: %s\n", trid_info);
671 : 0 : free(trid_info);
672 : 0 : continue;
673 : : }
674 : 23 : free(trid_info);
675 : :
676 [ + + ]: 23 : if (trid.trtype == SPDK_NVME_TRANSPORT_PCIE) {
677 : 7 : struct spdk_pci_addr pci_addr;
678 [ - + ]: 11 : if (spdk_pci_addr_parse(&pci_addr, trid.traddr) < 0) {
679 : 0 : SPDK_ERRLOG("Invalid traddr=%s\n", trid.traddr);
680 : 0 : continue;
681 : : }
682 : 11 : spdk_pci_addr_fmt(trid.traddr, sizeof(trid.traddr), &pci_addr);
683 : : } else {
684 [ + - ]: 12 : if (trid.subnqn[0] == '\0') {
685 : 12 : snprintf(trid.subnqn, sizeof(trid.subnqn), "%s",
686 : : SPDK_NVMF_DISCOVERY_NQN);
687 : : }
688 : : }
689 : :
690 : 23 : fio_thread->current_f = f;
691 : :
692 : 23 : pthread_mutex_lock(&g_mutex);
693 : 23 : fio_ctrlr = get_fio_ctrlr(&trid);
694 : 23 : pthread_mutex_unlock(&g_mutex);
695 [ - + ]: 23 : if (fio_ctrlr) {
696 : 0 : attach_cb(td, &trid, fio_ctrlr->ctrlr, &fio_ctrlr->opts);
697 : : } else {
698 : : /* Enumerate all of the controllers */
699 [ - + ]: 23 : if (spdk_nvme_probe(&trid, td, probe_cb, attach_cb, NULL) != 0) {
700 : 0 : SPDK_ERRLOG("spdk_nvme_probe() failed\n");
701 : 0 : continue;
702 : : }
703 : : }
704 : :
705 [ - + - + ]: 23 : if (g_error) {
706 : 0 : log_err("Failed to initialize spdk fio plugin\n");
707 : 0 : rc = 1;
708 : 0 : break;
709 : : }
710 : : }
711 : :
712 : 23 : pthread_mutex_lock(&g_mutex);
713 : 23 : g_td_count++;
714 : 23 : pthread_mutex_unlock(&g_mutex);
715 : :
716 : 23 : return rc;
717 : : }
718 : :
719 : : static int
720 : 37 : spdk_fio_open(struct thread_data *td, struct fio_file *f)
721 : : {
722 : 37 : struct spdk_fio_qpair *fio_qpair = f->engine_data;
723 : 37 : struct spdk_fio_ctrlr *fio_ctrlr = fio_qpair->fio_ctrlr;
724 : 37 : struct spdk_fio_options *fio_options = td->eo;
725 : 7 : struct spdk_nvme_io_qpair_opts qpopts;
726 : :
727 [ - + ]: 37 : assert(fio_qpair->qpair == NULL);
728 : 37 : spdk_nvme_ctrlr_get_default_io_qpair_opts(fio_ctrlr->ctrlr, &qpopts, sizeof(qpopts));
729 : 37 : qpopts.delay_cmd_submit = true;
730 [ - + ]: 37 : if (fio_options->enable_wrr) {
731 : 0 : qpopts.qprio = fio_options->wrr_priority;
732 : : }
733 : :
734 : 37 : fio_qpair->qpair = spdk_nvme_ctrlr_alloc_io_qpair(fio_ctrlr->ctrlr, &qpopts, sizeof(qpopts));
735 [ - + ]: 37 : if (!fio_qpair->qpair) {
736 : 0 : SPDK_ERRLOG("Cannot allocate nvme io_qpair any more\n");
737 : 0 : g_error = true;
738 : 0 : free(fio_qpair);
739 : 0 : return -1;
740 : : }
741 : :
742 [ - + ]: 37 : if (fio_options->print_qid_mappings == 1) {
743 : 0 : log_info("job %s: %s qid %d\n", td->o.name, f->file_name,
744 : 0 : spdk_nvme_qpair_get_id(fio_qpair->qpair));
745 : : }
746 : :
747 : 37 : return 0;
748 : : }
749 : :
750 : : static int
751 : 37 : spdk_fio_close(struct thread_data *td, struct fio_file *f)
752 : : {
753 : 37 : struct spdk_fio_qpair *fio_qpair = f->engine_data;
754 : :
755 [ - + ]: 37 : assert(fio_qpair->qpair != NULL);
756 : 37 : spdk_nvme_ctrlr_free_io_qpair(fio_qpair->qpair);
757 : 37 : fio_qpair->qpair = NULL;
758 : 37 : return 0;
759 : : }
760 : :
761 : : static int
762 : 23 : spdk_fio_iomem_alloc(struct thread_data *td, size_t total_mem)
763 : : {
764 : 23 : td->orig_buffer = spdk_dma_zmalloc(total_mem, NVME_IO_ALIGN, NULL);
765 : 23 : return td->orig_buffer == NULL;
766 : : }
767 : :
768 : : static void
769 : 23 : spdk_fio_iomem_free(struct thread_data *td)
770 : : {
771 : 23 : spdk_dma_free(td->orig_buffer);
772 : 23 : }
773 : :
774 : : static int
775 : 2944 : spdk_fio_io_u_init(struct thread_data *td, struct io_u *io_u)
776 : : {
777 : 2944 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
778 : : struct spdk_fio_request *fio_req;
779 : : uint32_t dsm_size;
780 : :
781 : 2944 : io_u->engine_data = NULL;
782 : :
783 : 2944 : fio_req = calloc(1, sizeof(*fio_req));
784 [ - + ]: 2944 : if (fio_req == NULL) {
785 : 0 : return 1;
786 : : }
787 : :
788 [ + - ]: 2944 : if (!(td->io_ops->flags & FIO_ASYNCIO_SYNC_TRIM)) {
789 : : #if FIO_HAS_MRT
790 : : /* By default number of range is set to 1 */
791 : : dsm_size = td->o.num_range * sizeof(struct spdk_nvme_dsm_range);
792 : : #else
793 : 2944 : dsm_size = sizeof(struct spdk_nvme_dsm_range);
794 : : #endif
795 : 2944 : fio_req->dsm_range = calloc(1, dsm_size);
796 [ - + ]: 2944 : if (fio_req->dsm_range == NULL) {
797 : 0 : free(fio_req);
798 : 0 : return 1;
799 : : }
800 : : }
801 : :
802 : 2944 : fio_req->md_buf = spdk_dma_zmalloc(g_spdk_md_per_io_size, NVME_IO_ALIGN, NULL);
803 [ - + ]: 2944 : if (fio_req->md_buf == NULL) {
804 [ # # # # ]: 0 : fprintf(stderr, "Allocate %u metadata failed\n", g_spdk_md_per_io_size);
805 : 0 : free(fio_req->dsm_range);
806 : 0 : free(fio_req);
807 : 0 : return 1;
808 : : }
809 : :
810 : 2944 : fio_req->io = io_u;
811 : 2944 : fio_req->fio_thread = fio_thread;
812 : :
813 : 2944 : io_u->engine_data = fio_req;
814 : :
815 : 2944 : return 0;
816 : : }
817 : :
818 : : static void
819 : 2944 : spdk_fio_io_u_free(struct thread_data *td, struct io_u *io_u)
820 : : {
821 : 2944 : struct spdk_fio_request *fio_req = io_u->engine_data;
822 : :
823 [ + - ]: 2944 : if (fio_req) {
824 [ - + ]: 2944 : assert(fio_req->io == io_u);
825 : 2944 : spdk_dma_free(fio_req->md_buf);
826 : 2944 : free(fio_req->dsm_range);
827 : 2944 : free(fio_req);
828 : 2944 : io_u->engine_data = NULL;
829 : : }
830 : 2944 : }
831 : :
832 : : static inline uint64_t
833 : 0 : fio_offset_to_zslba(unsigned long long offset, struct spdk_nvme_ns *ns)
834 : : {
835 [ # # ]: 0 : return (offset / spdk_nvme_zns_ns_get_zone_size(ns)) * spdk_nvme_zns_ns_get_zone_size_sectors(ns);
836 : : }
837 : :
838 : : static int
839 : 0 : fio_extended_lba_setup_pi(struct spdk_fio_qpair *fio_qpair, struct io_u *io_u)
840 : : {
841 : 0 : struct spdk_nvme_ns *ns = fio_qpair->ns;
842 : 0 : struct spdk_fio_request *fio_req = io_u->engine_data;
843 : : uint32_t md_size, extended_lba_size, lba_count;
844 : : uint64_t lba;
845 : 0 : struct iovec iov;
846 : : int rc;
847 : 0 : struct spdk_dif_ctx_init_ext_opts dif_opts;
848 : :
849 : : /* Set appmask and apptag when PRACT is enabled */
850 [ # # ]: 0 : if (fio_qpair->io_flags & SPDK_NVME_IO_FLAGS_PRACT) {
851 : 0 : fio_req->dif_ctx.apptag_mask = g_spdk_apptag_mask;
852 : 0 : fio_req->dif_ctx.app_tag = g_spdk_apptag;
853 : 0 : return 0;
854 : : }
855 : :
856 : 0 : extended_lba_size = spdk_nvme_ns_get_extended_sector_size(ns);
857 : 0 : md_size = spdk_nvme_ns_get_md_size(ns);
858 [ # # ]: 0 : lba = io_u->offset / extended_lba_size;
859 [ # # ]: 0 : lba_count = io_u->xfer_buflen / extended_lba_size;
860 : :
861 : 0 : dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
862 : 0 : dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
863 : 0 : rc = spdk_dif_ctx_init(&fio_req->dif_ctx, extended_lba_size, md_size,
864 [ # # ]: 0 : true, fio_qpair->md_start,
865 : 0 : (enum spdk_dif_type)spdk_nvme_ns_get_pi_type(ns),
866 : : fio_qpair->io_flags, lba, g_spdk_apptag_mask, g_spdk_apptag,
867 : : 0, 0, &dif_opts);
868 [ # # ]: 0 : if (rc != 0) {
869 [ # # # # ]: 0 : fprintf(stderr, "Initialization of DIF context failed\n");
870 : 0 : return rc;
871 : : }
872 : :
873 [ # # ]: 0 : if (io_u->ddir != DDIR_WRITE) {
874 : 0 : return 0;
875 : : }
876 : :
877 : 0 : iov.iov_base = io_u->buf;
878 : 0 : iov.iov_len = io_u->xfer_buflen;
879 : 0 : rc = spdk_dif_generate(&iov, 1, lba_count, &fio_req->dif_ctx);
880 [ # # ]: 0 : if (rc != 0) {
881 [ # # # # ]: 0 : fprintf(stderr, "Generation of DIF failed\n");
882 : : }
883 : :
884 : 0 : return rc;
885 : : }
886 : :
887 : : static int
888 : 0 : fio_separate_md_setup_pi(struct spdk_fio_qpair *fio_qpair, struct io_u *io_u)
889 : : {
890 : 0 : struct spdk_nvme_ns *ns = fio_qpair->ns;
891 : 0 : struct spdk_fio_request *fio_req = io_u->engine_data;
892 : : uint32_t md_size, block_size, lba_count;
893 : : uint64_t lba;
894 : 0 : struct iovec iov, md_iov;
895 : : int rc;
896 : 0 : struct spdk_dif_ctx_init_ext_opts dif_opts;
897 : :
898 : : /* Set appmask and apptag when PRACT is enabled */
899 [ # # ]: 0 : if (fio_qpair->io_flags & SPDK_NVME_IO_FLAGS_PRACT) {
900 : 0 : fio_req->dif_ctx.apptag_mask = g_spdk_apptag_mask;
901 : 0 : fio_req->dif_ctx.app_tag = g_spdk_apptag;
902 : 0 : return 0;
903 : : }
904 : :
905 : 0 : block_size = spdk_nvme_ns_get_sector_size(ns);
906 : 0 : md_size = spdk_nvme_ns_get_md_size(ns);
907 [ # # ]: 0 : lba = io_u->offset / block_size;
908 [ # # ]: 0 : lba_count = io_u->xfer_buflen / block_size;
909 : :
910 : 0 : dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
911 : 0 : dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
912 : 0 : rc = spdk_dif_ctx_init(&fio_req->dif_ctx, block_size, md_size,
913 [ # # ]: 0 : false, fio_qpair->md_start,
914 : 0 : (enum spdk_dif_type)spdk_nvme_ns_get_pi_type(ns),
915 : : fio_qpair->io_flags, lba, g_spdk_apptag_mask, g_spdk_apptag,
916 : : 0, 0, &dif_opts);
917 [ # # ]: 0 : if (rc != 0) {
918 [ # # # # ]: 0 : fprintf(stderr, "Initialization of DIF context failed\n");
919 : 0 : return rc;
920 : : }
921 : :
922 [ # # ]: 0 : if (io_u->ddir != DDIR_WRITE) {
923 : 0 : return 0;
924 : : }
925 : :
926 : 0 : iov.iov_base = io_u->buf;
927 : 0 : iov.iov_len = io_u->xfer_buflen;
928 : 0 : md_iov.iov_base = fio_req->md_buf;
929 : 0 : md_iov.iov_len = spdk_min(md_size * lba_count, g_spdk_md_per_io_size);
930 : 0 : rc = spdk_dix_generate(&iov, 1, &md_iov, lba_count, &fio_req->dif_ctx);
931 [ # # ]: 0 : if (rc < 0) {
932 [ # # # # ]: 0 : fprintf(stderr, "Generation of DIX failed\n");
933 : : }
934 : :
935 : 0 : return rc;
936 : : }
937 : :
938 : : static int
939 : 0 : fio_extended_lba_verify_pi(struct spdk_fio_qpair *fio_qpair, struct io_u *io_u)
940 : : {
941 : 0 : struct spdk_nvme_ns *ns = fio_qpair->ns;
942 : 0 : struct spdk_fio_request *fio_req = io_u->engine_data;
943 : : uint32_t lba_count;
944 : 0 : struct iovec iov;
945 : 0 : struct spdk_dif_error err_blk = {};
946 : : int rc;
947 : :
948 : : /* Do nothing when PRACT is enabled */
949 [ # # ]: 0 : if (fio_qpair->io_flags & SPDK_NVME_IO_FLAGS_PRACT) {
950 : 0 : return 0;
951 : : }
952 : :
953 : 0 : iov.iov_base = io_u->buf;
954 : 0 : iov.iov_len = io_u->xfer_buflen;
955 [ # # ]: 0 : lba_count = io_u->xfer_buflen / spdk_nvme_ns_get_extended_sector_size(ns);
956 : :
957 : 0 : rc = spdk_dif_verify(&iov, 1, lba_count, &fio_req->dif_ctx, &err_blk);
958 [ # # ]: 0 : if (rc != 0) {
959 [ # # ]: 0 : fprintf(stderr, "DIF error detected. type=%d, offset=%" PRIu32 "\n",
960 [ # # ]: 0 : err_blk.err_type, err_blk.err_offset);
961 : : }
962 : :
963 : 0 : return rc;
964 : : }
965 : :
966 : : static int
967 : 0 : fio_separate_md_verify_pi(struct spdk_fio_qpair *fio_qpair, struct io_u *io_u)
968 : : {
969 : 0 : struct spdk_nvme_ns *ns = fio_qpair->ns;
970 : 0 : struct spdk_fio_request *fio_req = io_u->engine_data;
971 : : uint32_t md_size, lba_count;
972 : 0 : struct iovec iov, md_iov;
973 : 0 : struct spdk_dif_error err_blk = {};
974 : : int rc;
975 : :
976 : : /* Do nothing when PRACT is enabled */
977 [ # # ]: 0 : if (fio_qpair->io_flags & SPDK_NVME_IO_FLAGS_PRACT) {
978 : 0 : return 0;
979 : : }
980 : :
981 : 0 : iov.iov_base = io_u->buf;
982 : 0 : iov.iov_len = io_u->xfer_buflen;
983 [ # # ]: 0 : lba_count = io_u->xfer_buflen / spdk_nvme_ns_get_sector_size(ns);
984 : 0 : md_size = spdk_nvme_ns_get_md_size(ns);
985 : 0 : md_iov.iov_base = fio_req->md_buf;
986 : 0 : md_iov.iov_len = spdk_min(md_size * lba_count, g_spdk_md_per_io_size);
987 : :
988 : 0 : rc = spdk_dix_verify(&iov, 1, &md_iov, lba_count, &fio_req->dif_ctx, &err_blk);
989 [ # # ]: 0 : if (rc != 0) {
990 [ # # ]: 0 : fprintf(stderr, "DIX error detected. type=%d, offset=%" PRIu32 "\n",
991 [ # # ]: 0 : err_blk.err_type, err_blk.err_offset);
992 : : }
993 : :
994 : 0 : return rc;
995 : : }
996 : :
997 : : static void
998 : 1663808 : spdk_fio_completion_cb(void *ctx, const struct spdk_nvme_cpl *cpl)
999 : : {
1000 : 1663808 : struct spdk_fio_request *fio_req = ctx;
1001 : 1663808 : struct spdk_fio_thread *fio_thread = fio_req->fio_thread;
1002 : 1663808 : struct spdk_fio_qpair *fio_qpair = fio_req->fio_qpair;
1003 : : int rc;
1004 : :
1005 [ - + - + : 1663808 : if (fio_qpair->nvme_pi_enabled && fio_req->io->ddir == DDIR_READ) {
- - ]
1006 [ # # # # ]: 0 : if (fio_qpair->extended_lba) {
1007 : 0 : rc = fio_extended_lba_verify_pi(fio_qpair, fio_req->io);
1008 : : } else {
1009 : 0 : rc = fio_separate_md_verify_pi(fio_qpair, fio_req->io);
1010 : : }
1011 [ # # ]: 0 : if (rc != 0) {
1012 : 0 : fio_req->io->error = abs(rc);
1013 : : }
1014 : : }
1015 : :
1016 [ + - - + ]: 1663808 : if (spdk_nvme_cpl_is_error(cpl)) {
1017 : 0 : fio_req->io->error = EIO;
1018 : : }
1019 : :
1020 [ - + ]: 1663808 : assert(fio_thread->iocq_count < fio_thread->iocq_size);
1021 : 1663808 : fio_thread->iocq[fio_thread->iocq_count++] = fio_req->io;
1022 : 1663808 : }
1023 : :
1024 : : static void
1025 : 148692 : spdk_nvme_io_reset_sgl(void *ref, uint32_t sgl_offset)
1026 : : {
1027 : 148692 : struct spdk_fio_request *fio_req = (struct spdk_fio_request *)ref;
1028 : :
1029 : 148692 : fio_req->iov_offset = sgl_offset;
1030 : 148692 : fio_req->bit_bucket_data_len = 0;
1031 : 148692 : }
1032 : :
1033 : : static int
1034 : 594768 : spdk_nvme_io_next_sge(void *ref, void **address, uint32_t *length)
1035 : : {
1036 : 594768 : struct spdk_fio_request *fio_req = (struct spdk_fio_request *)ref;
1037 : 594768 : struct io_u *io_u = fio_req->io;
1038 : : uint32_t iov_len;
1039 : : uint32_t bit_bucket_len;
1040 : :
1041 : 594768 : *address = io_u->buf;
1042 : :
1043 [ + + ]: 594768 : if (fio_req->iov_offset) {
1044 [ - + ]: 446076 : assert(fio_req->iov_offset <= io_u->xfer_buflen);
1045 : 446076 : *address += fio_req->iov_offset;
1046 : : }
1047 : :
1048 : 594768 : iov_len = io_u->xfer_buflen - fio_req->iov_offset;
1049 [ + + ]: 594768 : if (iov_len > g_spdk_sge_size) {
1050 : 446076 : iov_len = g_spdk_sge_size;
1051 : : }
1052 : :
1053 [ - + - - ]: 594768 : if ((fio_req->bit_bucket_data_len < g_spdk_bit_bucket_data_len) && (io_u->ddir == DDIR_READ)) {
1054 [ # # ]: 0 : assert(g_spdk_bit_bucket_data_len < io_u->xfer_buflen);
1055 : 0 : *address = (void *)UINT64_MAX;
1056 : 0 : bit_bucket_len = g_spdk_bit_bucket_data_len - fio_req->bit_bucket_data_len;
1057 [ # # ]: 0 : if (iov_len > bit_bucket_len) {
1058 : 0 : iov_len = bit_bucket_len;
1059 : : }
1060 : 0 : fio_req->bit_bucket_data_len += iov_len;
1061 : : }
1062 : :
1063 : 594768 : fio_req->iov_offset += iov_len;
1064 : 594768 : *length = iov_len;
1065 : :
1066 : 594768 : return 0;
1067 : : }
1068 : :
1069 : : #if FIO_IOOPS_VERSION >= 24
1070 : : typedef enum fio_q_status fio_q_status_t;
1071 : : #else
1072 : : typedef int fio_q_status_t;
1073 : : #endif
1074 : :
1075 : : static fio_q_status_t
1076 : 1663808 : spdk_fio_queue(struct thread_data *td, struct io_u *io_u)
1077 : : {
1078 : 1663808 : int rc = 1;
1079 : 1663808 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
1080 : 1663808 : struct spdk_fio_request *fio_req = io_u->engine_data;
1081 : : struct spdk_fio_qpair *fio_qpair;
1082 : 1663808 : struct spdk_nvme_ns *ns = NULL;
1083 : 1663808 : void *md_buf = NULL;
1084 : 1663808 : struct spdk_dif_ctx *dif_ctx = &fio_req->dif_ctx;
1085 : : #if FIO_HAS_FDP
1086 : 644489 : struct spdk_nvme_ns_cmd_ext_io_opts ext_opts;
1087 : : #endif
1088 : : struct spdk_nvme_dsm_range *range;
1089 : : uint32_t block_size;
1090 : : uint64_t lba;
1091 : : uint32_t lba_count;
1092 : : uint32_t num_range;
1093 : :
1094 : 1663808 : fio_qpair = get_fio_qpair(fio_thread, io_u->file);
1095 [ - + ]: 1663808 : if (fio_qpair == NULL) {
1096 : 0 : return -ENXIO;
1097 : : }
1098 : 1663808 : ns = fio_qpair->ns;
1099 : :
1100 [ - + - + : 1663808 : if (fio_qpair->nvme_pi_enabled && !fio_qpair->extended_lba) {
- - - - ]
1101 : 0 : md_buf = fio_req->md_buf;
1102 : : }
1103 : 1663808 : fio_req->fio_qpair = fio_qpair;
1104 : :
1105 : 1663808 : block_size = _nvme_get_host_buffer_sector_size(ns, fio_qpair->io_flags);
1106 [ - + ]: 1663808 : lba = io_u->offset / block_size;
1107 [ - + ]: 1663808 : lba_count = io_u->xfer_buflen / block_size;
1108 : :
1109 : : #if FIO_HAS_FDP
1110 : : /* Only SGL support for write command with directives */
1111 [ + + - + : 1663808 : if (io_u->ddir == DDIR_WRITE && io_u->dtype && !g_spdk_enable_sgl) {
- - ]
1112 : 0 : log_err("spdk/nvme: queue() directives require SGL to be enabled\n");
1113 : 0 : io_u->error = -EINVAL;
1114 : 0 : return FIO_Q_COMPLETED;
1115 : : }
1116 : : #endif
1117 : :
1118 : : /* TODO: considering situations that fio will randomize and verify io_u */
1119 [ - + - + ]: 1663808 : if (fio_qpair->nvme_pi_enabled) {
1120 [ # # # # ]: 0 : if (fio_qpair->extended_lba) {
1121 : 0 : rc = fio_extended_lba_setup_pi(fio_qpair, io_u);
1122 : : } else {
1123 : 0 : rc = fio_separate_md_setup_pi(fio_qpair, io_u);
1124 : : }
1125 [ # # ]: 0 : if (rc < 0) {
1126 : 0 : io_u->error = -rc;
1127 : 0 : return FIO_Q_COMPLETED;
1128 : : }
1129 : : }
1130 : :
1131 [ + + - - ]: 1663808 : switch (io_u->ddir) {
1132 : 844483 : case DDIR_READ:
1133 [ + + ]: 844483 : if (!g_spdk_enable_sgl) {
1134 : 795631 : rc = spdk_nvme_ns_cmd_read_with_md(ns, fio_qpair->qpair, io_u->buf, md_buf, lba, lba_count,
1135 : : spdk_fio_completion_cb, fio_req,
1136 : 795631 : fio_qpair->io_flags, dif_ctx->apptag_mask, dif_ctx->app_tag);
1137 : : } else {
1138 : 48852 : rc = spdk_nvme_ns_cmd_readv_with_md(ns, fio_qpair->qpair, lba,
1139 : : lba_count, spdk_fio_completion_cb, fio_req, fio_qpair->io_flags,
1140 : : spdk_nvme_io_reset_sgl, spdk_nvme_io_next_sge, md_buf,
1141 : 48852 : dif_ctx->apptag_mask, dif_ctx->app_tag);
1142 : : }
1143 : 844483 : break;
1144 : 819325 : case DDIR_WRITE:
1145 [ + + ]: 819325 : if (!g_spdk_enable_sgl) {
1146 [ + + + - ]: 793831 : if (!fio_qpair->zone_append_enabled) {
1147 : 793831 : rc = spdk_nvme_ns_cmd_write_with_md(ns, fio_qpair->qpair, io_u->buf, md_buf, lba,
1148 : : lba_count,
1149 : : spdk_fio_completion_cb, fio_req,
1150 : 793831 : fio_qpair->io_flags, dif_ctx->apptag_mask, dif_ctx->app_tag);
1151 : : } else {
1152 : 0 : uint64_t zslba = fio_offset_to_zslba(io_u->offset, ns);
1153 : 0 : rc = spdk_nvme_zns_zone_append_with_md(ns, fio_qpair->qpair, io_u->buf, md_buf, zslba,
1154 : : lba_count,
1155 : : spdk_fio_completion_cb, fio_req,
1156 : 0 : fio_qpair->io_flags, dif_ctx->apptag_mask, dif_ctx->app_tag);
1157 : : }
1158 : : } else {
1159 [ - + + - ]: 25494 : if (!fio_qpair->zone_append_enabled) {
1160 : : #if FIO_HAS_FDP
1161 [ - + ]: 25494 : if (spdk_unlikely(io_u->dtype)) {
1162 : 0 : ext_opts.size = SPDK_SIZEOF(&ext_opts, cdw13);
1163 : 0 : ext_opts.io_flags = fio_qpair->io_flags | (io_u->dtype << 20);
1164 : 0 : ext_opts.metadata = md_buf;
1165 : 0 : ext_opts.cdw13 = (io_u->dspec << 16);
1166 : 0 : ext_opts.apptag = dif_ctx->app_tag;
1167 : 0 : ext_opts.apptag_mask = dif_ctx->apptag_mask;
1168 : 0 : rc = spdk_nvme_ns_cmd_writev_ext(ns, fio_qpair->qpair, lba, lba_count,
1169 : : spdk_fio_completion_cb, fio_req,
1170 : : spdk_nvme_io_reset_sgl, spdk_nvme_io_next_sge, &ext_opts);
1171 : 0 : break;
1172 : : }
1173 : : #endif
1174 : 25494 : rc = spdk_nvme_ns_cmd_writev_with_md(ns, fio_qpair->qpair, lba,
1175 : : lba_count, spdk_fio_completion_cb, fio_req, fio_qpair->io_flags,
1176 : : spdk_nvme_io_reset_sgl, spdk_nvme_io_next_sge, md_buf,
1177 : 25494 : dif_ctx->apptag_mask, dif_ctx->app_tag);
1178 : : } else {
1179 : 0 : uint64_t zslba = fio_offset_to_zslba(io_u->offset, ns);
1180 : 0 : rc = spdk_nvme_zns_zone_appendv_with_md(ns, fio_qpair->qpair, zslba,
1181 : : lba_count, spdk_fio_completion_cb, fio_req, fio_qpair->io_flags,
1182 : : spdk_nvme_io_reset_sgl, spdk_nvme_io_next_sge, md_buf,
1183 : 0 : dif_ctx->apptag_mask, dif_ctx->app_tag);
1184 : : }
1185 : : }
1186 : 819325 : break;
1187 : 0 : case DDIR_TRIM:
1188 [ # # ]: 0 : if (td->io_ops->flags & FIO_ASYNCIO_SYNC_TRIM) {
1189 : 0 : do_io_u_trim(td, io_u);
1190 : 0 : io_u_mark_submit(td, 1);
1191 : 0 : io_u_mark_complete(td, 1);
1192 : 0 : return FIO_Q_COMPLETED;
1193 : : }
1194 : :
1195 : 0 : range = fio_req->dsm_range;
1196 : : #if FIO_HAS_MRT
1197 : : if (td->o.num_range == 1) {
1198 : : range->attributes.raw = 0;
1199 : : range->length = lba_count;
1200 : : range->starting_lba = lba;
1201 : : num_range = 1;
1202 : : } else {
1203 : : struct trim_range *tr = (struct trim_range *)io_u->xfer_buf;
1204 : : for (uint32_t i = 0; i < io_u->number_trim; i++) {
1205 : : range->attributes.raw = 0;
1206 : : range->length = tr->len / block_size;
1207 : : range->starting_lba = tr->start / block_size;
1208 : : range++;
1209 : : tr++;
1210 : : }
1211 : : num_range = io_u->number_trim;
1212 : : range = fio_req->dsm_range;
1213 : : }
1214 : : #else
1215 : 0 : range->attributes.raw = 0;
1216 : 0 : range->length = lba_count;
1217 : 0 : range->starting_lba = lba;
1218 : 0 : num_range = 1;
1219 : : #endif
1220 : :
1221 : 0 : rc = spdk_nvme_ns_cmd_dataset_management(ns, fio_qpair->qpair,
1222 : : SPDK_NVME_DSM_ATTR_DEALLOCATE, range, num_range,
1223 : : spdk_fio_completion_cb, fio_req);
1224 : 0 : break;
1225 : 0 : default:
1226 : 0 : assert(false);
1227 : : break;
1228 : : }
1229 : :
1230 : : /* NVMe read/write functions return -ENOMEM if there are no free requests. */
1231 [ - + ]: 1663808 : if (rc == -ENOMEM) {
1232 : 0 : return FIO_Q_BUSY;
1233 : : }
1234 : :
1235 [ - + ]: 1663808 : if (rc != 0) {
1236 : 0 : io_u->error = abs(rc);
1237 : 0 : return FIO_Q_COMPLETED;
1238 : : }
1239 : :
1240 : 1663808 : return FIO_Q_QUEUED;
1241 : : }
1242 : :
1243 : : static struct io_u *
1244 : 1663808 : spdk_fio_event(struct thread_data *td, int event)
1245 : : {
1246 : 1663808 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
1247 : :
1248 [ - + ]: 1663808 : assert(event >= 0);
1249 [ - + ]: 1663808 : assert((unsigned)event < fio_thread->iocq_count);
1250 : 1663808 : return fio_thread->iocq[event];
1251 : : }
1252 : :
1253 : : static int
1254 : 1659146 : spdk_fio_getevents(struct thread_data *td, unsigned int min,
1255 : : unsigned int max, const struct timespec *t)
1256 : : {
1257 : 1659146 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
1258 : 1659146 : struct spdk_fio_qpair *fio_qpair = NULL;
1259 : 643607 : struct timespec t0, t1;
1260 : 1659146 : uint64_t timeout = 0;
1261 : :
1262 [ - + ]: 1659146 : if (t) {
1263 : 0 : timeout = t->tv_sec * 1000000000L + t->tv_nsec;
1264 [ # # ]: 0 : clock_gettime(CLOCK_MONOTONIC_RAW, &t0);
1265 : : }
1266 : :
1267 : 1659146 : fio_thread->iocq_count = 0;
1268 : :
1269 : : /* fetch the next qpair */
1270 [ + + ]: 1659146 : if (fio_thread->fio_qpair_current) {
1271 : 1659123 : fio_qpair = TAILQ_NEXT(fio_thread->fio_qpair_current, link);
1272 : : }
1273 : :
1274 : : for (;;) {
1275 [ + - ]: 9287442 : if (fio_qpair == NULL) {
1276 : 9287442 : fio_qpair = TAILQ_FIRST(&fio_thread->fio_qpair);
1277 : : }
1278 : :
1279 [ + + ]: 16915738 : while (fio_qpair != NULL) {
1280 : : /*
1281 : : * We can be called while spdk_fio_open()s are still
1282 : : * ongoing, in which case, ->qpair can still be NULL.
1283 : : */
1284 [ - + ]: 9287442 : if (fio_qpair->qpair == NULL) {
1285 : 0 : fio_qpair = TAILQ_NEXT(fio_qpair, link);
1286 : 0 : continue;
1287 : : }
1288 : :
1289 : 9287442 : spdk_nvme_qpair_process_completions(fio_qpair->qpair, max - fio_thread->iocq_count);
1290 : :
1291 [ + + ]: 9287442 : if (fio_thread->iocq_count >= min) {
1292 : : /* reset the current handling qpair */
1293 : 1659146 : fio_thread->fio_qpair_current = fio_qpair;
1294 : 1659146 : return fio_thread->iocq_count;
1295 : : }
1296 : :
1297 : 7628296 : fio_qpair = TAILQ_NEXT(fio_qpair, link);
1298 : : }
1299 : :
1300 [ - + ]: 7628296 : if (t) {
1301 : : uint64_t elapse;
1302 : :
1303 [ # # ]: 0 : clock_gettime(CLOCK_MONOTONIC_RAW, &t1);
1304 : 0 : elapse = ((t1.tv_sec - t0.tv_sec) * 1000000000L)
1305 : 0 : + t1.tv_nsec - t0.tv_nsec;
1306 [ # # ]: 0 : if (elapse > timeout) {
1307 : 0 : break;
1308 : : }
1309 : : }
1310 : : }
1311 : :
1312 : : /* reset the current handling qpair */
1313 : 0 : fio_thread->fio_qpair_current = fio_qpair;
1314 : 0 : return fio_thread->iocq_count;
1315 : : }
1316 : :
1317 : : static int
1318 : 0 : spdk_fio_invalidate(struct thread_data *td, struct fio_file *f)
1319 : : {
1320 : : /* TODO: This should probably send a flush to the device, but for now just return successful. */
1321 : 0 : return 0;
1322 : : }
1323 : :
1324 : : #if FIO_HAS_ZBD
1325 : : static int
1326 : 0 : spdk_fio_get_zoned_model(struct thread_data *td, struct fio_file *f, enum zbd_zoned_model *model)
1327 : : {
1328 : 0 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
1329 : 0 : struct spdk_fio_qpair *fio_qpair = NULL;
1330 : 0 : const struct spdk_nvme_zns_ns_data *zns_data = NULL;
1331 : :
1332 [ # # ]: 0 : if (f->filetype != FIO_TYPE_BLOCK) {
1333 : 0 : log_info("spdk/nvme: unsupported filetype: %d\n", f->filetype);
1334 : 0 : return -EINVAL;
1335 : : }
1336 : :
1337 : 0 : fio_qpair = get_fio_qpair(fio_thread, f);
1338 [ # # ]: 0 : if (!fio_qpair) {
1339 : 0 : log_err("spdk/nvme: no ns/qpair or file_name: '%s'\n", f->file_name);
1340 : 0 : return -ENODEV;
1341 : : }
1342 : :
1343 [ # # # # ]: 0 : switch (spdk_nvme_ns_get_csi(fio_qpair->ns)) {
1344 : 0 : case SPDK_NVME_CSI_NVM:
1345 : 0 : *model = ZBD_NONE;
1346 : 0 : return 0;
1347 : :
1348 : 0 : case SPDK_NVME_CSI_KV:
1349 : 0 : log_err("spdk/nvme: KV namespace is currently not supported\n");
1350 : 0 : return -ENOSYS;
1351 : :
1352 : 0 : case SPDK_NVME_CSI_ZNS:
1353 : 0 : zns_data = spdk_nvme_zns_ns_get_data(fio_qpair->ns);
1354 [ # # ]: 0 : if (!zns_data) {
1355 : 0 : log_err("spdk/nvme: file_name: '%s', ZNS is not enabled\n", f->file_name);
1356 : 0 : return -EINVAL;
1357 : : }
1358 : :
1359 : 0 : *model = ZBD_HOST_MANAGED;
1360 : :
1361 : 0 : return 0;
1362 : : }
1363 : :
1364 : 0 : return -EINVAL;
1365 : : }
1366 : :
1367 : : static int
1368 : 0 : spdk_fio_report_zones(struct thread_data *td, struct fio_file *f, uint64_t offset,
1369 : : struct zbd_zone *zbdz, unsigned int nr_zones)
1370 : : {
1371 : 0 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
1372 : 0 : struct spdk_fio_qpair *fio_qpair = NULL;
1373 : 0 : const struct spdk_nvme_zns_ns_data *zns = NULL;
1374 : : struct spdk_nvme_zns_zone_report *report;
1375 : : struct spdk_nvme_qpair *tmp_qpair;
1376 : 0 : uint32_t report_nzones = 0, report_nzones_max, report_nbytes, mdts_nbytes;
1377 : : uint64_t zsze_nbytes, ns_nzones, lba_nbytes;
1378 : 0 : int completed = 0, err;
1379 : :
1380 : 0 : fio_qpair = get_fio_qpair(fio_thread, f);
1381 [ # # ]: 0 : if (!fio_qpair) {
1382 : 0 : log_err("spdk/nvme: no ns/qpair or file_name: '%s'\n", f->file_name);
1383 : 0 : return -ENODEV;
1384 : : }
1385 : 0 : zns = spdk_nvme_zns_ns_get_data(fio_qpair->ns);
1386 [ # # ]: 0 : if (!zns) {
1387 : 0 : log_err("spdk/nvme: file_name: '%s', zns is not enabled\n", f->file_name);
1388 : 0 : return -EINVAL;
1389 : : }
1390 : :
1391 : : /* qpair has not been allocated yet (it gets allocated in spdk_fio_open()).
1392 : : * Create a temporary qpair in order to perform report zones.
1393 : : */
1394 [ # # ]: 0 : assert(!fio_qpair->qpair);
1395 : :
1396 : 0 : tmp_qpair = spdk_nvme_ctrlr_alloc_io_qpair(fio_qpair->fio_ctrlr->ctrlr, NULL, 0);
1397 [ # # ]: 0 : if (!tmp_qpair) {
1398 : 0 : log_err("spdk/nvme: cannot allocate a temporary qpair\n");
1399 : 0 : return -EIO;
1400 : : }
1401 : :
1402 : : /** Retrieve device parameters */
1403 : 0 : mdts_nbytes = spdk_nvme_ns_get_max_io_xfer_size(fio_qpair->ns);
1404 : 0 : lba_nbytes = spdk_nvme_ns_get_sector_size(fio_qpair->ns);
1405 : 0 : zsze_nbytes = spdk_nvme_zns_ns_get_zone_size(fio_qpair->ns);
1406 : 0 : ns_nzones = spdk_nvme_zns_ns_get_num_zones(fio_qpair->ns);
1407 : :
1408 : : /** Allocate report-buffer without exceeding mdts, zbdz-storage, and what is needed */
1409 : 0 : report_nzones_max = (mdts_nbytes - sizeof(*report)) / sizeof(report->descs[0]);
1410 : 0 : report_nzones_max = spdk_min(spdk_min(report_nzones_max, nr_zones), ns_nzones);
1411 : 0 : report_nbytes = sizeof(report->descs[0]) * report_nzones_max + sizeof(*report);
1412 : 0 : report = calloc(1, report_nbytes);
1413 [ # # ]: 0 : if (!report) {
1414 : 0 : log_err("spdk/nvme: failed report_zones(): ENOMEM\n");
1415 : 0 : err = -ENOMEM;
1416 : 0 : goto exit;
1417 : : }
1418 : :
1419 [ # # ]: 0 : err = spdk_nvme_zns_report_zones(fio_qpair->ns, tmp_qpair, report, report_nbytes,
1420 : 0 : offset / lba_nbytes, SPDK_NVME_ZRA_LIST_ALL, true, pcu_cb,
1421 : : &completed);
1422 [ # # # # : 0 : if (err || pcu(tmp_qpair, &completed) || completed < 0) {
# # ]
1423 : 0 : log_err("spdk/nvme: report_zones(): err: %d, cpl: %d\n", err, completed);
1424 [ # # ]: 0 : err = err ? err : -EIO;
1425 : 0 : goto exit;
1426 : : }
1427 [ # # ]: 0 : assert(report->nr_zones <= report_nzones_max);
1428 : 0 : report_nzones = report->nr_zones;
1429 : :
1430 [ # # ]: 0 : for (uint64_t idx = 0; idx < report->nr_zones; ++idx) {
1431 : 0 : struct spdk_nvme_zns_zone_desc *zdesc = &report->descs[idx];
1432 : :
1433 : 0 : zbdz[idx].start = zdesc->zslba * lba_nbytes;
1434 : 0 : zbdz[idx].len = zsze_nbytes;
1435 : 0 : zbdz[idx].capacity = zdesc->zcap * lba_nbytes;
1436 : 0 : zbdz[idx].wp = zdesc->wp * lba_nbytes;
1437 : :
1438 [ # # ]: 0 : switch (zdesc->zt) {
1439 : 0 : case SPDK_NVME_ZONE_TYPE_SEQWR:
1440 : 0 : zbdz[idx].type = ZBD_ZONE_TYPE_SWR;
1441 : 0 : break;
1442 : :
1443 : 0 : default:
1444 : 0 : log_err("spdk/nvme: %s: inv. zone-type: 0x%x\n", f->file_name, zdesc->zt);
1445 : 0 : err = -EIO;
1446 : 0 : goto exit;
1447 : : }
1448 : :
1449 [ # # # # : 0 : switch (zdesc->zs) {
# # # # ]
1450 : 0 : case SPDK_NVME_ZONE_STATE_EMPTY:
1451 : 0 : zbdz[idx].cond = ZBD_ZONE_COND_EMPTY;
1452 : 0 : break;
1453 : 0 : case SPDK_NVME_ZONE_STATE_IOPEN:
1454 : 0 : zbdz[idx].cond = ZBD_ZONE_COND_IMP_OPEN;
1455 : 0 : break;
1456 : 0 : case SPDK_NVME_ZONE_STATE_EOPEN:
1457 : 0 : zbdz[idx].cond = ZBD_ZONE_COND_EXP_OPEN;
1458 : 0 : break;
1459 : 0 : case SPDK_NVME_ZONE_STATE_CLOSED:
1460 : 0 : zbdz[idx].cond = ZBD_ZONE_COND_CLOSED;
1461 : 0 : break;
1462 : 0 : case SPDK_NVME_ZONE_STATE_RONLY:
1463 : 0 : zbdz[idx].cond = ZBD_ZONE_COND_READONLY;
1464 : 0 : break;
1465 : 0 : case SPDK_NVME_ZONE_STATE_FULL:
1466 : 0 : zbdz[idx].cond = ZBD_ZONE_COND_FULL;
1467 : 0 : break;
1468 : 0 : case SPDK_NVME_ZONE_STATE_OFFLINE:
1469 : 0 : zbdz[idx].cond = ZBD_ZONE_COND_OFFLINE;
1470 : 0 : break;
1471 : :
1472 : 0 : default:
1473 : 0 : log_err("spdk/nvme: %s: inv. zone-state: 0x%x\n", f->file_name, zdesc->zs);
1474 : 0 : err = -EIO;
1475 : 0 : goto exit;
1476 : : }
1477 : : }
1478 : :
1479 : 0 : exit:
1480 : 0 : spdk_nvme_ctrlr_free_io_qpair(tmp_qpair);
1481 : 0 : free(report);
1482 : :
1483 [ # # ]: 0 : return err ? err : (int)report_nzones;
1484 : : }
1485 : :
1486 : : static int
1487 : 0 : spdk_fio_reset_wp(struct thread_data *td, struct fio_file *f, uint64_t offset, uint64_t length)
1488 : : {
1489 : 0 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
1490 : 0 : struct spdk_fio_qpair *fio_qpair = NULL;
1491 : 0 : const struct spdk_nvme_zns_ns_data *zns = NULL;
1492 : : uint64_t zsze_nbytes, lba_nbytes;
1493 : 0 : int err = 0;
1494 : :
1495 : 0 : fio_qpair = get_fio_qpair(fio_thread, f);
1496 [ # # ]: 0 : if (!fio_qpair) {
1497 : 0 : log_err("spdk/nvme: no ns/qpair or file_name: '%s'\n", f->file_name);
1498 : 0 : return -ENODEV;
1499 : : }
1500 : 0 : zns = spdk_nvme_zns_ns_get_data(fio_qpair->ns);
1501 [ # # ]: 0 : if (!zns) {
1502 : 0 : log_err("spdk/nvme: file_name: '%s', zns is not enabled\n", f->file_name);
1503 : 0 : return -EINVAL;
1504 : : }
1505 : 0 : zsze_nbytes = spdk_nvme_zns_ns_get_zone_size(fio_qpair->ns);
1506 : 0 : lba_nbytes = spdk_nvme_ns_get_sector_size(fio_qpair->ns);
1507 : :
1508 : : /** check the assumption that offset is valid zone-start lba */
1509 [ # # # # ]: 0 : if (offset % zsze_nbytes) {
1510 : 0 : log_err("spdk/nvme: offset: %zu is not a valid zslba\n", offset);
1511 : 0 : return -EINVAL;
1512 : : }
1513 : :
1514 [ # # ]: 0 : for (uint64_t cur = offset; cur < offset + length; cur += zsze_nbytes) {
1515 : 0 : int completed = 0;
1516 : :
1517 [ # # ]: 0 : err = spdk_nvme_zns_reset_zone(fio_qpair->ns, fio_qpair->qpair, cur / lba_nbytes,
1518 : : false, pcu_cb, &completed);
1519 [ # # # # : 0 : if (err || pcu(fio_qpair->qpair, &completed) || completed < 0) {
# # ]
1520 : 0 : log_err("spdk/nvme: zns_reset_zone(): err: %d, cpl: %d\n", err, completed);
1521 [ # # ]: 0 : err = err ? err : -EIO;
1522 : 0 : break;
1523 : : }
1524 : : }
1525 : :
1526 : 0 : return err;
1527 : : }
1528 : : #endif
1529 : :
1530 : : #if FIO_IOOPS_VERSION >= 30
1531 : : static int
1532 : 0 : spdk_fio_get_max_open_zones(struct thread_data *td, struct fio_file *f,
1533 : : unsigned int *max_open_zones)
1534 : : {
1535 : 0 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
1536 : 0 : struct spdk_fio_qpair *fio_qpair = NULL;
1537 : :
1538 : 0 : fio_qpair = get_fio_qpair(fio_thread, f);
1539 [ # # ]: 0 : if (!fio_qpair) {
1540 : 0 : log_err("spdk/nvme: no ns/qpair or file_name: '%s'\n", f->file_name);
1541 : 0 : return -ENODEV;
1542 : : }
1543 : :
1544 : 0 : *max_open_zones = spdk_nvme_zns_ns_get_max_open_zones(fio_qpair->ns);
1545 : :
1546 : 0 : return 0;
1547 : : }
1548 : : #endif
1549 : :
1550 : : #if FIO_HAS_FDP
1551 : : static int
1552 : 0 : spdk_fio_fdp_fetch_ruhs(struct thread_data *td, struct fio_file *f,
1553 : : struct fio_ruhs_info *fruhs_info)
1554 : : {
1555 : 0 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
1556 : 0 : struct spdk_fio_qpair *fio_qpair = NULL;
1557 : : struct spdk_nvme_qpair *tmp_qpair;
1558 : : struct {
1559 : : struct spdk_nvme_fdp_ruhs ruhs;
1560 : : struct spdk_nvme_fdp_ruhs_desc desc[128];
1561 : 0 : } fdp_ruhs;
1562 : : uint16_t idx;
1563 : 0 : int completed = 0, err;
1564 : :
1565 : 0 : fio_qpair = get_fio_qpair(fio_thread, f);
1566 [ # # ]: 0 : if (!fio_qpair) {
1567 : 0 : log_err("spdk/nvme: no ns/qpair or file_name: '%s'\n", f->file_name);
1568 : 0 : return -ENODEV;
1569 : : }
1570 : :
1571 : : /* qpair has not been allocated yet (it gets allocated in spdk_fio_open()).
1572 : : * Create a temporary qpair in order to perform report zones.
1573 : : */
1574 [ # # ]: 0 : assert(!fio_qpair->qpair);
1575 : :
1576 : 0 : tmp_qpair = spdk_nvme_ctrlr_alloc_io_qpair(fio_qpair->fio_ctrlr->ctrlr, NULL, 0);
1577 [ # # ]: 0 : if (!tmp_qpair) {
1578 : 0 : log_err("spdk/nvme: cannot allocate a temporary qpair\n");
1579 : 0 : return -EIO;
1580 : : }
1581 : :
1582 : 0 : err = spdk_nvme_ns_cmd_io_mgmt_recv(fio_qpair->ns, tmp_qpair, &fdp_ruhs, sizeof(fdp_ruhs),
1583 : : SPDK_NVME_FDP_IO_MGMT_RECV_RUHS, 0, pcu_cb, &completed);
1584 [ # # # # : 0 : if (err || pcu(tmp_qpair, &completed) || completed < 0) {
# # ]
1585 : 0 : log_err("spdk/nvme: fetch_ruhs(): err: %d, cpl: %d\n", err, completed);
1586 [ # # ]: 0 : err = err ? err : -EIO;
1587 : 0 : goto exit;
1588 : : }
1589 : :
1590 : 0 : fruhs_info->nr_ruhs = fdp_ruhs.ruhs.nruhsd;
1591 [ # # ]: 0 : for (idx = 0; idx < fdp_ruhs.ruhs.nruhsd; idx++) {
1592 : 0 : fruhs_info->plis[idx] = fdp_ruhs.desc[idx].pid;
1593 : : }
1594 : :
1595 : 0 : exit:
1596 : 0 : spdk_nvme_ctrlr_free_io_qpair(tmp_qpair);
1597 : :
1598 : 0 : return err;
1599 : : }
1600 : : #endif
1601 : :
1602 : : static void
1603 : 23 : spdk_fio_cleanup(struct thread_data *td)
1604 : : {
1605 : 23 : struct spdk_fio_thread *fio_thread = td->io_ops_data;
1606 : : struct spdk_fio_qpair *fio_qpair, *fio_qpair_tmp;
1607 : 23 : struct spdk_fio_options *fio_options = td->eo;
1608 : :
1609 [ - + ]: 23 : if (fio_options->spdk_tracing) {
1610 : 0 : spdk_trace_unregister_user_thread();
1611 : : }
1612 : :
1613 [ + + ]: 46 : TAILQ_FOREACH_SAFE(fio_qpair, &fio_thread->fio_qpair, link, fio_qpair_tmp) {
1614 [ - + ]: 23 : TAILQ_REMOVE(&fio_thread->fio_qpair, fio_qpair, link);
1615 : 23 : free(fio_qpair);
1616 : : }
1617 : :
1618 : 23 : free(fio_thread->iocq);
1619 : 23 : free(fio_thread);
1620 : :
1621 [ - + ]: 23 : pthread_mutex_lock(&g_mutex);
1622 : 23 : g_td_count--;
1623 [ + - ]: 23 : if (g_td_count == 0) {
1624 : : struct spdk_fio_ctrlr *fio_ctrlr, *fio_ctrlr_tmp;
1625 : 23 : struct spdk_nvme_detach_ctx *detach_ctx = NULL;
1626 : :
1627 [ + + ]: 46 : TAILQ_FOREACH_SAFE(fio_ctrlr, &g_ctrlrs, link, fio_ctrlr_tmp) {
1628 [ - + ]: 23 : TAILQ_REMOVE(&g_ctrlrs, fio_ctrlr, link);
1629 : 23 : spdk_nvme_detach_async(fio_ctrlr->ctrlr, &detach_ctx);
1630 : 23 : free(fio_ctrlr);
1631 : : }
1632 : :
1633 [ + - ]: 23 : if (detach_ctx) {
1634 : 23 : spdk_nvme_detach_poll(detach_ctx);
1635 : : }
1636 : :
1637 [ + + ]: 23 : if (fio_options->enable_vmd) {
1638 : 1 : spdk_vmd_fini();
1639 : : }
1640 : : }
1641 [ - + ]: 23 : pthread_mutex_unlock(&g_mutex);
1642 [ + - ]: 23 : if (TAILQ_EMPTY(&g_ctrlrs)) {
1643 [ + - ]: 23 : if (pthread_cancel(g_ctrlr_thread_id) == 0) {
1644 : 23 : pthread_join(g_ctrlr_thread_id, NULL);
1645 : : }
1646 : : }
1647 : 23 : }
1648 : :
1649 : : /* This function enables addition of SPDK parameters to the fio config
1650 : : * Adding new parameters by defining them here and defining a callback
1651 : : * function to read the parameter value. */
1652 : : static struct fio_option options[] = {
1653 : : {
1654 : : .name = "enable_wrr",
1655 : : .lname = "Enable weighted round robin (WRR) for IO submission queues",
1656 : : .type = FIO_OPT_INT,
1657 : : .off1 = offsetof(struct spdk_fio_options, enable_wrr),
1658 : : .def = "0",
1659 : : .help = "Enable weighted round robin (WRR) for IO submission queues",
1660 : : .category = FIO_OPT_C_ENGINE,
1661 : : .group = FIO_OPT_G_INVALID,
1662 : : },
1663 : : {
1664 : : .name = "arbitration_burst",
1665 : : .lname = "Arbitration Burst",
1666 : : .type = FIO_OPT_INT,
1667 : : .off1 = offsetof(struct spdk_fio_options, arbitration_burst),
1668 : : .def = "0",
1669 : : .help = "Arbitration Burst used for WRR (valid range from 0 - 7)",
1670 : : .category = FIO_OPT_C_ENGINE,
1671 : : .group = FIO_OPT_G_INVALID,
1672 : : },
1673 : : {
1674 : : .name = "low_weight",
1675 : : .lname = "low_weight for WRR",
1676 : : .type = FIO_OPT_INT,
1677 : : .off1 = offsetof(struct spdk_fio_options, low_weight),
1678 : : .def = "0",
1679 : : .help = "low_weight used for WRR (valid range from 0 - 255)",
1680 : : .category = FIO_OPT_C_ENGINE,
1681 : : .group = FIO_OPT_G_INVALID,
1682 : : },
1683 : : {
1684 : : .name = "medium_weight",
1685 : : .lname = "medium_weight for WRR",
1686 : : .type = FIO_OPT_INT,
1687 : : .off1 = offsetof(struct spdk_fio_options, medium_weight),
1688 : : .def = "0",
1689 : : .help = "medium weight used for WRR (valid range from 0 - 255)",
1690 : : .category = FIO_OPT_C_ENGINE,
1691 : : .group = FIO_OPT_G_INVALID,
1692 : : },
1693 : : {
1694 : : .name = "high_weight",
1695 : : .lname = "high_weight for WRR",
1696 : : .type = FIO_OPT_INT,
1697 : : .off1 = offsetof(struct spdk_fio_options, high_weight),
1698 : : .def = "0",
1699 : : .help = "high weight used for WRR (valid range from 0 - 255)",
1700 : : .category = FIO_OPT_C_ENGINE,
1701 : : .group = FIO_OPT_G_INVALID,
1702 : : },
1703 : : {
1704 : : .name = "wrr_priority",
1705 : : .lname = "priority used for WRR",
1706 : : .type = FIO_OPT_INT,
1707 : : .off1 = offsetof(struct spdk_fio_options, wrr_priority),
1708 : : .def = "0",
1709 : : .help = "priority used for WRR (valid range from 0-3)",
1710 : : .category = FIO_OPT_C_ENGINE,
1711 : : .group = FIO_OPT_G_INVALID,
1712 : : },
1713 : : {
1714 : : .name = "mem_size_mb",
1715 : : .lname = "Memory size in MB",
1716 : : .type = FIO_OPT_INT,
1717 : : .off1 = offsetof(struct spdk_fio_options, mem_size),
1718 : : .def = "0",
1719 : : .help = "Memory Size for SPDK (MB)",
1720 : : .category = FIO_OPT_C_ENGINE,
1721 : : .group = FIO_OPT_G_INVALID,
1722 : : },
1723 : : {
1724 : : .name = "shm_id",
1725 : : .lname = "shared memory ID",
1726 : : .type = FIO_OPT_INT,
1727 : : .off1 = offsetof(struct spdk_fio_options, shm_id),
1728 : : .def = "-1",
1729 : : .help = "Shared Memory ID",
1730 : : .category = FIO_OPT_C_ENGINE,
1731 : : .group = FIO_OPT_G_INVALID,
1732 : : },
1733 : : {
1734 : : .name = "enable_sgl",
1735 : : .lname = "SGL used for I/O commands",
1736 : : .type = FIO_OPT_INT,
1737 : : .off1 = offsetof(struct spdk_fio_options, enable_sgl),
1738 : : .def = "0",
1739 : : .help = "SGL Used for I/O Commands (enable_sgl=1 or enable_sgl=0)",
1740 : : .category = FIO_OPT_C_ENGINE,
1741 : : .group = FIO_OPT_G_INVALID,
1742 : : },
1743 : : {
1744 : : .name = "sge_size",
1745 : : .lname = "SGL size used for I/O commands",
1746 : : .type = FIO_OPT_INT,
1747 : : .off1 = offsetof(struct spdk_fio_options, sge_size),
1748 : : .def = "4096",
1749 : : .help = "SGL size in bytes for I/O Commands (default 4096)",
1750 : : .category = FIO_OPT_C_ENGINE,
1751 : : .group = FIO_OPT_G_INVALID,
1752 : : },
1753 : : {
1754 : : .name = "bit_bucket_data_len",
1755 : : .lname = "Amount of data used for Bit Bucket",
1756 : : .type = FIO_OPT_INT,
1757 : : .off1 = offsetof(struct spdk_fio_options, bit_bucket_data_len),
1758 : : .def = "0",
1759 : : .help = "Bit Bucket Data Length for READ commands (disabled by default)",
1760 : : .category = FIO_OPT_C_ENGINE,
1761 : : .group = FIO_OPT_G_INVALID,
1762 : : },
1763 : : {
1764 : : .name = "hostnqn",
1765 : : .lname = "Host NQN to use when connecting to controllers.",
1766 : : .type = FIO_OPT_STR_STORE,
1767 : : .off1 = offsetof(struct spdk_fio_options, hostnqn),
1768 : : .help = "Host NQN",
1769 : : .category = FIO_OPT_C_ENGINE,
1770 : : .group = FIO_OPT_G_INVALID,
1771 : : },
1772 : : {
1773 : : .name = "pi_act",
1774 : : .lname = "Protection Information Action",
1775 : : .type = FIO_OPT_INT,
1776 : : .off1 = offsetof(struct spdk_fio_options, pi_act),
1777 : : .def = "1",
1778 : : .help = "Protection Information Action bit (pi_act=1 or pi_act=0)",
1779 : : .category = FIO_OPT_C_ENGINE,
1780 : : .group = FIO_OPT_G_INVALID,
1781 : : },
1782 : : {
1783 : : .name = "pi_chk",
1784 : : .lname = "Protection Information Check(GUARD|REFTAG|APPTAG)",
1785 : : .type = FIO_OPT_STR_STORE,
1786 : : .off1 = offsetof(struct spdk_fio_options, pi_chk),
1787 : : .def = NULL,
1788 : : .help = "Control of Protection Information Checking (pi_chk=GUARD|REFTAG|APPTAG)",
1789 : : .category = FIO_OPT_C_ENGINE,
1790 : : .group = FIO_OPT_G_INVALID,
1791 : : },
1792 : : {
1793 : : .name = "md_per_io_size",
1794 : : .lname = "Separate Metadata Buffer Size per I/O",
1795 : : .type = FIO_OPT_INT,
1796 : : .off1 = offsetof(struct spdk_fio_options, md_per_io_size),
1797 : : .def = "4096",
1798 : : .help = "Size of separate metadata buffer per I/O (Default: 4096)",
1799 : : .category = FIO_OPT_C_ENGINE,
1800 : : .group = FIO_OPT_G_INVALID,
1801 : : },
1802 : : {
1803 : : .name = "apptag",
1804 : : .lname = "Application Tag used in Protection Information",
1805 : : .type = FIO_OPT_INT,
1806 : : .off1 = offsetof(struct spdk_fio_options, apptag),
1807 : : .def = "0x1234",
1808 : : .help = "Application Tag used in Protection Information field (Default: 0x1234)",
1809 : : .category = FIO_OPT_C_ENGINE,
1810 : : .group = FIO_OPT_G_INVALID,
1811 : : },
1812 : : {
1813 : : .name = "apptag_mask",
1814 : : .lname = "Application Tag Mask",
1815 : : .type = FIO_OPT_INT,
1816 : : .off1 = offsetof(struct spdk_fio_options, apptag_mask),
1817 : : .def = "0xffff",
1818 : : .help = "Application Tag Mask used with Application Tag (Default: 0xffff)",
1819 : : .category = FIO_OPT_C_ENGINE,
1820 : : .group = FIO_OPT_G_INVALID,
1821 : : },
1822 : : {
1823 : : .name = "digest_enable",
1824 : : .lname = "PDU digest choice for NVMe/TCP Transport(NONE|HEADER|DATA|BOTH)",
1825 : : .type = FIO_OPT_STR_STORE,
1826 : : .off1 = offsetof(struct spdk_fio_options, digest_enable),
1827 : : .def = NULL,
1828 : : .help = "Control the NVMe/TCP control(digest_enable=NONE|HEADER|DATA|BOTH)",
1829 : : .category = FIO_OPT_C_ENGINE,
1830 : : .group = FIO_OPT_G_INVALID,
1831 : : },
1832 : : {
1833 : : .name = "enable_vmd",
1834 : : .lname = "Enable VMD enumeration",
1835 : : .type = FIO_OPT_INT,
1836 : : .off1 = offsetof(struct spdk_fio_options, enable_vmd),
1837 : : .def = "0",
1838 : : .help = "Enable VMD enumeration (enable_vmd=1 or enable_vmd=0)",
1839 : : .category = FIO_OPT_C_ENGINE,
1840 : : .group = FIO_OPT_G_INVALID,
1841 : : },
1842 : : {
1843 : : .name = "initial_zone_reset",
1844 : : .lname = "Reset Zones on initialization",
1845 : : .type = FIO_OPT_INT,
1846 : : .off1 = offsetof(struct spdk_fio_options, initial_zone_reset),
1847 : : .def = "0",
1848 : : .help = "Reset Zones on initialization (0=disable, 1=Reset All Zones)",
1849 : : .category = FIO_OPT_C_ENGINE,
1850 : : .group = FIO_OPT_G_INVALID,
1851 : : },
1852 : : {
1853 : : .name = "zone_append",
1854 : : .lname = "Use zone append instead of write",
1855 : : .type = FIO_OPT_INT,
1856 : : .off1 = offsetof(struct spdk_fio_options, zone_append),
1857 : : .def = "0",
1858 : : .help = "Use zone append instead of write (1=zone append, 0=write)",
1859 : : .category = FIO_OPT_C_ENGINE,
1860 : : .group = FIO_OPT_G_INVALID,
1861 : : },
1862 : : {
1863 : : .name = "print_qid_mappings",
1864 : : .lname = "Print job-to-qid mappings",
1865 : : .type = FIO_OPT_INT,
1866 : : .off1 = offsetof(struct spdk_fio_options, print_qid_mappings),
1867 : : .def = "0",
1868 : : .help = "Print job-to-qid mappings (0=disable, 1=enable)",
1869 : : .category = FIO_OPT_C_ENGINE,
1870 : : .group = FIO_OPT_G_INVALID,
1871 : : },
1872 : : {
1873 : : .name = "log_flags",
1874 : : .lname = "log_flags",
1875 : : .type = FIO_OPT_STR_STORE,
1876 : : .off1 = offsetof(struct spdk_fio_options, log_flags),
1877 : : .help = "Enable log flags (comma-separated list)",
1878 : : .category = FIO_OPT_C_ENGINE,
1879 : : .group = FIO_OPT_G_INVALID,
1880 : : },
1881 : : {
1882 : : .name = "spdk_tracing",
1883 : : .lname = "Enable SPDK Tracing",
1884 : : .type = FIO_OPT_INT,
1885 : : .off1 = offsetof(struct spdk_fio_options, spdk_tracing),
1886 : : .def = "0",
1887 : : .help = "SPDK Tracing (0=disable, 1=enable)",
1888 : : .category = FIO_OPT_C_ENGINE,
1889 : : .group = FIO_OPT_G_INVALID,
1890 : : },
1891 : : {
1892 : : .name = NULL,
1893 : : },
1894 : : };
1895 : :
1896 : : /* FIO imports this structure using dlsym */
1897 : : struct ioengine_ops ioengine = {
1898 : : .name = "spdk",
1899 : : .version = FIO_IOOPS_VERSION,
1900 : : .queue = spdk_fio_queue,
1901 : : .getevents = spdk_fio_getevents,
1902 : : .event = spdk_fio_event,
1903 : : .cleanup = spdk_fio_cleanup,
1904 : : .open_file = spdk_fio_open,
1905 : : .close_file = spdk_fio_close,
1906 : : .invalidate = spdk_fio_invalidate,
1907 : : .iomem_alloc = spdk_fio_iomem_alloc,
1908 : : .iomem_free = spdk_fio_iomem_free,
1909 : : .setup = spdk_fio_setup,
1910 : : .init = spdk_fio_init,
1911 : : .io_u_init = spdk_fio_io_u_init,
1912 : : .io_u_free = spdk_fio_io_u_free,
1913 : : #if FIO_HAS_ZBD
1914 : : .get_zoned_model = spdk_fio_get_zoned_model,
1915 : : .report_zones = spdk_fio_report_zones,
1916 : : .reset_wp = spdk_fio_reset_wp,
1917 : : #endif
1918 : : #if FIO_IOOPS_VERSION >= 30
1919 : : .get_max_open_zones = spdk_fio_get_max_open_zones,
1920 : : #endif
1921 : : #if FIO_HAS_FDP
1922 : : .fdp_fetch_ruhs = spdk_fio_fdp_fetch_ruhs,
1923 : : #endif
1924 : : #if FIO_HAS_MRT
1925 : : .flags = FIO_RAWIO | FIO_NOEXTEND | FIO_NODISKUTIL | FIO_MEMALIGN | FIO_DISKLESSIO | FIO_MULTI_RANGE_TRIM,
1926 : : #else
1927 : : .flags = FIO_RAWIO | FIO_NOEXTEND | FIO_NODISKUTIL | FIO_MEMALIGN | FIO_DISKLESSIO,
1928 : : #endif
1929 : : .options = options,
1930 : : .option_struct_size = sizeof(struct spdk_fio_options),
1931 : : };
1932 : :
1933 : : static void fio_init
1934 : 23 : fio_spdk_register(void)
1935 : : {
1936 : 23 : register_ioengine(&ioengine);
1937 : 23 : }
1938 : :
1939 : : static void fio_exit
1940 : 23 : fio_spdk_unregister(void)
1941 : : {
1942 [ + + + - ]: 23 : if (g_spdk_env_initialized) {
1943 : 23 : spdk_trace_cleanup();
1944 : 23 : spdk_env_fini();
1945 : : }
1946 : :
1947 : 23 : unregister_ioengine(&ioengine);
1948 : 23 : }
1949 : :
1950 : 23 : SPDK_LOG_REGISTER_COMPONENT(fio_nvme)
|