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