Line data Source code
1 : /* SPDX-License-Identifier: BSD-3-Clause
2 : * Copyright (C) 2016 Intel Corporation.
3 : * All rights reserved.
4 : * Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5 : */
6 :
7 : /** \file
8 : * Block Device Module Interface
9 : *
10 : * For information on how to write a bdev module, see @ref bdev_module.
11 : */
12 :
13 : #ifndef SPDK_BDEV_MODULE_H
14 : #define SPDK_BDEV_MODULE_H
15 :
16 : #include "spdk/stdinc.h"
17 :
18 : #include "spdk/bdev.h"
19 : #include "spdk/bdev_zone.h"
20 : #include "spdk/log.h"
21 : #include "spdk/queue.h"
22 : #include "spdk/scsi_spec.h"
23 : #include "spdk/thread.h"
24 : #include "spdk/tree.h"
25 : #include "spdk/util.h"
26 : #include "spdk/uuid.h"
27 :
28 : #ifdef __cplusplus
29 : extern "C" {
30 : #endif
31 :
32 : #define SPDK_BDEV_CLAIM_NAME_LEN 32
33 :
34 : /* This parameter is best defined for bdevs that share an underlying bdev,
35 : * such as multiple lvol bdevs sharing an nvme device, to avoid unnecessarily
36 : * resetting the underlying bdev and affecting other bdevs that are sharing it. */
37 : #define SPDK_BDEV_RESET_IO_DRAIN_RECOMMENDED_VALUE 5
38 :
39 : /** Block device module */
40 : struct spdk_bdev_module {
41 : /**
42 : * Initialization function for the module. Called by the bdev library
43 : * during startup.
44 : *
45 : * Modules are required to define this function.
46 : */
47 : int (*module_init)(void);
48 :
49 : /**
50 : * Optional callback for modules that require notification of when
51 : * the bdev subsystem has completed initialization.
52 : *
53 : * Modules are not required to define this function.
54 : */
55 : void (*init_complete)(void);
56 :
57 : /**
58 : * Optional callback for modules that require notification of when
59 : * the bdev subsystem is starting the fini process. Called by
60 : * the bdev library before starting to unregister the bdevs.
61 : *
62 : * If a module claimed a bdev without presenting virtual bdevs on top of it,
63 : * it has to release that claim during this call.
64 : *
65 : * Modules are not required to define this function.
66 : */
67 : void (*fini_start)(void);
68 :
69 : /**
70 : * Finish function for the module. Called by the bdev library
71 : * after all bdevs for all modules have been unregistered. This allows
72 : * the module to do any final cleanup before the bdev library finishes operation.
73 : *
74 : * Modules are not required to define this function.
75 : */
76 : void (*module_fini)(void);
77 :
78 : /**
79 : * Function called to return a text string representing the module-level
80 : * JSON RPCs required to regenerate the current configuration. This will
81 : * include module-level configuration options, or methods to construct
82 : * bdevs when one RPC may generate multiple bdevs (for example, an NVMe
83 : * controller with multiple namespaces).
84 : *
85 : * Per-bdev JSON RPCs (where one "construct" RPC always creates one bdev)
86 : * may be implemented here, or by the bdev's write_config_json function -
87 : * but not both. Bdev module implementers may choose which mechanism to
88 : * use based on the module's design.
89 : *
90 : * \return 0 on success or Bdev specific negative error code.
91 : */
92 : int (*config_json)(struct spdk_json_write_ctx *w);
93 :
94 : /** Name for the modules being defined. */
95 : const char *name;
96 :
97 : /**
98 : * Returns the allocation size required for the backend for uses such as local
99 : * command structs, local SGL, iovecs, or other user context.
100 : */
101 : int (*get_ctx_size)(void);
102 :
103 : /**
104 : * First notification that a bdev should be examined by a virtual bdev module.
105 : * Virtual bdev modules may use this to examine newly-added bdevs and automatically
106 : * create their own vbdevs, but no I/O to device can be send to bdev at this point.
107 : * Only vbdevs based on config files can be created here. This callback must make
108 : * its decision to claim the module synchronously.
109 : * It must also call spdk_bdev_module_examine_done() before returning. If the module
110 : * needs to perform asynchronous operations such as I/O after claiming the bdev,
111 : * it may define an examine_disk callback. The examine_disk callback will then
112 : * be called immediately after the examine_config callback returns.
113 : */
114 : void (*examine_config)(struct spdk_bdev *bdev);
115 :
116 : /**
117 : * Second notification that a bdev should be examined by a virtual bdev module.
118 : * Virtual bdev modules may use this to examine newly-added bdevs and automatically
119 : * create their own vbdevs. This callback may use I/O operations and finish asynchronously.
120 : * Once complete spdk_bdev_module_examine_done() must be called.
121 : */
122 : void (*examine_disk)(struct spdk_bdev *bdev);
123 :
124 : /**
125 : * Denotes if the module_init function may complete asynchronously. If set to true,
126 : * the module initialization has to be explicitly completed by calling
127 : * spdk_bdev_module_init_done().
128 : */
129 : bool async_init;
130 :
131 : /**
132 : * Denotes if the module_fini function may complete asynchronously.
133 : * If set to true finishing has to be explicitly completed by calling
134 : * spdk_bdev_module_fini_done().
135 : */
136 : bool async_fini;
137 :
138 : /**
139 : * Denotes if the fini_start function may complete asynchronously.
140 : * If set to true finishing has to be explicitly completed by calling
141 : * spdk_bdev_module_fini_start_done().
142 : */
143 : bool async_fini_start;
144 :
145 : /**
146 : * Fields that are used by the internal bdev subsystem. Bdev modules
147 : * must not read or write to these fields.
148 : */
149 : struct __bdev_module_internal_fields {
150 : /**
151 : * Protects action_in_progress and quiesced_ranges.
152 : * Take no locks while holding this one.
153 : */
154 : struct spdk_spinlock spinlock;
155 :
156 : /**
157 : * Count of bdev inits/examinations in progress. Used by generic bdev
158 : * layer and must not be modified by bdev modules.
159 : *
160 : * \note Used internally by bdev subsystem, don't change this value in bdev module.
161 : */
162 : uint32_t action_in_progress;
163 :
164 : /**
165 : * List of quiesced lba ranges in all bdevs of this module.
166 : */
167 : TAILQ_HEAD(, lba_range) quiesced_ranges;
168 :
169 : TAILQ_ENTRY(spdk_bdev_module) tailq;
170 : } internal;
171 : };
172 :
173 : /** Claim types */
174 : enum spdk_bdev_claim_type {
175 : /* Not claimed. Must not be used to request a claim. */
176 : SPDK_BDEV_CLAIM_NONE = 0,
177 :
178 : /**
179 : * Exclusive writer, with allowances for legacy behavior. This matches the behavior of
180 : * `spdk_bdev_module_claim_bdev()` as of SPDK 22.09. New consumer should use
181 : * SPDK_BDEV_CLAIM_READ_MANY_WRITE_ONE instead.
182 : */
183 : SPDK_BDEV_CLAIM_EXCL_WRITE,
184 :
185 : /**
186 : * The descriptor passed with this claim request is the only writer. Other claimless readers
187 : * are allowed.
188 : */
189 : SPDK_BDEV_CLAIM_READ_MANY_WRITE_ONE,
190 :
191 : /**
192 : * Any number of readers, no writers. Readers without a claim are allowed.
193 : */
194 : SPDK_BDEV_CLAIM_READ_MANY_WRITE_NONE,
195 :
196 : /**
197 : * Any number of writers with matching shared_claim_key. After the first writer establishes
198 : * a claim, future aspiring writers should open read-only and pass the read-only descriptor.
199 : * If the shared claim is granted to the aspiring writer, the descriptor will be upgraded to
200 : * read-write.
201 : */
202 : SPDK_BDEV_CLAIM_READ_MANY_WRITE_SHARED
203 : };
204 :
205 : /** Options used when requesting a claim. */
206 : struct spdk_bdev_claim_opts {
207 : /* Size of this structure in bytes */
208 : size_t opts_size;
209 : /**
210 : * An arbitrary name for the claim. If set, it should be a string suitable for printing in
211 : * error messages. Must be '\0' terminated.
212 : */
213 : char name[SPDK_BDEV_CLAIM_NAME_LEN];
214 : /**
215 : * Used with SPDK_BDEV_CLAIM_READ_MANY_WRITE_SHARED claims. Any non-zero value is considered
216 : * a key.
217 : */
218 : uint64_t shared_claim_key;
219 : };
220 : SPDK_STATIC_ASSERT(sizeof(struct spdk_bdev_claim_opts) == 48, "Incorrect size");
221 :
222 : /**
223 : * Retrieve the name of the bdev module claim type. The mapping between claim types and their names
224 : * is:
225 : *
226 : * SPDK_BDEV_CLAIM_NONE "not_claimed"
227 : * SPDK_BDEV_CLAIM_EXCL_WRITE "exclusive_write"
228 : * SPDK_BDEV_CLAIM_READ_MANY_WRITE_ONE "read_many_write_one"
229 : * SPDK_BDEV_CLAIM_READ_MANY_WRITE_NONE "read_many_write_none"
230 : * SPDK_BDEV_CLAIM_READ_MANY_WRITE_SHARED "read_many_write_shared"
231 : *
232 : * Any other value will return "invalid_claim".
233 : *
234 : * \param claim_type The claim type.
235 : * \return A string that describes the claim type.
236 : */
237 : const char *spdk_bdev_claim_get_name(enum spdk_bdev_claim_type claim_type);
238 :
239 : /**
240 : * Initialize bdev module claim options structure.
241 : *
242 : * \param opts The structure to initialize.
243 : * \param size The size of *opts.
244 : */
245 : void spdk_bdev_claim_opts_init(struct spdk_bdev_claim_opts *opts, size_t size);
246 :
247 : /**
248 : * Claim the bdev referenced by the open descriptor. The claim is released as the descriptor is
249 : * closed.
250 : *
251 : * \param desc An open bdev descriptor. Some claim types may upgrade this from read-only to
252 : * read-write.
253 : * \param type The type of claim to establish.
254 : * \param opts NULL or options required by the particular claim type.
255 : * \param module The bdev module making this claim.
256 : * \return 0 on success
257 : * \return -ENOMEM if insufficient memory to track the claim
258 : * \return -EBUSY if the claim cannot be granted due to a conflict
259 : * \return -EINVAL if the claim type required options that were not passed or required parameters
260 : * were NULL.
261 : */
262 : int spdk_bdev_module_claim_bdev_desc(struct spdk_bdev_desc *desc,
263 : enum spdk_bdev_claim_type type,
264 : struct spdk_bdev_claim_opts *opts,
265 : struct spdk_bdev_module *module);
266 :
267 : /**
268 : * Called by a bdev module to lay exclusive claim to a bdev.
269 : *
270 : * Also upgrades that bdev's descriptor to have write access if desc
271 : * is not NULL.
272 : *
273 : * \param bdev Block device to be claimed.
274 : * \param desc Descriptor for the above block device or NULL.
275 : * \param module Bdev module attempting to claim bdev.
276 : *
277 : * \return 0 on success
278 : * \return -EPERM if the bdev is already claimed by another module.
279 : */
280 : int spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
281 : struct spdk_bdev_module *module);
282 :
283 : /**
284 : * Called to release a write claim on a block device.
285 : *
286 : * \param bdev Block device to be released.
287 : */
288 : void spdk_bdev_module_release_bdev(struct spdk_bdev *bdev);
289 :
290 : /* Libraries may define __SPDK_BDEV_MODULE_ONLY so that they include
291 : * only the struct spdk_bdev_module definition, and the relevant APIs
292 : * to claim/release a bdev. This may be useful in some cases to avoid
293 : * abidiff errors related to including the struct spdk_bdev structure
294 : * unnecessarily.
295 : */
296 : #ifndef __SPDK_BDEV_MODULE_ONLY
297 :
298 : typedef void (*spdk_bdev_unregister_cb)(void *cb_arg, int rc);
299 :
300 : /**
301 : * Function table for a block device backend.
302 : *
303 : * The backend block device function table provides a set of APIs to allow
304 : * communication with a backend. The main commands are read/write API
305 : * calls for I/O via submit_request.
306 : */
307 : struct spdk_bdev_fn_table {
308 : /** Destroy the backend block device object. If the destruct process
309 : * for the bdev is asynchronous, return 1 from this function, and
310 : * then call spdk_bdev_destruct_done() once the async work is
311 : * complete. If the destruct process is synchronous, return 0 if
312 : * successful, or <0 if unsuccessful.
313 : */
314 : int (*destruct)(void *ctx);
315 :
316 : /** Process the IO. */
317 : void (*submit_request)(struct spdk_io_channel *ch, struct spdk_bdev_io *);
318 :
319 : /** Check if the block device supports a specific I/O type. */
320 : bool (*io_type_supported)(void *ctx, enum spdk_bdev_io_type);
321 :
322 : /** Get an I/O channel for the specific bdev for the calling thread. */
323 : struct spdk_io_channel *(*get_io_channel)(void *ctx);
324 :
325 : /**
326 : * Output driver-specific information to a JSON stream. Optional - may be NULL.
327 : *
328 : * The JSON write context will be initialized with an open object, so the bdev
329 : * driver should write a name (based on the driver name) followed by a JSON value
330 : * (most likely another nested object).
331 : */
332 : int (*dump_info_json)(void *ctx, struct spdk_json_write_ctx *w);
333 :
334 : /**
335 : * Output bdev-specific RPC configuration to a JSON stream. Optional - may be NULL.
336 : *
337 : * This function should only be implemented for bdevs which can be configured
338 : * independently of other bdevs. For example, RPCs to create a bdev for an NVMe
339 : * namespace may not be generated by this function, since enumerating an NVMe
340 : * namespace requires attaching to an NVMe controller, and that controller may
341 : * contain multiple namespaces. The spdk_bdev_module's config_json function should
342 : * be used instead for these cases.
343 : *
344 : * The JSON write context will be initialized with an open object, so the bdev
345 : * driver should write all data necessary to recreate this bdev by invoking
346 : * constructor method. No other data should be written.
347 : */
348 : void (*write_config_json)(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w);
349 :
350 : /** Get spin-time per I/O channel in microseconds.
351 : * Optional - may be NULL.
352 : */
353 : uint64_t (*get_spin_time)(struct spdk_io_channel *ch);
354 :
355 : /** Get bdev module context. */
356 : void *(*get_module_ctx)(void *ctx);
357 :
358 : /** Get memory domains used by bdev. Optional - may be NULL.
359 : * Vbdev module implementation should call \ref spdk_bdev_get_memory_domains for underlying bdev.
360 : * Vbdev module must inspect types of memory domains returned by base bdev and report only those
361 : * memory domains that it can work with. */
362 : int (*get_memory_domains)(void *ctx, struct spdk_memory_domain **domains, int array_size);
363 :
364 : /**
365 : * Reset I/O statistics specific for this bdev context.
366 : */
367 : void (*reset_device_stat)(void *ctx);
368 :
369 : /**
370 : * Dump I/O statistics specific for this bdev context.
371 : */
372 : void (*dump_device_stat_json)(void *ctx, struct spdk_json_write_ctx *w);
373 :
374 : /** Check if bdev can handle spdk_accel_sequence to handle I/O of specific type. */
375 : bool (*accel_sequence_supported)(void *ctx, enum spdk_bdev_io_type type);
376 : };
377 :
378 : /** bdev I/O completion status */
379 : enum spdk_bdev_io_status {
380 : SPDK_BDEV_IO_STATUS_AIO_ERROR = -8,
381 : SPDK_BDEV_IO_STATUS_ABORTED = -7,
382 : SPDK_BDEV_IO_STATUS_FIRST_FUSED_FAILED = -6,
383 : SPDK_BDEV_IO_STATUS_MISCOMPARE = -5,
384 : /*
385 : * NOMEM should be returned when a bdev module cannot start an I/O because of
386 : * some lack of resources. It may not be returned for RESET I/O. I/O completed
387 : * with NOMEM status will be retried after some I/O from the same channel have
388 : * completed.
389 : */
390 : SPDK_BDEV_IO_STATUS_NOMEM = -4,
391 : SPDK_BDEV_IO_STATUS_SCSI_ERROR = -3,
392 : SPDK_BDEV_IO_STATUS_NVME_ERROR = -2,
393 : SPDK_BDEV_IO_STATUS_FAILED = -1,
394 : SPDK_BDEV_IO_STATUS_PENDING = 0,
395 : SPDK_BDEV_IO_STATUS_SUCCESS = 1,
396 :
397 : /* This may be used as the size of an error status array by negation.
398 : * Hence, this should be updated when adding new error statuses.
399 : */
400 : SPDK_MIN_BDEV_IO_STATUS = SPDK_BDEV_IO_STATUS_AIO_ERROR,
401 : };
402 :
403 : struct spdk_bdev_name {
404 : char *name;
405 : struct spdk_bdev *bdev;
406 : RB_ENTRY(spdk_bdev_name) node;
407 : };
408 :
409 : struct spdk_bdev_alias {
410 : struct spdk_bdev_name alias;
411 : TAILQ_ENTRY(spdk_bdev_alias) tailq;
412 : };
413 :
414 : struct spdk_bdev_module_claim {
415 : struct spdk_bdev_module *module;
416 : struct spdk_bdev_desc *desc;
417 : char name[SPDK_BDEV_CLAIM_NAME_LEN];
418 : TAILQ_ENTRY(spdk_bdev_module_claim) link;
419 : };
420 :
421 : typedef TAILQ_HEAD(, spdk_bdev_io) bdev_io_tailq_t;
422 : typedef STAILQ_HEAD(, spdk_bdev_io) bdev_io_stailq_t;
423 : typedef TAILQ_HEAD(, lba_range) lba_range_tailq_t;
424 :
425 : struct spdk_bdev {
426 : /** User context passed in by the backend */
427 : void *ctxt;
428 :
429 : /** Unique name for this block device. */
430 : char *name;
431 :
432 : /** Unique aliases for this block device. */
433 : TAILQ_HEAD(spdk_bdev_aliases_list, spdk_bdev_alias) aliases;
434 :
435 : /** Unique product name for this kind of block device. */
436 : char *product_name;
437 :
438 : /** write cache enabled, not used at the moment */
439 : int write_cache;
440 :
441 : /** Size in bytes of a logical block for the backend */
442 : uint32_t blocklen;
443 :
444 : /** Size in bytes of a physical block for the backend */
445 : uint32_t phys_blocklen;
446 :
447 : /** Number of blocks */
448 : uint64_t blockcnt;
449 :
450 : /**
451 : * Specifies whether the write_unit_size is mandatory or
452 : * only advisory. If set to true, the bdev layer will split
453 : * WRITE I/O that span the write_unit_size before
454 : * submitting them to the bdev module.
455 : *
456 : * This field takes precedence over split_on_optimal_io_boundary
457 : * for WRITE I/O if both are set to true.
458 : *
459 : * Note that this field cannot be used to force splitting of
460 : * UNMAP, WRITE_ZEROES or FLUSH I/O.
461 : */
462 : bool split_on_write_unit;
463 :
464 : /** Number of blocks required for write */
465 : uint32_t write_unit_size;
466 :
467 : /** Atomic compare & write unit */
468 : uint16_t acwu;
469 :
470 : /**
471 : * Specifies an alignment requirement for data buffers associated with an spdk_bdev_io.
472 : * 0 = no alignment requirement
473 : * >0 = alignment requirement is 2 ^ required_alignment.
474 : * bdev layer will automatically double buffer any spdk_bdev_io that violates this
475 : * alignment, before the spdk_bdev_io is submitted to the bdev module.
476 : */
477 : uint8_t required_alignment;
478 :
479 : /**
480 : * Specifies whether the optimal_io_boundary is mandatory or
481 : * only advisory. If set to true, the bdev layer will split
482 : * READ and WRITE I/O that span the optimal_io_boundary before
483 : * submitting them to the bdev module.
484 : *
485 : * Note that this field cannot be used to force splitting of
486 : * UNMAP, WRITE_ZEROES or FLUSH I/O.
487 : */
488 : bool split_on_optimal_io_boundary;
489 :
490 : /**
491 : * Optimal I/O boundary in blocks, or 0 for no value reported.
492 : */
493 : uint32_t optimal_io_boundary;
494 :
495 : /**
496 : * Max io size in bytes of a single segment
497 : *
498 : * Note: both max_segment_size and max_num_segments
499 : * should be zero or non-zero.
500 : */
501 : uint32_t max_segment_size;
502 :
503 : /* Maximum number of segments in a I/O */
504 : uint32_t max_num_segments;
505 :
506 : /* Maximum unmap in unit of logical block */
507 : uint32_t max_unmap;
508 :
509 : /* Maximum unmap block segments */
510 : uint32_t max_unmap_segments;
511 :
512 : /* Maximum write zeroes in unit of logical block */
513 : uint32_t max_write_zeroes;
514 :
515 : /**
516 : * Maximum copy size in unit of logical block
517 : * Should be set explicitly when backing device support copy command
518 : */
519 : uint32_t max_copy;
520 :
521 : /**
522 : * Maximum number of blocks in a single read/write I/O. Requests exceeding this value will
523 : * be split by the bdev layer.
524 : */
525 : uint32_t max_rw_size;
526 :
527 : /**
528 : * UUID for this bdev.
529 : *
530 : * If not provided, it will be generated by bdev layer.
531 : */
532 : struct spdk_uuid uuid;
533 :
534 : /** Size in bytes of a metadata for the backend */
535 : uint32_t md_len;
536 :
537 : /**
538 : * Specify metadata location and set to true if metadata is interleaved
539 : * with block data or false if metadata is separated with block data.
540 : *
541 : * Note that this field is valid only if there is metadata.
542 : */
543 : bool md_interleave;
544 :
545 : /**
546 : * DIF type for this bdev.
547 : *
548 : * Note that this field is valid only if there is metadata.
549 : */
550 : enum spdk_dif_type dif_type;
551 :
552 : /**
553 : * DIF protection information format for this bdev.
554 : *
555 : * Note that this field is valid only if there is metadata and dif_type is
556 : * not SPDK_DIF_DISABLE.
557 : */
558 : enum spdk_dif_pi_format dif_pi_format;
559 :
560 : /*
561 : * DIF location.
562 : *
563 : * Set to true if DIF is set in the first 8/16 bytes of metadata or false
564 : * if DIF is set in the last 8/16 bytes of metadata.
565 : *
566 : * Note that this field is valid only if DIF is enabled.
567 : */
568 : bool dif_is_head_of_md;
569 :
570 : /**
571 : * Specify whether each DIF check type is enabled.
572 : */
573 : uint32_t dif_check_flags;
574 :
575 : /**
576 : * Specify whether bdev is zoned device.
577 : */
578 : bool zoned;
579 :
580 : /**
581 : * Default size of each zone (in blocks).
582 : */
583 : uint64_t zone_size;
584 :
585 : /**
586 : * Maximum zone append data transfer size (in blocks).
587 : */
588 : uint32_t max_zone_append_size;
589 :
590 : /**
591 : * Maximum number of open zones.
592 : */
593 : uint32_t max_open_zones;
594 :
595 : /**
596 : * Maximum number of active zones.
597 : */
598 : uint32_t max_active_zones;
599 :
600 : /**
601 : * Optimal number of open zones.
602 : */
603 : uint32_t optimal_open_zones;
604 :
605 : /**
606 : * Specifies whether bdev supports media management events.
607 : */
608 : bool media_events;
609 :
610 : /**
611 : * Specifies the bdev nvme controller attributes.
612 : */
613 : union spdk_bdev_nvme_ctratt ctratt;
614 :
615 : /**
616 : * NVMe namespace ID.
617 : */
618 : uint32_t nsid;
619 :
620 : /* Upon receiving a reset request, this is the amount of time in seconds
621 : * to wait for all I/O to complete before moving forward with the reset.
622 : * If all I/O completes prior to this time out, the reset will be skipped.
623 : * A value of 0 is special and will always send resets immediately, even
624 : * if there is no I/O outstanding.
625 : *
626 : * Use case example:
627 : * A shared bdev (e.g. multiple lvol bdevs sharing an underlying nvme bdev)
628 : * needs to be reset. For a non-zero value bdev reset code will wait
629 : * `reset_io_drain_timeout` seconds for outstanding IO that are present
630 : * on any bdev channel, before sending a reset down to the underlying device.
631 : * That way we can avoid sending "empty" resets and interrupting work of
632 : * other lvols that use the same bdev. SPDK_BDEV_RESET_IO_DRAIN_RECOMMENDED_VALUE
633 : * is a good choice for the value of this parameter.
634 : *
635 : * If this parameter remains equal to zero, the bdev reset will be forcefully
636 : * sent down to the device, without any delays and waiting for outstanding IO. */
637 : uint16_t reset_io_drain_timeout;
638 :
639 : struct {
640 : /** Is numa.id valid? Needed to know whether numa.id == 0 was
641 : * explicitly set by bdev module or implicitly set when
642 : * calloc()'ing the structure.
643 : */
644 : uint32_t id_valid : 1;
645 : /** NUMA node ID for the bdev */
646 : int32_t id : 31;
647 : } numa;
648 :
649 : /**
650 : * Pointer to the bdev module that registered this bdev.
651 : */
652 : struct spdk_bdev_module *module;
653 :
654 : /** function table for all LUN ops */
655 : const struct spdk_bdev_fn_table *fn_table;
656 :
657 : /** Fields that are used internally by the bdev subsystem. Bdev modules
658 : * must not read or write to these fields.
659 : */
660 : struct __bdev_internal_fields {
661 : /** Quality of service parameters */
662 : struct spdk_bdev_qos *qos;
663 :
664 : /** True if the state of the QoS is being modified */
665 : bool qos_mod_in_progress;
666 :
667 : /** Trace ID for this bdev. */
668 : uint16_t trace_id;
669 :
670 : /**
671 : * SPDK spinlock protecting many of the internal fields of this structure. If
672 : * multiple locks need to be held, the following order must be used:
673 : * g_bdev_mgr.spinlock
674 : * bdev->internal.spinlock
675 : * bdev_desc->spinlock
676 : * bdev_module->internal.spinlock
677 : */
678 : struct spdk_spinlock spinlock;
679 :
680 : /** The bdev status */
681 : enum spdk_bdev_status status;
682 :
683 : /**
684 : * How many bdev_examine() calls are iterating claim.v2.claims. When non-zero claims
685 : * that are released will be cleared but remain on the claims list until
686 : * bdev_examine() finishes. Must hold spinlock on all updates.
687 : */
688 : uint32_t examine_in_progress;
689 :
690 : /**
691 : * The claim type: used in conjunction with claim. Must hold spinlock on all
692 : * updates.
693 : */
694 : enum spdk_bdev_claim_type claim_type;
695 :
696 : /** Which module has claimed this bdev. Must hold spinlock on all updates. */
697 : union __bdev_internal_claim {
698 : /** Claims acquired with spdk_bdev_module_claim_bdev() */
699 : struct __bdev_internal_claim_v1 {
700 : /**
701 : * Pointer to the module that has claimed this bdev for purposes of
702 : * creating virtual bdevs on top of it. Set to NULL and set
703 : * claim_type to SPDK_BDEV_CLAIM_NONE if the bdev has not been
704 : * claimed.
705 : */
706 : struct spdk_bdev_module *module;
707 : } v1;
708 : /** Claims acquired with spdk_bdev_module_claim_bdev_desc() */
709 : struct __bdev_internal_claim_v2 {
710 : /** The claims on this bdev */
711 : TAILQ_HEAD(v2_claims, spdk_bdev_module_claim) claims;
712 : /** See spdk_bdev_claim_opts.shared_claim_key */
713 : uint64_t key;
714 : } v2;
715 : } claim;
716 :
717 : /** Callback function that will be called after bdev destruct is completed. */
718 : spdk_bdev_unregister_cb unregister_cb;
719 :
720 : /** Unregister call context */
721 : void *unregister_ctx;
722 :
723 : /** Thread that issued the unregister. The cb must be called on this thread. */
724 : struct spdk_thread *unregister_td;
725 :
726 : /** List of open descriptors for this block device. */
727 : TAILQ_HEAD(, spdk_bdev_desc) open_descs;
728 :
729 : TAILQ_ENTRY(spdk_bdev) link;
730 :
731 : /** points to a reset bdev_io if one is in progress. */
732 : struct spdk_bdev_io *reset_in_progress;
733 :
734 : /** poller for tracking the queue_depth of a device, NULL if not tracking */
735 : struct spdk_poller *qd_poller;
736 :
737 : /** open descriptor to use qd_poller safely */
738 : struct spdk_bdev_desc *qd_desc;
739 :
740 : /** period at which we poll for queue depth information */
741 : uint64_t period;
742 :
743 : /** new period to be used to poll for queue depth information */
744 : uint64_t new_period;
745 :
746 : /** used to aggregate queue depth while iterating across the bdev's open channels */
747 : uint64_t temporary_queue_depth;
748 :
749 : /** queue depth as calculated the last time the telemetry poller checked. */
750 : uint64_t measured_queue_depth;
751 :
752 : /** most recent value of ticks spent performing I/O. Used to calculate the weighted time doing I/O */
753 : uint64_t io_time;
754 :
755 : /** weighted time performing I/O. Equal to measured_queue_depth * period */
756 : uint64_t weighted_io_time;
757 :
758 : /** accumulated I/O statistics for previously deleted channels of this bdev */
759 : struct spdk_bdev_io_stat *stat;
760 :
761 : /** true if tracking the queue_depth of a device is in progress */
762 : bool qd_poll_in_progress;
763 :
764 : /** histogram enabled on this bdev */
765 : bool histogram_enabled;
766 : bool histogram_in_progress;
767 : uint8_t histogram_io_type;
768 :
769 : /** Currently locked ranges for this bdev. Used to populate new channels. */
770 : lba_range_tailq_t locked_ranges;
771 :
772 : /** Pending locked ranges for this bdev. These ranges are not currently
773 : * locked due to overlapping with another locked range.
774 : */
775 : lba_range_tailq_t pending_locked_ranges;
776 :
777 : /** Bdev name used for quick lookup */
778 : struct spdk_bdev_name bdev_name;
779 : } internal;
780 : };
781 :
782 : /**
783 : * Callback when buffer is allocated for the bdev I/O.
784 : *
785 : * \param ch The I/O channel the bdev I/O was handled on.
786 : * \param bdev_io The bdev I/O
787 : * \param success True if buffer is allocated successfully or the bdev I/O has an SGL
788 : * assigned already, or false if it failed. The possible reason of failure is the size
789 : * of the buffer to allocate is greater than the permitted maximum.
790 : */
791 : typedef void (*spdk_bdev_io_get_buf_cb)(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
792 : bool success);
793 :
794 : /**
795 : * Callback when an auxiliary buffer is allocated for the bdev I/O.
796 : *
797 : * \param ch The I/O channel the bdev I/O was handled on.
798 : * \param bdev_io The bdev I/O
799 : * \param aux_buf Pointer to the allocated buffer. NULL if there was a failure such as
800 : * the size of the buffer to allocate is greater than the permitted maximum.
801 : */
802 : typedef void (*spdk_bdev_io_get_aux_buf_cb)(struct spdk_io_channel *ch,
803 : struct spdk_bdev_io *bdev_io, void *aux_buf);
804 :
805 : /* Maximum number of IOVs used for I/O splitting */
806 : #define SPDK_BDEV_IO_NUM_CHILD_IOV 32
807 :
808 : struct spdk_bdev_io_block_params {
809 : /** For SG buffer cases, array of iovecs to transfer. */
810 : struct iovec *iovs;
811 :
812 : /** For SG buffer cases, number of iovecs in iovec array. */
813 : int iovcnt;
814 :
815 : /** Total size of data to be transferred. */
816 : uint64_t num_blocks;
817 :
818 : /** Starting offset (in blocks) of the bdev for this I/O. */
819 : uint64_t offset_blocks;
820 :
821 : /** Memory domain and its context to be used by bdev modules */
822 : struct spdk_memory_domain *memory_domain;
823 : void *memory_domain_ctx;
824 :
825 : /* Sequence of accel operations */
826 : struct spdk_accel_sequence *accel_sequence;
827 :
828 : /* Metadata buffer */
829 : void *md_buf;
830 :
831 : /** For fused operations such as COMPARE_AND_WRITE, array of iovecs
832 : * for the second operation.
833 : */
834 : struct iovec *fused_iovs;
835 :
836 : /** Number of iovecs in fused_iovs. */
837 : int fused_iovcnt;
838 :
839 : /** Specify whether each DIF check type is enabled. */
840 : uint32_t dif_check_flags;
841 :
842 : /** defined by \ref spdk_bdev_nvme_cdw12 */
843 : union spdk_bdev_nvme_cdw12 nvme_cdw12;
844 :
845 : /** defined by \ref spdk_bdev_nvme_cdw13 */
846 : union spdk_bdev_nvme_cdw13 nvme_cdw13;
847 :
848 : struct {
849 : /** Whether the buffer should be populated with the real data */
850 : uint8_t populate : 1;
851 :
852 : /** Whether the buffer should be committed back to disk */
853 : uint8_t commit : 1;
854 :
855 : /** True if this request is in the 'start' phase of zcopy. False if in 'end'. */
856 : uint8_t start : 1;
857 : } zcopy;
858 :
859 : struct {
860 : /** The callback argument for the outstanding request which this abort
861 : * attempts to cancel.
862 : */
863 : void *bio_cb_arg;
864 : } abort;
865 :
866 : struct {
867 : /** The offset of next data/hole. */
868 : uint64_t offset;
869 : } seek;
870 :
871 : struct {
872 : /** Starting source offset (in blocks) of the bdev for copy I/O. */
873 : uint64_t src_offset_blocks;
874 : } copy;
875 : };
876 :
877 : struct spdk_bdev_io_reset_params {
878 : /** Channel reference held while messages for this reset are in progress. */
879 : struct spdk_io_channel *ch_ref;
880 : struct {
881 : /* Handle to timed poller that checks each channel for outstanding IO. */
882 : struct spdk_poller *poller;
883 : /* Store calculated time value, when a poller should stop its work. */
884 : uint64_t stop_time_tsc;
885 : } wait_poller;
886 : };
887 :
888 : struct spdk_bdev_io_abort_params {
889 : /** The outstanding request matching bio_cb_arg which this abort attempts to cancel. */
890 : struct spdk_bdev_io *bio_to_abort;
891 : };
892 :
893 : struct spdk_bdev_io_nvme_passthru_params {
894 : /* The NVMe command to execute */
895 : struct spdk_nvme_cmd cmd;
896 :
897 : /* For SG buffer cases, array of iovecs to transfer. */
898 : struct iovec *iovs;
899 :
900 : /* For SG buffer cases, number of iovecs in iovec array. */
901 : int iovcnt;
902 :
903 : /* The data buffer to transfer */
904 : void *buf;
905 :
906 : /* The number of bytes to transfer */
907 : size_t nbytes;
908 :
909 : /* The meta data buffer to transfer */
910 : void *md_buf;
911 :
912 : /* meta data buffer size to transfer */
913 : size_t md_len;
914 : };
915 :
916 : struct spdk_bdev_io_zone_mgmt_params {
917 : /* First logical block of a zone */
918 : uint64_t zone_id;
919 :
920 : /* Number of zones */
921 : uint32_t num_zones;
922 :
923 : /* Used to change zoned device zone state */
924 : enum spdk_bdev_zone_action zone_action;
925 :
926 : /* The data buffer */
927 : void *buf;
928 : };
929 :
930 : /**
931 : * Fields that are used internally by the bdev subsystem. Bdev modules
932 : * must not read or write to these fields.
933 : */
934 : struct spdk_bdev_io_internal_fields {
935 : /** The bdev I/O channel that this was handled on. */
936 : struct spdk_bdev_channel *ch;
937 :
938 : union {
939 : struct {
940 :
941 : /** Whether the accel_sequence member is valid */
942 : uint8_t has_accel_sequence : 1;
943 :
944 : /** Whether memory_domain member is valid */
945 : uint8_t has_memory_domain : 1;
946 :
947 : /** Whether the split data structure is valid */
948 : uint8_t split : 1;
949 :
950 : /** Whether ptr in the buf data structure is valid */
951 : uint8_t has_buf : 1;
952 :
953 : /** Whether the bounce_buf data structure is valid */
954 : uint8_t has_bounce_buf : 1;
955 :
956 : /** Whether we are currently inside the submit request call */
957 : uint8_t in_submit_request : 1;
958 :
959 : uint8_t reserved : 2;
960 : };
961 : uint8_t raw;
962 : } f;
963 :
964 : /** Status for the IO */
965 : int8_t status;
966 :
967 : /** Retry state (resubmit, re-pull, re-push, etc.) */
968 : uint8_t retry_state;
969 :
970 : uint8_t reserved[5];
971 :
972 : /** The bdev descriptor that was used when submitting this I/O. */
973 : struct spdk_bdev_desc *desc;
974 :
975 : /** User function that will be called when this completes */
976 : spdk_bdev_io_completion_cb cb;
977 :
978 : /** Context that will be passed to the completion callback */
979 : void *caller_ctx;
980 :
981 : /** Current tsc at submit time. Used to calculate latency at completion. */
982 : uint64_t submit_tsc;
983 :
984 : /** Entry to the list io_submitted of struct spdk_bdev_channel */
985 : TAILQ_ENTRY(spdk_bdev_io) ch_link;
986 :
987 : /** bdev_io pool entry */
988 : STAILQ_ENTRY(spdk_bdev_io) buf_link;
989 :
990 : /** Error information from a device */
991 : union {
992 : struct {
993 : /** NVMe completion queue entry DW0 */
994 : uint32_t cdw0;
995 : /** NVMe status code type */
996 : uint8_t sct;
997 : /** NVMe status code */
998 : uint8_t sc;
999 : } nvme;
1000 : /** Only valid when status is SPDK_BDEV_IO_STATUS_SCSI_ERROR */
1001 : struct {
1002 : /** SCSI status code */
1003 : uint8_t sc;
1004 : /** SCSI sense key */
1005 : uint8_t sk;
1006 : /** SCSI additional sense code */
1007 : uint8_t asc;
1008 : /** SCSI additional sense code qualifier */
1009 : uint8_t ascq;
1010 : } scsi;
1011 : /** Only valid when status is SPDK_BDEV_IO_STATUS_AIO_ERROR */
1012 : int aio_result;
1013 : } error;
1014 :
1015 : struct {
1016 : /** stored user callback in case we split the I/O and use a temporary callback */
1017 : spdk_bdev_io_completion_cb stored_user_cb;
1018 :
1019 : /** number of blocks remaining in a split i/o */
1020 : uint64_t remaining_num_blocks;
1021 :
1022 : /** current offset of the split I/O in the bdev */
1023 : uint64_t current_offset_blocks;
1024 :
1025 : /** count of outstanding batched split I/Os */
1026 : uint32_t outstanding;
1027 : } split;
1028 :
1029 : struct {
1030 : /** bdev allocated memory associated with this request */
1031 : void *ptr;
1032 :
1033 : /** requested size of the buffer associated with this I/O */
1034 : uint64_t len;
1035 : } buf;
1036 :
1037 : /** if the request is double buffered, store original request iovs here */
1038 : struct {
1039 : struct iovec iov;
1040 : struct iovec md_iov;
1041 : struct iovec orig_md_iov;
1042 : struct iovec *orig_iovs;
1043 : int orig_iovcnt;
1044 : } bounce_buf;
1045 :
1046 : /** Callback for when the aux buf is allocated */
1047 : spdk_bdev_io_get_aux_buf_cb get_aux_buf_cb;
1048 :
1049 : /** Callback for when buf is allocated */
1050 : spdk_bdev_io_get_buf_cb get_buf_cb;
1051 :
1052 : /**
1053 : * Queue entry used in several cases:
1054 : * 1. IOs awaiting retry due to NOMEM status,
1055 : * 2. IOs awaiting submission due to QoS,
1056 : * 3. IOs with an accel sequence being executed,
1057 : * 4. IOs awaiting memory domain pull/push,
1058 : * 5. queued reset requests.
1059 : */
1060 : TAILQ_ENTRY(spdk_bdev_io) link;
1061 :
1062 : /** iobuf queue entry */
1063 : struct spdk_iobuf_entry iobuf;
1064 :
1065 : /** Enables queuing parent I/O when no bdev_ios available for split children. */
1066 : struct spdk_bdev_io_wait_entry waitq_entry;
1067 :
1068 : /** Memory domain and its context passed by the user in ext API */
1069 : struct spdk_memory_domain *memory_domain;
1070 : void *memory_domain_ctx;
1071 :
1072 : /* Sequence of accel operations passed by the user */
1073 : struct spdk_accel_sequence *accel_sequence;
1074 :
1075 : /** Data transfer completion callback */
1076 : void (*data_transfer_cpl)(void *ctx, int rc);
1077 : };
1078 :
1079 : struct spdk_bdev_io {
1080 : /** The block device that this I/O belongs to. */
1081 : struct spdk_bdev *bdev;
1082 :
1083 : /** Enumerated value representing the I/O type. */
1084 : uint8_t type;
1085 :
1086 : uint8_t reserved0;
1087 :
1088 : /** Number of IO submission retries */
1089 : uint16_t num_retries;
1090 :
1091 : uint32_t reserved1;
1092 :
1093 : /** A single iovec element for use by this bdev_io. */
1094 : struct iovec iov;
1095 :
1096 : /** Array of iovecs used for I/O splitting. */
1097 : struct iovec child_iov[SPDK_BDEV_IO_NUM_CHILD_IOV];
1098 :
1099 : uint8_t reserved2[32];
1100 :
1101 : /** Parameters filled in by the user */
1102 : union {
1103 : struct spdk_bdev_io_block_params bdev;
1104 : struct spdk_bdev_io_reset_params reset;
1105 : struct spdk_bdev_io_abort_params abort;
1106 : struct spdk_bdev_io_nvme_passthru_params nvme_passthru;
1107 : struct spdk_bdev_io_zone_mgmt_params zone_mgmt;
1108 : } u;
1109 :
1110 : uint64_t reserved3;
1111 :
1112 : /**
1113 : * Fields that are used internally by the bdev subsystem. Bdev modules
1114 : * must not read or write to these fields.
1115 : */
1116 : struct spdk_bdev_io_internal_fields internal;
1117 :
1118 : /**
1119 : * Per I/O context for use by the bdev module.
1120 : */
1121 : uint8_t driver_ctx[0];
1122 :
1123 : /* No members may be added after driver_ctx! */
1124 : };
1125 : SPDK_STATIC_ASSERT(offsetof(struct spdk_bdev_io, driver_ctx) % SPDK_CACHE_LINE_SIZE == 0,
1126 : "driver_ctx not cache line aligned");
1127 :
1128 : /**
1129 : * Register a new bdev.
1130 : *
1131 : * This function must be called from the SPDK app thread.
1132 : *
1133 : * \param bdev Block device to register.
1134 : *
1135 : * \return 0 on success.
1136 : * \return -EINVAL if the bdev name is NULL.
1137 : * \return -EEXIST if a bdev or bdev alias with the same name already exists.
1138 : */
1139 : int spdk_bdev_register(struct spdk_bdev *bdev);
1140 :
1141 : /**
1142 : * Start unregistering a bdev. This will notify each currently open descriptor
1143 : * on this bdev of the hotremoval to request the upper layers to stop using this bdev
1144 : * and manually close all the descriptors with spdk_bdev_close().
1145 : * The actual bdev unregistration may be deferred until all descriptors are closed.
1146 : *
1147 : * The cb_fn will be called from the context of the same spdk_thread that called
1148 : * spdk_bdev_unregister.
1149 : *
1150 : * Note: spdk_bdev_unregister() can be unsafe unless the bdev is not opened before and
1151 : * closed after unregistration. It is recommended to use spdk_bdev_unregister_by_name().
1152 : *
1153 : * \param bdev Block device to unregister.
1154 : * \param cb_fn Callback function to be called when the unregister is complete.
1155 : * \param cb_arg Argument to be supplied to cb_fn
1156 : */
1157 : void spdk_bdev_unregister(struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn, void *cb_arg);
1158 :
1159 : /**
1160 : * Start unregistering a bdev. This will notify each currently open descriptor
1161 : * on this bdev of the hotremoval to request the upper layer to stop using this bdev
1162 : * and manually close all the descriptors with spdk_bdev_close().
1163 : * The actual bdev unregistration may be deferred until all descriptors are closed.
1164 : *
1165 : * The cb_fn will be called from the context of the same spdk_thread that called
1166 : * spdk_bdev_unregister.
1167 : *
1168 : * \param bdev_name Block device name to unregister.
1169 : * \param module Module by which the block device was registered.
1170 : * \param cb_fn Callback function to be called when the unregister is complete.
1171 : * \param cb_arg Argument to be supplied to cb_fn
1172 : *
1173 : * \return 0 on success, or suitable errno value otherwise
1174 : */
1175 : int spdk_bdev_unregister_by_name(const char *bdev_name, struct spdk_bdev_module *module,
1176 : spdk_bdev_unregister_cb cb_fn, void *cb_arg);
1177 :
1178 : /**
1179 : * Notify the bdev layer that an asynchronous destruct operation is complete.
1180 : *
1181 : * A Bdev with an asynchronous destruct path should return 1 from its
1182 : * destruct function and call this function at the conclusion of that path.
1183 : * Bdevs with synchronous destruct paths should return 0 from their destruct
1184 : * path.
1185 : *
1186 : * \param bdev Block device that was destroyed.
1187 : * \param bdeverrno Error code returned from bdev's destruct callback.
1188 : */
1189 : void spdk_bdev_destruct_done(struct spdk_bdev *bdev, int bdeverrno);
1190 :
1191 : /**
1192 : * Indicate to the bdev layer that the module is done examining a bdev.
1193 : *
1194 : * To be called during examine_config function or asynchronously in response to the
1195 : * module's examine_disk function being called.
1196 : *
1197 : * \param module Pointer to the module completing the examination.
1198 : */
1199 : void spdk_bdev_module_examine_done(struct spdk_bdev_module *module);
1200 :
1201 : /**
1202 : * Indicate to the bdev layer that the module is done initializing.
1203 : *
1204 : * To be called once after an asynchronous operation required for module initialization is
1205 : * completed. If module->async_init is false, the module must not call this function.
1206 : *
1207 : * \param module Pointer to the module completing the initialization.
1208 : */
1209 : void spdk_bdev_module_init_done(struct spdk_bdev_module *module);
1210 :
1211 : /**
1212 : * Indicate that the module finish has completed.
1213 : *
1214 : * To be called in response to the module_fini, only if async_fini is set.
1215 : *
1216 : */
1217 : void spdk_bdev_module_fini_done(void);
1218 :
1219 : /**
1220 : * Indicate that the module fini start has completed.
1221 : *
1222 : * To be called in response to the fini_start, only if async_fini_start is set.
1223 : * May be called during fini_start or asynchronously.
1224 : *
1225 : */
1226 : void spdk_bdev_module_fini_start_done(void);
1227 :
1228 : /**
1229 : * Add alias to block device names list.
1230 : * Aliases can be add only to registered bdev.
1231 : *
1232 : * \param bdev Block device to query.
1233 : * \param alias Alias to be added to list.
1234 : *
1235 : * \return 0 on success
1236 : * \return -EEXIST if alias already exists as name or alias on any bdev
1237 : * \return -ENOMEM if memory cannot be allocated to store alias
1238 : * \return -EINVAL if passed alias is empty
1239 : */
1240 : int spdk_bdev_alias_add(struct spdk_bdev *bdev, const char *alias);
1241 :
1242 : /**
1243 : * Removes name from block device names list.
1244 : *
1245 : * \param bdev Block device to query.
1246 : * \param alias Alias to be deleted from list.
1247 : * \return 0 on success
1248 : * \return -ENOENT if alias does not exists
1249 : */
1250 : int spdk_bdev_alias_del(struct spdk_bdev *bdev, const char *alias);
1251 :
1252 : /**
1253 : * Removes all alias from block device alias list.
1254 : *
1255 : * \param bdev Block device to operate.
1256 : */
1257 : void spdk_bdev_alias_del_all(struct spdk_bdev *bdev);
1258 :
1259 : /**
1260 : * Get pointer to block device aliases list.
1261 : *
1262 : * \param bdev Block device to query.
1263 : * \return Pointer to bdev aliases list.
1264 : */
1265 : const struct spdk_bdev_aliases_list *spdk_bdev_get_aliases(const struct spdk_bdev *bdev);
1266 :
1267 : /**
1268 : * Allocate a buffer for given bdev_io. Allocation will happen
1269 : * only if the bdev_io has no assigned SGL yet or SGL is not
1270 : * aligned to \c bdev->required_alignment. If SGL is not aligned,
1271 : * this call will cause copy from SGL to bounce buffer on write
1272 : * path or copy from bounce buffer to SGL before completion
1273 : * callback on read path. The buffer will be freed automatically
1274 : * on \c spdk_bdev_free_io() call. This call will never fail.
1275 : * In case of lack of memory given callback \c cb will be deferred
1276 : * until enough memory is freed. This function *must* be called
1277 : * from the thread issuing \c bdev_io.
1278 : *
1279 : * \param bdev_io I/O to allocate buffer for.
1280 : * \param cb callback to be called when the buffer is allocated
1281 : * or the bdev_io has an SGL assigned already.
1282 : * \param len size of the buffer to allocate. In case the bdev_io
1283 : * doesn't have an SGL assigned this field must be no bigger than
1284 : * \c SPDK_BDEV_LARGE_BUF_MAX_SIZE.
1285 : */
1286 : void spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb, uint64_t len);
1287 :
1288 : /**
1289 : * Allocate an auxiliary buffer for given bdev_io. The length of the
1290 : * buffer will be the same size as the bdev_io primary buffer. The buffer
1291 : * must be freed using \c spdk_bdev_io_put_aux_buf() before completing
1292 : * the associated bdev_io. This call will never fail. In case of lack of
1293 : * memory given callback \c cb will be deferred until enough memory is freed.
1294 : *
1295 : * \param bdev_io I/O to allocate buffer for.
1296 : * \param cb callback to be called when the buffer is allocated
1297 : */
1298 : void spdk_bdev_io_get_aux_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_aux_buf_cb cb);
1299 :
1300 : /**
1301 : * Free an auxiliary buffer previously allocated by \c spdk_bdev_io_get_aux_buf().
1302 : *
1303 : * \param bdev_io bdev_io specified when the aux_buf was allocated.
1304 : * \param aux_buf auxiliary buffer to free
1305 : */
1306 : void spdk_bdev_io_put_aux_buf(struct spdk_bdev_io *bdev_io, void *aux_buf);
1307 :
1308 : /**
1309 : * Set the given buffer as the data buffer described by this bdev_io.
1310 : *
1311 : * The portion of the buffer used may be adjusted for memory alignment
1312 : * purposes.
1313 : *
1314 : * \param bdev_io I/O to set the buffer on.
1315 : * \param buf The buffer to set as the active data buffer.
1316 : * \param len The length of the buffer.
1317 : *
1318 : */
1319 : void spdk_bdev_io_set_buf(struct spdk_bdev_io *bdev_io, void *buf, size_t len);
1320 :
1321 : /**
1322 : * Set the given buffer as metadata buffer described by this bdev_io.
1323 : *
1324 : * \param bdev_io I/O to set the buffer on.
1325 : * \param md_buf The buffer to set as the active metadata buffer.
1326 : * \param len The length of the metadata buffer.
1327 : */
1328 : void spdk_bdev_io_set_md_buf(struct spdk_bdev_io *bdev_io, void *md_buf, size_t len);
1329 :
1330 : /**
1331 : * Complete a bdev_io
1332 : *
1333 : * \param bdev_io I/O to complete.
1334 : * \param status The I/O completion status.
1335 : */
1336 : void spdk_bdev_io_complete(struct spdk_bdev_io *bdev_io,
1337 : enum spdk_bdev_io_status status);
1338 :
1339 : /**
1340 : * Complete a bdev_io with an NVMe status code and DW0 completion queue entry
1341 : *
1342 : * \param bdev_io I/O to complete.
1343 : * \param cdw0 NVMe Completion Queue DW0 value (set to 0 if not applicable)
1344 : * \param sct NVMe Status Code Type.
1345 : * \param sc NVMe Status Code.
1346 : */
1347 : void spdk_bdev_io_complete_nvme_status(struct spdk_bdev_io *bdev_io, uint32_t cdw0, int sct,
1348 : int sc);
1349 :
1350 : /**
1351 : * Complete a bdev_io with a SCSI status code.
1352 : *
1353 : * \param bdev_io I/O to complete.
1354 : * \param sc SCSI Status Code.
1355 : * \param sk SCSI Sense Key.
1356 : * \param asc SCSI Additional Sense Code.
1357 : * \param ascq SCSI Additional Sense Code Qualifier.
1358 : */
1359 : void spdk_bdev_io_complete_scsi_status(struct spdk_bdev_io *bdev_io, enum spdk_scsi_status sc,
1360 : enum spdk_scsi_sense sk, uint8_t asc, uint8_t ascq);
1361 :
1362 : /**
1363 : * Complete a bdev_io with AIO errno.
1364 : *
1365 : * \param bdev_io I/O to complete.
1366 : * \param aio_result Negative errno returned from AIO.
1367 : */
1368 : void spdk_bdev_io_complete_aio_status(struct spdk_bdev_io *bdev_io, int aio_result);
1369 :
1370 : /**
1371 : * Complete a bdev_io copying a status from another bdev_io.
1372 : *
1373 : * \param bdev_io I/O to complete.
1374 : * \param base_io I/O from which to copy the status.
1375 : */
1376 : void spdk_bdev_io_complete_base_io_status(struct spdk_bdev_io *bdev_io,
1377 : const struct spdk_bdev_io *base_io);
1378 :
1379 : /**
1380 : * Get a thread that given bdev_io was submitted on.
1381 : *
1382 : * \param bdev_io I/O
1383 : * \return thread that submitted the I/O
1384 : */
1385 : struct spdk_thread *spdk_bdev_io_get_thread(struct spdk_bdev_io *bdev_io);
1386 :
1387 : /**
1388 : * Get the bdev module's I/O channel that the given bdev_io was submitted on.
1389 : *
1390 : * \param bdev_io I/O
1391 : * \return the bdev module's I/O channel that the given bdev_io was submitted on.
1392 : */
1393 : struct spdk_io_channel *spdk_bdev_io_get_io_channel(struct spdk_bdev_io *bdev_io);
1394 :
1395 : /**
1396 : * Get the submit_tsc of a bdev I/O.
1397 : *
1398 : * \param bdev_io The bdev I/O to get the submit_tsc.
1399 : *
1400 : * \return The submit_tsc of the specified bdev I/O.
1401 : */
1402 : uint64_t spdk_bdev_io_get_submit_tsc(struct spdk_bdev_io *bdev_io);
1403 :
1404 : /**
1405 : * Resize for a bdev.
1406 : *
1407 : * Change number of blocks for provided block device.
1408 : * It can only be called on a registered bdev.
1409 : *
1410 : * \param bdev Block device to change.
1411 : * \param size New size of bdev.
1412 : * \return 0 on success, negated errno on failure.
1413 : */
1414 : int spdk_bdev_notify_blockcnt_change(struct spdk_bdev *bdev, uint64_t size);
1415 :
1416 : /**
1417 : * Translates NVMe status codes to SCSI status information.
1418 : *
1419 : * The codes are stored in the user supplied integers.
1420 : *
1421 : * \param bdev_io I/O containing status codes to translate.
1422 : * \param sc SCSI Status Code will be stored here.
1423 : * \param sk SCSI Sense Key will be stored here.
1424 : * \param asc SCSI Additional Sense Code will be stored here.
1425 : * \param ascq SCSI Additional Sense Code Qualifier will be stored here.
1426 : */
1427 : void spdk_scsi_nvme_translate(const struct spdk_bdev_io *bdev_io,
1428 : int *sc, int *sk, int *asc, int *ascq);
1429 :
1430 : /**
1431 : * Add the given module to the list of registered modules.
1432 : * This function should be invoked by referencing the macro
1433 : * SPDK_BDEV_MODULE_REGISTER in the module c file.
1434 : *
1435 : * \param bdev_module Module to be added.
1436 : */
1437 : void spdk_bdev_module_list_add(struct spdk_bdev_module *bdev_module);
1438 :
1439 : /**
1440 : * Find registered module with name pointed by \c name.
1441 : *
1442 : * \param name name of module to be searched for.
1443 : * \return pointer to module or NULL if no module with \c name exist
1444 : */
1445 : struct spdk_bdev_module *spdk_bdev_module_list_find(const char *name);
1446 :
1447 : static inline struct spdk_bdev_io *
1448 803 : spdk_bdev_io_from_ctx(void *ctx)
1449 : {
1450 803 : return SPDK_CONTAINEROF(ctx, struct spdk_bdev_io, driver_ctx);
1451 : }
1452 :
1453 : struct spdk_bdev_part_base;
1454 :
1455 : /**
1456 : * Returns a pointer to the spdk_bdev associated with an spdk_bdev_part_base
1457 : *
1458 : * \param part_base A pointer to an spdk_bdev_part_base object.
1459 : *
1460 : * \return A pointer to the base's spdk_bdev struct.
1461 : */
1462 : struct spdk_bdev *spdk_bdev_part_base_get_bdev(struct spdk_bdev_part_base *part_base);
1463 :
1464 : /**
1465 : * Returns a spdk_bdev name of the corresponding spdk_bdev_part_base
1466 : *
1467 : * \param part_base A pointer to an spdk_bdev_part_base object.
1468 : *
1469 : * \return A text string representing the name of the base bdev.
1470 : */
1471 : const char *spdk_bdev_part_base_get_bdev_name(struct spdk_bdev_part_base *part_base);
1472 :
1473 : /**
1474 : * Returns a pointer to the spdk_bdev_descriptor associated with an spdk_bdev_part_base
1475 : *
1476 : * \param part_base A pointer to an spdk_bdev_part_base object.
1477 : *
1478 : * \return A pointer to the base's spdk_bdev_desc struct.
1479 : */
1480 : struct spdk_bdev_desc *spdk_bdev_part_base_get_desc(struct spdk_bdev_part_base *part_base);
1481 :
1482 : /**
1483 : * Returns a pointer to the tailq associated with an spdk_bdev_part_base
1484 : *
1485 : * \param part_base A pointer to an spdk_bdev_part_base object.
1486 : *
1487 : * \return The head of a tailq of spdk_bdev_part structs registered to the base's module.
1488 : */
1489 : struct bdev_part_tailq *spdk_bdev_part_base_get_tailq(struct spdk_bdev_part_base *part_base);
1490 :
1491 : /**
1492 : * Returns a pointer to the module level context associated with an spdk_bdev_part_base
1493 : *
1494 : * \param part_base A pointer to an spdk_bdev_part_base object.
1495 : *
1496 : * \return A pointer to the module level context registered with the base in spdk_bdev_part_base_construct.
1497 : */
1498 : void *spdk_bdev_part_base_get_ctx(struct spdk_bdev_part_base *part_base);
1499 :
1500 : typedef void (*spdk_bdev_part_base_free_fn)(void *ctx);
1501 :
1502 : struct spdk_bdev_part {
1503 : /* Entry into the module's global list of bdev parts */
1504 : TAILQ_ENTRY(spdk_bdev_part) tailq;
1505 :
1506 : /**
1507 : * Fields that are used internally by part.c These fields should only
1508 : * be accessed from a module using any pertinent get and set methods.
1509 : */
1510 : struct bdev_part_internal_fields {
1511 :
1512 : /* This part's corresponding bdev object. Not to be confused with the base bdev */
1513 : struct spdk_bdev bdev;
1514 :
1515 : /* The base to which this part belongs */
1516 : struct spdk_bdev_part_base *base;
1517 :
1518 : /* number of blocks from the start of the base bdev to the start of this part */
1519 : uint64_t offset_blocks;
1520 : } internal;
1521 : };
1522 :
1523 : struct spdk_bdev_part_channel {
1524 : struct spdk_bdev_part *part;
1525 : struct spdk_io_channel *base_ch;
1526 : };
1527 :
1528 : typedef TAILQ_HEAD(bdev_part_tailq, spdk_bdev_part) SPDK_BDEV_PART_TAILQ;
1529 :
1530 : /**
1531 : * Free the base corresponding to one or more spdk_bdev_part.
1532 : *
1533 : * \param base The base to free.
1534 : */
1535 : void spdk_bdev_part_base_free(struct spdk_bdev_part_base *base);
1536 :
1537 : /**
1538 : * Free an spdk_bdev_part context.
1539 : *
1540 : * \param part The part to free.
1541 : *
1542 : * \return 1 always. To indicate that the operation is asynchronous.
1543 : */
1544 : int spdk_bdev_part_free(struct spdk_bdev_part *part);
1545 :
1546 : /**
1547 : * Calls spdk_bdev_unregister on the bdev for each part associated with base_bdev.
1548 : *
1549 : * \param part_base The part base object built on top of an spdk_bdev
1550 : * \param tailq The list of spdk_bdev_part bdevs associated with this base bdev.
1551 : */
1552 : void spdk_bdev_part_base_hotremove(struct spdk_bdev_part_base *part_base,
1553 : struct bdev_part_tailq *tailq);
1554 :
1555 : /**
1556 : * Construct a new spdk_bdev_part_base on top of the provided bdev.
1557 : *
1558 : * \param bdev_name Name of the bdev upon which this base will be built.
1559 : * \param remove_cb Function to be called upon hotremove of the bdev.
1560 : * \param module The module to which this bdev base belongs.
1561 : * \param fn_table Function table for communicating with the bdev backend.
1562 : * \param tailq The head of the list of all spdk_bdev_part structures registered to this base's module.
1563 : * \param free_fn User provided function to free base related context upon bdev removal or shutdown.
1564 : * \param ctx Module specific context for this bdev part base.
1565 : * \param channel_size Channel size in bytes.
1566 : * \param ch_create_cb Called after a new channel is allocated.
1567 : * \param ch_destroy_cb Called upon channel deletion.
1568 : * \param base output parameter for the part object when operation is successful.
1569 : *
1570 : * \return 0 if operation is successful, or suitable errno value otherwise.
1571 : */
1572 : int spdk_bdev_part_base_construct_ext(const char *bdev_name,
1573 : spdk_bdev_remove_cb_t remove_cb,
1574 : struct spdk_bdev_module *module,
1575 : struct spdk_bdev_fn_table *fn_table,
1576 : struct bdev_part_tailq *tailq,
1577 : spdk_bdev_part_base_free_fn free_fn,
1578 : void *ctx,
1579 : uint32_t channel_size,
1580 : spdk_io_channel_create_cb ch_create_cb,
1581 : spdk_io_channel_destroy_cb ch_destroy_cb,
1582 : struct spdk_bdev_part_base **base);
1583 :
1584 : /** Options used when constructing a part bdev. */
1585 : struct spdk_bdev_part_construct_opts {
1586 : /* Size of this structure in bytes */
1587 : uint64_t opts_size;
1588 : /** UUID of the bdev */
1589 : struct spdk_uuid uuid;
1590 : };
1591 :
1592 : SPDK_STATIC_ASSERT(sizeof(struct spdk_bdev_part_construct_opts) == 24, "Incorrect size");
1593 :
1594 : /**
1595 : * Initialize options that will be passed to spdk_bdev_part_construct_ext().
1596 : *
1597 : * \param opts Options structure to initialize
1598 : * \param size Size of opts structure.
1599 : */
1600 : void spdk_bdev_part_construct_opts_init(struct spdk_bdev_part_construct_opts *opts, uint64_t size);
1601 :
1602 : /**
1603 : * Create a logical spdk_bdev_part on top of a base.
1604 : *
1605 : * \param part The part object allocated by the user.
1606 : * \param base The base from which to create the part.
1607 : * \param name The name of the new spdk_bdev_part.
1608 : * \param offset_blocks The offset into the base bdev at which this part begins.
1609 : * \param num_blocks The number of blocks that this part will span.
1610 : * \param product_name Unique name for this type of block device.
1611 : *
1612 : * \return 0 on success.
1613 : * \return -1 if the bases underlying bdev cannot be claimed by the current module.
1614 : */
1615 : int spdk_bdev_part_construct(struct spdk_bdev_part *part, struct spdk_bdev_part_base *base,
1616 : char *name, uint64_t offset_blocks, uint64_t num_blocks,
1617 : char *product_name);
1618 :
1619 : /**
1620 : * Create a logical spdk_bdev_part on top of a base with a non-NULL bdev UUID
1621 : *
1622 : * \param part The part object allocated by the user.
1623 : * \param base The base from which to create the part.
1624 : * \param name The name of the new spdk_bdev_part.
1625 : * \param offset_blocks The offset into the base bdev at which this part begins.
1626 : * \param num_blocks The number of blocks that this part will span.
1627 : * \param product_name Unique name for this type of block device.
1628 : * \param opts Additional options.
1629 : *
1630 : * \return 0 on success.
1631 : * \return -1 if the bases underlying bdev cannot be claimed by the current module.
1632 : */
1633 : int spdk_bdev_part_construct_ext(struct spdk_bdev_part *part, struct spdk_bdev_part_base *base,
1634 : char *name, uint64_t offset_blocks, uint64_t num_blocks,
1635 : char *product_name,
1636 : const struct spdk_bdev_part_construct_opts *opts);
1637 :
1638 : /**
1639 : * Forwards I/O from an spdk_bdev_part to the underlying base bdev.
1640 : *
1641 : * This function will apply the offset_blocks the user provided to
1642 : * spdk_bdev_part_construct to the I/O. The user should not manually
1643 : * apply this offset before submitting any I/O through this function.
1644 : *
1645 : * \param ch The I/O channel associated with the spdk_bdev_part.
1646 : * \param bdev_io The I/O to be submitted to the underlying bdev.
1647 : * \return 0 on success or non-zero if submit request failed.
1648 : */
1649 : int spdk_bdev_part_submit_request(struct spdk_bdev_part_channel *ch, struct spdk_bdev_io *bdev_io);
1650 :
1651 : /**
1652 : * Forwards I/O from an spdk_bdev_part to the underlying base bdev.
1653 : *
1654 : * This function will apply the offset_blocks the user provided to
1655 : * spdk_bdev_part_construct to the I/O. The user should not manually
1656 : * apply this offset before submitting any I/O through this function.
1657 : *
1658 : * This function enables user to specify a completion callback. It is required that
1659 : * the completion callback calls spdk_bdev_io_complete() for the forwarded I/O.
1660 : *
1661 : * \param ch The I/O channel associated with the spdk_bdev_part.
1662 : * \param bdev_io The I/O to be submitted to the underlying bdev.
1663 : * \param cb Called when the forwarded I/O completes.
1664 : * \return 0 on success or non-zero if submit request failed.
1665 : */
1666 : int spdk_bdev_part_submit_request_ext(struct spdk_bdev_part_channel *ch,
1667 : struct spdk_bdev_io *bdev_io,
1668 : spdk_bdev_io_completion_cb cb);
1669 :
1670 : /**
1671 : * Return a pointer to this part's spdk_bdev.
1672 : *
1673 : * \param part An spdk_bdev_part object.
1674 : *
1675 : * \return A pointer to this part's spdk_bdev object.
1676 : */
1677 : struct spdk_bdev *spdk_bdev_part_get_bdev(struct spdk_bdev_part *part);
1678 :
1679 : /**
1680 : * Return a pointer to this part's base.
1681 : *
1682 : * \param part An spdk_bdev_part object.
1683 : *
1684 : * \return A pointer to this part's spdk_bdev_part_base object.
1685 : */
1686 : struct spdk_bdev_part_base *spdk_bdev_part_get_base(struct spdk_bdev_part *part);
1687 :
1688 : /**
1689 : * Return a pointer to this part's base bdev.
1690 : *
1691 : * The return value of this function is equivalent to calling
1692 : * spdk_bdev_part_base_get_bdev on this part's base.
1693 : *
1694 : * \param part An spdk_bdev_part object.
1695 : *
1696 : * \return A pointer to the bdev belonging to this part's base.
1697 : */
1698 : struct spdk_bdev *spdk_bdev_part_get_base_bdev(struct spdk_bdev_part *part);
1699 :
1700 : /**
1701 : * Return this part's offset from the beginning of the base bdev.
1702 : *
1703 : * This function should not be called in the I/O path. Any block
1704 : * translations to I/O will be handled in spdk_bdev_part_submit_request.
1705 : *
1706 : * \param part An spdk_bdev_part object.
1707 : *
1708 : * \return the block offset of this part from it's underlying bdev.
1709 : */
1710 : uint64_t spdk_bdev_part_get_offset_blocks(struct spdk_bdev_part *part);
1711 :
1712 : /**
1713 : * Push media management events. To send the notification that new events are
1714 : * available, spdk_bdev_notify_media_management needs to be called.
1715 : *
1716 : * \param bdev Block device
1717 : * \param events Array of media events
1718 : * \param num_events Size of the events array
1719 : *
1720 : * \return number of events pushed or negative errno in case of failure
1721 : */
1722 : int spdk_bdev_push_media_events(struct spdk_bdev *bdev, const struct spdk_bdev_media_event *events,
1723 : size_t num_events);
1724 :
1725 : /**
1726 : * Send SPDK_BDEV_EVENT_MEDIA_MANAGEMENT to all open descriptors that have
1727 : * pending media events.
1728 : *
1729 : * \param bdev Block device
1730 : */
1731 : void spdk_bdev_notify_media_management(struct spdk_bdev *bdev);
1732 :
1733 : typedef int (*spdk_bdev_io_fn)(void *ctx, struct spdk_bdev_io *bdev_io);
1734 : typedef void (*spdk_bdev_for_each_io_cb)(void *ctx, int rc);
1735 :
1736 : /**
1737 : * Call the provided function on the appropriate thread for each bdev_io submitted
1738 : * to the provided bdev.
1739 : *
1740 : * Note: This function should be used only in the bdev module and it should be
1741 : * ensured that the bdev is not unregistered while executing the function.
1742 : * Both fn and cb are required to specify.
1743 : *
1744 : * \param bdev Block device to query.
1745 : * \param ctx Context passed to the function for each bdev_io and the completion
1746 : * callback function.
1747 : * \param fn Called on the appropriate thread for each bdev_io submitted to the bdev.
1748 : * \param cb Called when this operation completes.
1749 : */
1750 : void spdk_bdev_for_each_bdev_io(struct spdk_bdev *bdev, void *ctx, spdk_bdev_io_fn fn,
1751 : spdk_bdev_for_each_io_cb cb);
1752 :
1753 : typedef void (*spdk_bdev_get_current_qd_cb)(struct spdk_bdev *bdev, uint64_t current_qd,
1754 : void *cb_arg, int rc);
1755 :
1756 : /**
1757 : * Measure and return the queue depth from a bdev.
1758 : *
1759 : * Note: spdk_bdev_get_qd() works only when the user enables queue depth sampling,
1760 : * while this new function works even when queue depth sampling is disabled.
1761 : * The returned queue depth may not be exact, for example, some additional I/Os may
1762 : * have been submitted or completed during the for_each_channel operation.
1763 : * This function should be used only in the bdev module and it should be ensured
1764 : * that the dev is not unregistered while executing the function.
1765 : * cb_fn is required to specify.
1766 : *
1767 : * \param bdev Block device to query.
1768 : * \param cb_fn Callback function to be called with queue depth measured for a bdev.
1769 : * \param cb_arg Argument to pass to callback function.
1770 : */
1771 : void spdk_bdev_get_current_qd(struct spdk_bdev *bdev,
1772 : spdk_bdev_get_current_qd_cb cb_fn, void *cb_arg);
1773 :
1774 : /**
1775 : * Add I/O statistics.
1776 : *
1777 : * \param total The aggregated I/O statistics.
1778 : * \param add The I/O statistics to be added.
1779 : */
1780 : void spdk_bdev_add_io_stat(struct spdk_bdev_io_stat *total, struct spdk_bdev_io_stat *add);
1781 :
1782 : /**
1783 : * Output bdev I/O statistics information to a JSON stream.
1784 : *
1785 : * \param stat The bdev I/O statistics to output.
1786 : * \param w JSON write context.
1787 : */
1788 : void spdk_bdev_dump_io_stat_json(struct spdk_bdev_io_stat *stat, struct spdk_json_write_ctx *w);
1789 :
1790 : /**
1791 : * Reset I/O statistics structure.
1792 : *
1793 : * \param stat The I/O statistics to reset.
1794 : * \param mode The mode to reset I/O statistics.
1795 : */
1796 : void spdk_bdev_reset_io_stat(struct spdk_bdev_io_stat *stat, enum spdk_bdev_reset_stat_mode mode);
1797 :
1798 : typedef void (*spdk_bdev_quiesce_cb)(void *ctx, int status);
1799 :
1800 : /**
1801 : * Quiesce a bdev. All I/O submitted after this function is called will be queued until
1802 : * the bdev is unquiesced. A callback will be called when all outstanding I/O on this bdev
1803 : * submitted before calling this function have completed.
1804 : *
1805 : * Only the module that registered the bdev may call this function.
1806 : *
1807 : * \param bdev Block device.
1808 : * \param module The module that registered the bdev.
1809 : * \param cb_fn Callback function to be called when the bdev is quiesced. Optional.
1810 : * \param cb_arg Argument to be supplied to cb_fn.
1811 : *
1812 : * \return 0 on success, or suitable errno value otherwise.
1813 : */
1814 : int spdk_bdev_quiesce(struct spdk_bdev *bdev, struct spdk_bdev_module *module,
1815 : spdk_bdev_quiesce_cb cb_fn, void *cb_arg);
1816 :
1817 : /**
1818 : * Unquiesce a previously quiesced bdev. All I/O queued after the bdev was quiesced
1819 : * will be submitted.
1820 : *
1821 : * Only the module that registered the bdev may call this function.
1822 : *
1823 : * \param bdev Block device.
1824 : * \param module The module that registered the bdev.
1825 : * \param cb_fn Callback function to be called when the bdev is unquiesced. Optional.
1826 : * \param cb_arg Argument to be supplied to cb_fn.
1827 : *
1828 : * \return 0 on success, or suitable errno value otherwise.
1829 : */
1830 : int spdk_bdev_unquiesce(struct spdk_bdev *bdev, struct spdk_bdev_module *module,
1831 : spdk_bdev_quiesce_cb cb_fn, void *cb_arg);
1832 :
1833 : /**
1834 : * Quiesce a bdev LBA range.
1835 : * Same as spdk_bdev_quiesce() but limited to the specified LBA range.
1836 : *
1837 : * \param bdev Block device.
1838 : * \param module The module that registered the bdev.
1839 : * \param offset The offset of the start of the range, in blocks,
1840 : * from the start of the block device.
1841 : * \param length The length of the range, in blocks.
1842 : * \param cb_fn Callback function to be called when the range is quiesced. Optional.
1843 : * \param cb_arg Argument to be supplied to cb_fn.
1844 : *
1845 : * \return 0 on success, or suitable errno value otherwise.
1846 : */
1847 : int spdk_bdev_quiesce_range(struct spdk_bdev *bdev, struct spdk_bdev_module *module,
1848 : uint64_t offset, uint64_t length,
1849 : spdk_bdev_quiesce_cb cb_fn, void *cb_arg);
1850 :
1851 : /**
1852 : * Unquiesce a previously quiesced bdev LBA range.
1853 : * Same as spdk_bdev_unquiesce() but limited to the specified LBA range.
1854 : * The specified range must match exactly a previously quiesced LBA range.
1855 : *
1856 : * \param bdev Block device.
1857 : * \param module The module that registered the bdev.
1858 : * \param offset The offset of the start of the range, in blocks,
1859 : * from the start of the block device.
1860 : * \param length The length of the range, in blocks.
1861 : * \param cb_fn Callback function to be called when the range is unquiesced. Optional.
1862 : * \param cb_arg Argument to be supplied to cb_fn.
1863 : *
1864 : * \return 0 on success, or suitable errno value otherwise.
1865 : */
1866 : int spdk_bdev_unquiesce_range(struct spdk_bdev *bdev, struct spdk_bdev_module *module,
1867 : uint64_t offset, uint64_t length,
1868 : spdk_bdev_quiesce_cb cb_fn, void *cb_arg);
1869 :
1870 : /*
1871 : * Macro used to register module for later initialization.
1872 : */
1873 : #define SPDK_BDEV_MODULE_REGISTER(name, module) \
1874 : static void __attribute__((constructor)) _spdk_bdev_module_register_##name(void) \
1875 : { \
1876 : spdk_bdev_module_list_add(module); \
1877 : }
1878 :
1879 : #endif /* __SPDK_BDEV_MODULE_ONLY */
1880 :
1881 : #ifdef __cplusplus
1882 : }
1883 : #endif
1884 :
1885 : #endif /* SPDK_BDEV_MODULE_H */
|