bdev_module.h File Reference

Block Device Module Interface. More...

Data Structures

struct  spdk_bdev_module
 Block device module. More...
 
struct  spdk_bdev_module::__bdev_module_internal_fields
 Fields that are used by the internal bdev subsystem. More...
 
struct  spdk_bdev_claim_opts
 Options used when requesting a claim. More...
 
struct  spdk_bdev_fn_table
 Function table for a block device backend. More...
 
struct  spdk_bdev_name
 
struct  spdk_bdev_alias
 
struct  spdk_bdev_module_claim
 
struct  spdk_bdev
 
struct  spdk_bdev::__bdev_internal_fields
 Fields that are used internally by the bdev subsystem. More...
 
union  spdk_bdev::__bdev_internal_fields::__bdev_internal_claim
 Which module has claimed this bdev. More...
 
struct  spdk_bdev::__bdev_internal_fields::__bdev_internal_claim::__bdev_internal_claim_v1
 Claims acquired with spdk_bdev_module_claim_bdev() More...
 
struct  spdk_bdev::__bdev_internal_fields::__bdev_internal_claim::__bdev_internal_claim_v2
 Claims acquired with spdk_bdev_module_claim_bdev_desc() More...
 
struct  spdk_bdev_io
 
struct  spdk_bdev_io::__bdev_io_internal_fields
 Fields that are used internally by the bdev subsystem. More...
 
struct  spdk_bdev_part
 
struct  spdk_bdev_part::bdev_part_internal_fields
 Fields that are used internally by part.c These fields should only be accessed from a module using any pertinent get and set methods. More...
 
struct  spdk_bdev_part_channel
 
struct  spdk_bdev_part_construct_opts
 Options used when constructing a part bdev. More...
 

Macros

#define SPDK_BDEV_CLAIM_NAME_LEN   32
 
#define SPDK_BDEV_RESET_IO_DRAIN_RECOMMENDED_VALUE   5
 
#define SPDK_BDEV_IO_NUM_CHILD_IOV   32
 
#define SPDK_BDEV_MODULE_REGISTER(name, module)
 

Typedefs

typedef void(* spdk_bdev_unregister_cb) (void *cb_arg, int rc)
 
typedef void(* spdk_bdev_io_get_buf_cb) (struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io, bool success)
 Callback when buffer is allocated for the bdev I/O. More...
 
typedef void(* spdk_bdev_io_get_aux_buf_cb) (struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io, void *aux_buf)
 Callback when an auxiliary buffer is allocated for the bdev I/O. More...
 
typedef void(* spdk_bdev_part_base_free_fn) (void *ctx)
 
typedef int(* spdk_bdev_io_fn) (void *ctx, struct spdk_bdev_io *bdev_io)
 
typedef void(* spdk_bdev_for_each_io_cb) (void *ctx, int rc)
 
typedef void(* spdk_bdev_get_current_qd_cb) (struct spdk_bdev *bdev, uint64_t current_qd, void *cb_arg, int rc)
 
typedef void(* spdk_bdev_quiesce_cb) (void *ctx, int status)
 

Enumerations

enum  spdk_bdev_claim_type {
  SPDK_BDEV_CLAIM_NONE = 0 , SPDK_BDEV_CLAIM_EXCL_WRITE , SPDK_BDEV_CLAIM_READ_MANY_WRITE_ONE , SPDK_BDEV_CLAIM_READ_MANY_WRITE_NONE ,
  SPDK_BDEV_CLAIM_READ_MANY_WRITE_SHARED
}
 Claim types. More...
 
enum  spdk_bdev_io_status {
  SPDK_BDEV_IO_STATUS_AIO_ERROR = -8 , SPDK_BDEV_IO_STATUS_ABORTED = -7 , SPDK_BDEV_IO_STATUS_FIRST_FUSED_FAILED = -6 , SPDK_BDEV_IO_STATUS_MISCOMPARE = -5 ,
  SPDK_BDEV_IO_STATUS_NOMEM = -4 , SPDK_BDEV_IO_STATUS_SCSI_ERROR = -3 , SPDK_BDEV_IO_STATUS_NVME_ERROR = -2 , SPDK_BDEV_IO_STATUS_FAILED = -1 ,
  SPDK_BDEV_IO_STATUS_PENDING = 0 , SPDK_BDEV_IO_STATUS_SUCCESS = 1 , SPDK_MIN_BDEV_IO_STATUS = SPDK_BDEV_IO_STATUS_AIO_ERROR
}
 bdev I/O completion status
 
enum  spdk_bdev_reset_stat_mode { SPDK_BDEV_RESET_STAT_ALL , SPDK_BDEV_RESET_STAT_MAXMIN }
 

Functions

 SPDK_STATIC_ASSERT (sizeof(struct spdk_bdev_claim_opts)==48, "Incorrect size")
 
const char * spdk_bdev_claim_get_name (enum spdk_bdev_claim_type claim_type)
 Retrieve the name of the bdev module claim type. More...
 
void spdk_bdev_claim_opts_init (struct spdk_bdev_claim_opts *opts, size_t size)
 Initialize bdev module claim options structure. More...
 
int spdk_bdev_module_claim_bdev_desc (struct spdk_bdev_desc *desc, enum spdk_bdev_claim_type type, struct spdk_bdev_claim_opts *opts, struct spdk_bdev_module *module)
 Claim the bdev referenced by the open descriptor. More...
 
int spdk_bdev_module_claim_bdev (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, struct spdk_bdev_module *module)
 Called by a bdev module to lay exclusive claim to a bdev. More...
 
void spdk_bdev_module_release_bdev (struct spdk_bdev *bdev)
 Called to release a write claim on a block device. More...
 
typedef TAILQ_HEAD (, spdk_bdev_io) bdev_io_tailq_t
 
typedef STAILQ_HEAD (, spdk_bdev_io) bdev_io_stailq_t
 
typedef TAILQ_HEAD (, lba_range) lba_range_tailq_t
 
int spdk_bdev_register (struct spdk_bdev *bdev)
 Register a new bdev. More...
 
void spdk_bdev_unregister (struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn, void *cb_arg)
 Start unregistering a bdev. More...
 
int spdk_bdev_unregister_by_name (const char *bdev_name, struct spdk_bdev_module *module, spdk_bdev_unregister_cb cb_fn, void *cb_arg)
 Start unregistering a bdev. More...
 
void spdk_bdev_destruct_done (struct spdk_bdev *bdev, int bdeverrno)
 Notify the bdev layer that an asynchronous destruct operation is complete. More...
 
void spdk_bdev_module_examine_done (struct spdk_bdev_module *module)
 Indicate to the bdev layer that the module is done examining a bdev. More...
 
void spdk_bdev_module_init_done (struct spdk_bdev_module *module)
 Indicate to the bdev layer that the module is done initializing. More...
 
void spdk_bdev_module_fini_done (void)
 Indicate that the module finish has completed. More...
 
void spdk_bdev_module_fini_start_done (void)
 Indicate that the module fini start has completed. More...
 
int spdk_bdev_alias_add (struct spdk_bdev *bdev, const char *alias)
 Add alias to block device names list. More...
 
int spdk_bdev_alias_del (struct spdk_bdev *bdev, const char *alias)
 Removes name from block device names list. More...
 
void spdk_bdev_alias_del_all (struct spdk_bdev *bdev)
 Removes all alias from block device alias list. More...
 
const struct spdk_bdev_aliases_list * spdk_bdev_get_aliases (const struct spdk_bdev *bdev)
 Get pointer to block device aliases list. More...
 
void spdk_bdev_io_get_buf (struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb, uint64_t len)
 Allocate a buffer for given bdev_io. More...
 
void spdk_bdev_io_get_aux_buf (struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_aux_buf_cb cb)
 Allocate an auxiliary buffer for given bdev_io. More...
 
void spdk_bdev_io_put_aux_buf (struct spdk_bdev_io *bdev_io, void *aux_buf)
 Free an auxiliary buffer previously allocated by spdk_bdev_io_get_aux_buf(). More...
 
void spdk_bdev_io_set_buf (struct spdk_bdev_io *bdev_io, void *buf, size_t len)
 Set the given buffer as the data buffer described by this bdev_io. More...
 
void spdk_bdev_io_set_md_buf (struct spdk_bdev_io *bdev_io, void *md_buf, size_t len)
 Set the given buffer as metadata buffer described by this bdev_io. More...
 
void spdk_bdev_io_complete (struct spdk_bdev_io *bdev_io, enum spdk_bdev_io_status status)
 Complete a bdev_io. More...
 
void spdk_bdev_io_complete_nvme_status (struct spdk_bdev_io *bdev_io, uint32_t cdw0, int sct, int sc)
 Complete a bdev_io with an NVMe status code and DW0 completion queue entry. More...
 
void spdk_bdev_io_complete_scsi_status (struct spdk_bdev_io *bdev_io, enum spdk_scsi_status sc, enum spdk_scsi_sense sk, uint8_t asc, uint8_t ascq)
 Complete a bdev_io with a SCSI status code. More...
 
void spdk_bdev_io_complete_aio_status (struct spdk_bdev_io *bdev_io, int aio_result)
 Complete a bdev_io with AIO errno. More...
 
void spdk_bdev_io_complete_base_io_status (struct spdk_bdev_io *bdev_io, const struct spdk_bdev_io *base_io)
 Complete a bdev_io copying a status from another bdev_io. More...
 
struct spdk_thread * spdk_bdev_io_get_thread (struct spdk_bdev_io *bdev_io)
 Get a thread that given bdev_io was submitted on. More...
 
struct spdk_io_channel * spdk_bdev_io_get_io_channel (struct spdk_bdev_io *bdev_io)
 Get the bdev module's I/O channel that the given bdev_io was submitted on. More...
 
uint64_t spdk_bdev_io_get_submit_tsc (struct spdk_bdev_io *bdev_io)
 Get the submit_tsc of a bdev I/O. More...
 
int spdk_bdev_notify_blockcnt_change (struct spdk_bdev *bdev, uint64_t size)
 Resize for a bdev. More...
 
void spdk_scsi_nvme_translate (const struct spdk_bdev_io *bdev_io, int *sc, int *sk, int *asc, int *ascq)
 Translates NVMe status codes to SCSI status information. More...
 
void spdk_bdev_module_list_add (struct spdk_bdev_module *bdev_module)
 Add the given module to the list of registered modules. More...
 
struct spdk_bdev_modulespdk_bdev_module_list_find (const char *name)
 Find registered module with name pointed by name. More...
 
static struct spdk_bdev_iospdk_bdev_io_from_ctx (void *ctx)
 
struct spdk_bdevspdk_bdev_part_base_get_bdev (struct spdk_bdev_part_base *part_base)
 Returns a pointer to the spdk_bdev associated with an spdk_bdev_part_base. More...
 
const char * spdk_bdev_part_base_get_bdev_name (struct spdk_bdev_part_base *part_base)
 Returns a spdk_bdev name of the corresponding spdk_bdev_part_base. More...
 
struct spdk_bdev_desc * spdk_bdev_part_base_get_desc (struct spdk_bdev_part_base *part_base)
 Returns a pointer to the spdk_bdev_descriptor associated with an spdk_bdev_part_base. More...
 
struct bdev_part_tailq * spdk_bdev_part_base_get_tailq (struct spdk_bdev_part_base *part_base)
 Returns a pointer to the tailq associated with an spdk_bdev_part_base. More...
 
void * spdk_bdev_part_base_get_ctx (struct spdk_bdev_part_base *part_base)
 Returns a pointer to the module level context associated with an spdk_bdev_part_base. More...
 
typedef TAILQ_HEAD (bdev_part_tailq, spdk_bdev_part) SPDK_BDEV_PART_TAILQ
 
void spdk_bdev_part_base_free (struct spdk_bdev_part_base *base)
 Free the base corresponding to one or more spdk_bdev_part. More...
 
int spdk_bdev_part_free (struct spdk_bdev_part *part)
 Free an spdk_bdev_part context. More...
 
void spdk_bdev_part_base_hotremove (struct spdk_bdev_part_base *part_base, struct bdev_part_tailq *tailq)
 Calls spdk_bdev_unregister on the bdev for each part associated with base_bdev. More...
 
int spdk_bdev_part_base_construct_ext (const char *bdev_name, spdk_bdev_remove_cb_t remove_cb, struct spdk_bdev_module *module, struct spdk_bdev_fn_table *fn_table, struct bdev_part_tailq *tailq, spdk_bdev_part_base_free_fn free_fn, void *ctx, uint32_t channel_size, spdk_io_channel_create_cb ch_create_cb, spdk_io_channel_destroy_cb ch_destroy_cb, struct spdk_bdev_part_base **base)
 Construct a new spdk_bdev_part_base on top of the provided bdev. More...
 
 SPDK_STATIC_ASSERT (sizeof(struct spdk_bdev_part_construct_opts)==24, "Incorrect size")
 
void spdk_bdev_part_construct_opts_init (struct spdk_bdev_part_construct_opts *opts, uint64_t size)
 Initialize options that will be passed to spdk_bdev_part_construct_ext(). More...
 
int spdk_bdev_part_construct (struct spdk_bdev_part *part, struct spdk_bdev_part_base *base, char *name, uint64_t offset_blocks, uint64_t num_blocks, char *product_name)
 Create a logical spdk_bdev_part on top of a base. More...
 
int spdk_bdev_part_construct_ext (struct spdk_bdev_part *part, struct spdk_bdev_part_base *base, char *name, uint64_t offset_blocks, uint64_t num_blocks, char *product_name, const struct spdk_bdev_part_construct_opts *opts)
 Create a logical spdk_bdev_part on top of a base with a non-NULL bdev UUID. More...
 
int spdk_bdev_part_submit_request (struct spdk_bdev_part_channel *ch, struct spdk_bdev_io *bdev_io)
 Forwards I/O from an spdk_bdev_part to the underlying base bdev. More...
 
int spdk_bdev_part_submit_request_ext (struct spdk_bdev_part_channel *ch, struct spdk_bdev_io *bdev_io, spdk_bdev_io_completion_cb cb)
 Forwards I/O from an spdk_bdev_part to the underlying base bdev. More...
 
struct spdk_bdevspdk_bdev_part_get_bdev (struct spdk_bdev_part *part)
 Return a pointer to this part's spdk_bdev. More...
 
struct spdk_bdev_part_base * spdk_bdev_part_get_base (struct spdk_bdev_part *part)
 Return a pointer to this part's base. More...
 
struct spdk_bdevspdk_bdev_part_get_base_bdev (struct spdk_bdev_part *part)
 Return a pointer to this part's base bdev. More...
 
uint64_t spdk_bdev_part_get_offset_blocks (struct spdk_bdev_part *part)
 Return this part's offset from the beginning of the base bdev. More...
 
int spdk_bdev_push_media_events (struct spdk_bdev *bdev, const struct spdk_bdev_media_event *events, size_t num_events)
 Push media management events. More...
 
void spdk_bdev_notify_media_management (struct spdk_bdev *bdev)
 Send SPDK_BDEV_EVENT_MEDIA_MANAGEMENT to all open descriptors that have pending media events. More...
 
void spdk_bdev_for_each_bdev_io (struct spdk_bdev *bdev, void *ctx, spdk_bdev_io_fn fn, spdk_bdev_for_each_io_cb cb)
 Call the provided function on the appropriate thread for each bdev_io submitted to the provided bdev. More...
 
void spdk_bdev_get_current_qd (struct spdk_bdev *bdev, spdk_bdev_get_current_qd_cb cb_fn, void *cb_arg)
 Measure and return the queue depth from a bdev. More...
 
void spdk_bdev_add_io_stat (struct spdk_bdev_io_stat *total, struct spdk_bdev_io_stat *add)
 Add I/O statictics. More...
 
void spdk_bdev_dump_io_stat_json (struct spdk_bdev_io_stat *stat, struct spdk_json_write_ctx *w)
 Output bdev I/O statictics information to a JSON stream. More...
 
void spdk_bdev_reset_io_stat (struct spdk_bdev_io_stat *stat, enum spdk_bdev_reset_stat_mode mode)
 Reset I/O statictics structure. More...
 
int spdk_bdev_quiesce (struct spdk_bdev *bdev, struct spdk_bdev_module *module, spdk_bdev_quiesce_cb cb_fn, void *cb_arg)
 Quiesce a bdev. More...
 
int spdk_bdev_unquiesce (struct spdk_bdev *bdev, struct spdk_bdev_module *module, spdk_bdev_quiesce_cb cb_fn, void *cb_arg)
 Unquiesce a previously quiesced bdev. More...
 
int spdk_bdev_quiesce_range (struct spdk_bdev *bdev, struct spdk_bdev_module *module, uint64_t offset, uint64_t length, spdk_bdev_quiesce_cb cb_fn, void *cb_arg)
 Quiesce a bdev LBA range. More...
 
int spdk_bdev_unquiesce_range (struct spdk_bdev *bdev, struct spdk_bdev_module *module, uint64_t offset, uint64_t length, spdk_bdev_quiesce_cb cb_fn, void *cb_arg)
 Unquiesce a previously quiesced bdev LBA range. More...
 

Detailed Description

Block Device Module Interface.

For information on how to write a bdev module, see Writing a Custom Block Device Module.

Macro Definition Documentation

◆ SPDK_BDEV_MODULE_REGISTER

#define SPDK_BDEV_MODULE_REGISTER (   name,
  module 
)
Value:
static void __attribute__((constructor)) _spdk_bdev_module_register_##name(void) \
{ \
spdk_bdev_module_list_add(module); \
}

Typedef Documentation

◆ spdk_bdev_io_get_aux_buf_cb

typedef void(* spdk_bdev_io_get_aux_buf_cb) (struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io, void *aux_buf)

Callback when an auxiliary buffer is allocated for the bdev I/O.

Parameters
chThe I/O channel the bdev I/O was handled on.
bdev_ioThe bdev I/O
aux_bufPointer to the allocated buffer. NULL if there was a failure such as the size of the buffer to allocate is greater than the permitted maximum.

◆ spdk_bdev_io_get_buf_cb

typedef void(* spdk_bdev_io_get_buf_cb) (struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io, bool success)

Callback when buffer is allocated for the bdev I/O.

Parameters
chThe I/O channel the bdev I/O was handled on.
bdev_ioThe bdev I/O
successTrue if buffer is allocated successfully or the bdev I/O has an SGL assigned already, or false if it failed. The possible reason of failure is the size of the buffer to allocate is greater than the permitted maximum.

Enumeration Type Documentation

◆ spdk_bdev_claim_type

Claim types.

Enumerator
SPDK_BDEV_CLAIM_EXCL_WRITE 

Exclusive writer, with allowances for legacy behavior.

This matches the behavior of spdk_bdev_module_claim_bdev() as of SPDK 22.09. New consumer should use SPDK_BDEV_CLAIM_READ_MANY_WRITE_ONE instead.

SPDK_BDEV_CLAIM_READ_MANY_WRITE_ONE 

The descriptor passed with this claim request is the only writer.

Other claimless readers are allowed.

SPDK_BDEV_CLAIM_READ_MANY_WRITE_NONE 

Any number of readers, no writers.

Readers without a claim are allowed.

SPDK_BDEV_CLAIM_READ_MANY_WRITE_SHARED 

Any number of writers with matching shared_claim_key.

After the first writer establishes a claim, future aspiring writers should open read-only and pass the read-only descriptor. If the shared claim is granted to the aspiring writer, the descriptor will be upgraded to read-write.

Function Documentation

◆ spdk_bdev_add_io_stat()

void spdk_bdev_add_io_stat ( struct spdk_bdev_io_stat total,
struct spdk_bdev_io_stat add 
)

Add I/O statictics.

Parameters
totalThe aggregated I/O statictics.
addThe I/O statictics to be added.

◆ spdk_bdev_alias_add()

int spdk_bdev_alias_add ( struct spdk_bdev bdev,
const char *  alias 
)

Add alias to block device names list.

Aliases can be add only to registered bdev.

Parameters
bdevBlock device to query.
aliasAlias to be added to list.
Returns
0 on success
-EEXIST if alias already exists as name or alias on any bdev
-ENOMEM if memory cannot be allocated to store alias
-EINVAL if passed alias is empty

◆ spdk_bdev_alias_del()

int spdk_bdev_alias_del ( struct spdk_bdev bdev,
const char *  alias 
)

Removes name from block device names list.

Parameters
bdevBlock device to query.
aliasAlias to be deleted from list.
Returns
0 on success
-ENOENT if alias does not exists

◆ spdk_bdev_alias_del_all()

void spdk_bdev_alias_del_all ( struct spdk_bdev bdev)

Removes all alias from block device alias list.

Parameters
bdevBlock device to operate.

◆ spdk_bdev_claim_get_name()

const char* spdk_bdev_claim_get_name ( enum spdk_bdev_claim_type  claim_type)

Retrieve the name of the bdev module claim type.

The mapping between claim types and their names is:

SPDK_BDEV_CLAIM_NONE "not_claimed" SPDK_BDEV_CLAIM_EXCL_WRITE "exclusive_write" SPDK_BDEV_CLAIM_READ_MANY_WRITE_ONE "read_many_write_one" SPDK_BDEV_CLAIM_READ_MANY_WRITE_NONE "read_many_write_none" SPDK_BDEV_CLAIM_READ_MANY_WRITE_SHARED "read_many_write_shared"

Any other value will return "invalid_claim".

Parameters
claim_typeThe claim type.
Returns
A string that describes the claim type.

◆ spdk_bdev_claim_opts_init()

void spdk_bdev_claim_opts_init ( struct spdk_bdev_claim_opts opts,
size_t  size 
)

Initialize bdev module claim options structure.

Parameters
optsThe structure to initialize.
sizeThe size of *opts.

◆ spdk_bdev_destruct_done()

void spdk_bdev_destruct_done ( struct spdk_bdev bdev,
int  bdeverrno 
)

Notify the bdev layer that an asynchronous destruct operation is complete.

A Bdev with an asynchronous destruct path should return 1 from its destruct function and call this function at the conclusion of that path. Bdevs with synchronous destruct paths should return 0 from their destruct path.

Parameters
bdevBlock device that was destroyed.
bdeverrnoError code returned from bdev's destruct callback.

◆ spdk_bdev_dump_io_stat_json()

void spdk_bdev_dump_io_stat_json ( struct spdk_bdev_io_stat stat,
struct spdk_json_write_ctx *  w 
)

Output bdev I/O statictics information to a JSON stream.

Parameters
statThe bdev I/O statictics to output.
wJSON write context.

◆ spdk_bdev_for_each_bdev_io()

void spdk_bdev_for_each_bdev_io ( struct spdk_bdev bdev,
void *  ctx,
spdk_bdev_io_fn  fn,
spdk_bdev_for_each_io_cb  cb 
)

Call the provided function on the appropriate thread for each bdev_io submitted to the provided bdev.

Note: This function should be used only in the bdev module and it should be ensured that the bdev is not unregistered while executing the function. Both fn and cb are required to specify.

Parameters
bdevBlock device to query.
ctxContext passed to the function for each bdev_io and the completion callback function.
fnCalled on the appropriate thread for each bdev_io submitted to the bdev.
cbCalled when this operation completes.

◆ spdk_bdev_get_aliases()

const struct spdk_bdev_aliases_list* spdk_bdev_get_aliases ( const struct spdk_bdev bdev)

Get pointer to block device aliases list.

Parameters
bdevBlock device to query.
Returns
Pointer to bdev aliases list.

◆ spdk_bdev_get_current_qd()

void spdk_bdev_get_current_qd ( struct spdk_bdev bdev,
spdk_bdev_get_current_qd_cb  cb_fn,
void *  cb_arg 
)

Measure and return the queue depth from a bdev.

Note: spdk_bdev_get_qd() works only when the user enables queue depth sampling, while this new function works even when queue depth sampling is disabled. The returned queue depth may not be exact, for example, some additional I/Os may have been submitted or completed during the for_each_channel operation. This function should be used only in the bdev module and it should be ensured that the dev is not unregistered while executing the function. cb_fn is required to specify.

Parameters
bdevBlock device to query.
cb_fnCallback function to be called with queue depth measured for a bdev.
cb_argArgument to pass to callback function.

◆ spdk_bdev_io_complete()

void spdk_bdev_io_complete ( struct spdk_bdev_io bdev_io,
enum spdk_bdev_io_status  status 
)

Complete a bdev_io.

Parameters
bdev_ioI/O to complete.
statusThe I/O completion status.

◆ spdk_bdev_io_complete_aio_status()

void spdk_bdev_io_complete_aio_status ( struct spdk_bdev_io bdev_io,
int  aio_result 
)

Complete a bdev_io with AIO errno.

Parameters
bdev_ioI/O to complete.
aio_resultNegative errno returned from AIO.

◆ spdk_bdev_io_complete_base_io_status()

void spdk_bdev_io_complete_base_io_status ( struct spdk_bdev_io bdev_io,
const struct spdk_bdev_io base_io 
)

Complete a bdev_io copying a status from another bdev_io.

Parameters
bdev_ioI/O to complete.
base_ioI/O from which to copy the status.

◆ spdk_bdev_io_complete_nvme_status()

void spdk_bdev_io_complete_nvme_status ( struct spdk_bdev_io bdev_io,
uint32_t  cdw0,
int  sct,
int  sc 
)

Complete a bdev_io with an NVMe status code and DW0 completion queue entry.

Parameters
bdev_ioI/O to complete.
cdw0NVMe Completion Queue DW0 value (set to 0 if not applicable)
sctNVMe Status Code Type.
scNVMe Status Code.

◆ spdk_bdev_io_complete_scsi_status()

void spdk_bdev_io_complete_scsi_status ( struct spdk_bdev_io bdev_io,
enum spdk_scsi_status  sc,
enum spdk_scsi_sense  sk,
uint8_t  asc,
uint8_t  ascq 
)

Complete a bdev_io with a SCSI status code.

Parameters
bdev_ioI/O to complete.
scSCSI Status Code.
skSCSI Sense Key.
ascSCSI Additional Sense Code.
ascqSCSI Additional Sense Code Qualifier.

◆ spdk_bdev_io_get_aux_buf()

void spdk_bdev_io_get_aux_buf ( struct spdk_bdev_io bdev_io,
spdk_bdev_io_get_aux_buf_cb  cb 
)

Allocate an auxiliary buffer for given bdev_io.

The length of the buffer will be the same size as the bdev_io primary buffer. The buffer must be freed using spdk_bdev_io_put_aux_buf() before completing the associated bdev_io. This call will never fail. In case of lack of memory given callback cb will be deferred until enough memory is freed.

Parameters
bdev_ioI/O to allocate buffer for.
cbcallback to be called when the buffer is allocated

◆ spdk_bdev_io_get_buf()

void spdk_bdev_io_get_buf ( struct spdk_bdev_io bdev_io,
spdk_bdev_io_get_buf_cb  cb,
uint64_t  len 
)

Allocate a buffer for given bdev_io.

Allocation will happen only if the bdev_io has no assigned SGL yet or SGL is not aligned to bdev->required_alignment. If SGL is not aligned, this call will cause copy from SGL to bounce buffer on write path or copy from bounce buffer to SGL before completion callback on read path. The buffer will be freed automatically on spdk_bdev_free_io() call. This call will never fail. In case of lack of memory given callback cb will be deferred until enough memory is freed. This function must be called from the thread issuing bdev_io.

Parameters
bdev_ioI/O to allocate buffer for.
cbcallback to be called when the buffer is allocated or the bdev_io has an SGL assigned already.
lensize of the buffer to allocate. In case the bdev_io doesn't have an SGL assigned this field must be no bigger than SPDK_BDEV_LARGE_BUF_MAX_SIZE.

◆ spdk_bdev_io_get_io_channel()

struct spdk_io_channel* spdk_bdev_io_get_io_channel ( struct spdk_bdev_io bdev_io)

Get the bdev module's I/O channel that the given bdev_io was submitted on.

Parameters
bdev_ioI/O
Returns
the bdev module's I/O channel that the given bdev_io was submitted on.

◆ spdk_bdev_io_get_submit_tsc()

uint64_t spdk_bdev_io_get_submit_tsc ( struct spdk_bdev_io bdev_io)

Get the submit_tsc of a bdev I/O.

Parameters
bdev_ioThe bdev I/O to get the submit_tsc.
Returns
The submit_tsc of the specified bdev I/O.

◆ spdk_bdev_io_get_thread()

struct spdk_thread* spdk_bdev_io_get_thread ( struct spdk_bdev_io bdev_io)

Get a thread that given bdev_io was submitted on.

Parameters
bdev_ioI/O
Returns
thread that submitted the I/O

◆ spdk_bdev_io_put_aux_buf()

void spdk_bdev_io_put_aux_buf ( struct spdk_bdev_io bdev_io,
void *  aux_buf 
)

Free an auxiliary buffer previously allocated by spdk_bdev_io_get_aux_buf().

Parameters
bdev_iobdev_io specified when the aux_buf was allocated.
aux_bufauxiliary buffer to free

◆ spdk_bdev_io_set_buf()

void spdk_bdev_io_set_buf ( struct spdk_bdev_io bdev_io,
void *  buf,
size_t  len 
)

Set the given buffer as the data buffer described by this bdev_io.

The portion of the buffer used may be adjusted for memory alignment purposes.

Parameters
bdev_ioI/O to set the buffer on.
bufThe buffer to set as the active data buffer.
lenThe length of the buffer.

◆ spdk_bdev_io_set_md_buf()

void spdk_bdev_io_set_md_buf ( struct spdk_bdev_io bdev_io,
void *  md_buf,
size_t  len 
)

Set the given buffer as metadata buffer described by this bdev_io.

Parameters
bdev_ioI/O to set the buffer on.
md_bufThe buffer to set as the active metadata buffer.
lenThe length of the metadata buffer.

◆ spdk_bdev_module_claim_bdev()

int spdk_bdev_module_claim_bdev ( struct spdk_bdev bdev,
struct spdk_bdev_desc *  desc,
struct spdk_bdev_module module 
)

Called by a bdev module to lay exclusive claim to a bdev.

Also upgrades that bdev's descriptor to have write access if desc is not NULL.

Parameters
bdevBlock device to be claimed.
descDescriptor for the above block device or NULL.
moduleBdev module attempting to claim bdev.
Returns
0 on success
-EPERM if the bdev is already claimed by another module.

◆ spdk_bdev_module_claim_bdev_desc()

int spdk_bdev_module_claim_bdev_desc ( struct spdk_bdev_desc *  desc,
enum spdk_bdev_claim_type  type,
struct spdk_bdev_claim_opts opts,
struct spdk_bdev_module module 
)

Claim the bdev referenced by the open descriptor.

The claim is released as the descriptor is closed.

Parameters
descAn open bdev descriptor. Some claim types may upgrade this from read-only to read-write.
typeThe type of claim to establish.
optsNULL or options required by the particular claim type.
moduleThe bdev module making this claim.
Returns
0 on success
-ENOMEM if insufficient memory to track the claim
-EBUSY if the claim cannot be granted due to a conflict
-EINVAL if the claim type required options that were not passed or required parameters were NULL.

◆ spdk_bdev_module_examine_done()

void spdk_bdev_module_examine_done ( struct spdk_bdev_module module)

Indicate to the bdev layer that the module is done examining a bdev.

To be called during examine_config function or asynchronously in response to the module's examine_disk function being called.

Parameters
modulePointer to the module completing the examination.

◆ spdk_bdev_module_fini_done()

void spdk_bdev_module_fini_done ( void  )

Indicate that the module finish has completed.

To be called in response to the module_fini, only if async_fini is set.

◆ spdk_bdev_module_fini_start_done()

void spdk_bdev_module_fini_start_done ( void  )

Indicate that the module fini start has completed.

To be called in response to the fini_start, only if async_fini_start is set. May be called during fini_start or asynchronously.

◆ spdk_bdev_module_init_done()

void spdk_bdev_module_init_done ( struct spdk_bdev_module module)

Indicate to the bdev layer that the module is done initializing.

To be called once after an asynchronous operation required for module initialization is completed. If module->async_init is false, the module must not call this function.

Parameters
modulePointer to the module completing the initialization.

◆ spdk_bdev_module_list_add()

void spdk_bdev_module_list_add ( struct spdk_bdev_module bdev_module)

Add the given module to the list of registered modules.

This function should be invoked by referencing the macro SPDK_BDEV_MODULE_REGISTER in the module c file.

Parameters
bdev_moduleModule to be added.

◆ spdk_bdev_module_list_find()

struct spdk_bdev_module* spdk_bdev_module_list_find ( const char *  name)

Find registered module with name pointed by name.

Parameters
namename of module to be searched for.
Returns
pointer to module or NULL if no module with name exist

◆ spdk_bdev_module_release_bdev()

void spdk_bdev_module_release_bdev ( struct spdk_bdev bdev)

Called to release a write claim on a block device.

Parameters
bdevBlock device to be released.

◆ spdk_bdev_notify_blockcnt_change()

int spdk_bdev_notify_blockcnt_change ( struct spdk_bdev bdev,
uint64_t  size 
)

Resize for a bdev.

Change number of blocks for provided block device. It can only be called on a registered bdev.

Parameters
bdevBlock device to change.
sizeNew size of bdev.
Returns
0 on success, negated errno on failure.

◆ spdk_bdev_notify_media_management()

void spdk_bdev_notify_media_management ( struct spdk_bdev bdev)

Send SPDK_BDEV_EVENT_MEDIA_MANAGEMENT to all open descriptors that have pending media events.

Parameters
bdevBlock device

◆ spdk_bdev_part_base_construct_ext()

int spdk_bdev_part_base_construct_ext ( const char *  bdev_name,
spdk_bdev_remove_cb_t  remove_cb,
struct spdk_bdev_module module,
struct spdk_bdev_fn_table fn_table,
struct bdev_part_tailq *  tailq,
spdk_bdev_part_base_free_fn  free_fn,
void *  ctx,
uint32_t  channel_size,
spdk_io_channel_create_cb  ch_create_cb,
spdk_io_channel_destroy_cb  ch_destroy_cb,
struct spdk_bdev_part_base **  base 
)

Construct a new spdk_bdev_part_base on top of the provided bdev.

Parameters
bdev_nameName of the bdev upon which this base will be built.
remove_cbFunction to be called upon hotremove of the bdev.
moduleThe module to which this bdev base belongs.
fn_tableFunction table for communicating with the bdev backend.
tailqThe head of the list of all spdk_bdev_part structures registered to this base's module.
free_fnUser provided function to free base related context upon bdev removal or shutdown.
ctxModule specific context for this bdev part base.
channel_sizeChannel size in bytes.
ch_create_cbCalled after a new channel is allocated.
ch_destroy_cbCalled upon channel deletion.
baseoutput parameter for the part object when operation is successful.
Returns
0 if operation is successful, or suitable errno value otherwise.

◆ spdk_bdev_part_base_free()

void spdk_bdev_part_base_free ( struct spdk_bdev_part_base *  base)

Free the base corresponding to one or more spdk_bdev_part.

Parameters
baseThe base to free.

◆ spdk_bdev_part_base_get_bdev()

struct spdk_bdev* spdk_bdev_part_base_get_bdev ( struct spdk_bdev_part_base *  part_base)

Returns a pointer to the spdk_bdev associated with an spdk_bdev_part_base.

Parameters
part_baseA pointer to an spdk_bdev_part_base object.
Returns
A pointer to the base's spdk_bdev struct.

◆ spdk_bdev_part_base_get_bdev_name()

const char* spdk_bdev_part_base_get_bdev_name ( struct spdk_bdev_part_base *  part_base)

Returns a spdk_bdev name of the corresponding spdk_bdev_part_base.

Parameters
part_baseA pointer to an spdk_bdev_part_base object.
Returns
A text string representing the name of the base bdev.

◆ spdk_bdev_part_base_get_ctx()

void* spdk_bdev_part_base_get_ctx ( struct spdk_bdev_part_base *  part_base)

Returns a pointer to the module level context associated with an spdk_bdev_part_base.

Parameters
part_baseA pointer to an spdk_bdev_part_base object.
Returns
A pointer to the module level context registered with the base in spdk_bdev_part_base_construct.

◆ spdk_bdev_part_base_get_desc()

struct spdk_bdev_desc* spdk_bdev_part_base_get_desc ( struct spdk_bdev_part_base *  part_base)

Returns a pointer to the spdk_bdev_descriptor associated with an spdk_bdev_part_base.

Parameters
part_baseA pointer to an spdk_bdev_part_base object.
Returns
A pointer to the base's spdk_bdev_desc struct.

◆ spdk_bdev_part_base_get_tailq()

struct bdev_part_tailq* spdk_bdev_part_base_get_tailq ( struct spdk_bdev_part_base *  part_base)

Returns a pointer to the tailq associated with an spdk_bdev_part_base.

Parameters
part_baseA pointer to an spdk_bdev_part_base object.
Returns
The head of a tailq of spdk_bdev_part structs registered to the base's module.

◆ spdk_bdev_part_base_hotremove()

void spdk_bdev_part_base_hotremove ( struct spdk_bdev_part_base *  part_base,
struct bdev_part_tailq *  tailq 
)

Calls spdk_bdev_unregister on the bdev for each part associated with base_bdev.

Parameters
part_baseThe part base object built on top of an spdk_bdev
tailqThe list of spdk_bdev_part bdevs associated with this base bdev.

◆ spdk_bdev_part_construct()

int spdk_bdev_part_construct ( struct spdk_bdev_part part,
struct spdk_bdev_part_base *  base,
char *  name,
uint64_t  offset_blocks,
uint64_t  num_blocks,
char *  product_name 
)

Create a logical spdk_bdev_part on top of a base.

Parameters
partThe part object allocated by the user.
baseThe base from which to create the part.
nameThe name of the new spdk_bdev_part.
offset_blocksThe offset into the base bdev at which this part begins.
num_blocksThe number of blocks that this part will span.
product_nameUnique name for this type of block device.
Returns
0 on success.
-1 if the bases underlying bdev cannot be claimed by the current module.

◆ spdk_bdev_part_construct_ext()

int spdk_bdev_part_construct_ext ( struct spdk_bdev_part part,
struct spdk_bdev_part_base *  base,
char *  name,
uint64_t  offset_blocks,
uint64_t  num_blocks,
char *  product_name,
const struct spdk_bdev_part_construct_opts opts 
)

Create a logical spdk_bdev_part on top of a base with a non-NULL bdev UUID.

Parameters
partThe part object allocated by the user.
baseThe base from which to create the part.
nameThe name of the new spdk_bdev_part.
offset_blocksThe offset into the base bdev at which this part begins.
num_blocksThe number of blocks that this part will span.
product_nameUnique name for this type of block device.
optsAdditional options.
Returns
0 on success.
-1 if the bases underlying bdev cannot be claimed by the current module.

◆ spdk_bdev_part_construct_opts_init()

void spdk_bdev_part_construct_opts_init ( struct spdk_bdev_part_construct_opts opts,
uint64_t  size 
)

Initialize options that will be passed to spdk_bdev_part_construct_ext().

Parameters
optsOptions structure to initialize
sizeSize of opts structure.

◆ spdk_bdev_part_free()

int spdk_bdev_part_free ( struct spdk_bdev_part part)

Free an spdk_bdev_part context.

Parameters
partThe part to free.
Returns
1 always. To indicate that the operation is asynchronous.

◆ spdk_bdev_part_get_base()

struct spdk_bdev_part_base* spdk_bdev_part_get_base ( struct spdk_bdev_part part)

Return a pointer to this part's base.

Parameters
partAn spdk_bdev_part object.
Returns
A pointer to this part's spdk_bdev_part_base object.

◆ spdk_bdev_part_get_base_bdev()

struct spdk_bdev* spdk_bdev_part_get_base_bdev ( struct spdk_bdev_part part)

Return a pointer to this part's base bdev.

The return value of this function is equivalent to calling spdk_bdev_part_base_get_bdev on this part's base.

Parameters
partAn spdk_bdev_part object.
Returns
A pointer to the bdev belonging to this part's base.

◆ spdk_bdev_part_get_bdev()

struct spdk_bdev* spdk_bdev_part_get_bdev ( struct spdk_bdev_part part)

Return a pointer to this part's spdk_bdev.

Parameters
partAn spdk_bdev_part object.
Returns
A pointer to this part's spdk_bdev object.

◆ spdk_bdev_part_get_offset_blocks()

uint64_t spdk_bdev_part_get_offset_blocks ( struct spdk_bdev_part part)

Return this part's offset from the beginning of the base bdev.

This function should not be called in the I/O path. Any block translations to I/O will be handled in spdk_bdev_part_submit_request.

Parameters
partAn spdk_bdev_part object.
Returns
the block offset of this part from it's underlying bdev.

◆ spdk_bdev_part_submit_request()

int spdk_bdev_part_submit_request ( struct spdk_bdev_part_channel ch,
struct spdk_bdev_io bdev_io 
)

Forwards I/O from an spdk_bdev_part to the underlying base bdev.

This function will apply the offset_blocks the user provided to spdk_bdev_part_construct to the I/O. The user should not manually apply this offset before submitting any I/O through this function.

Parameters
chThe I/O channel associated with the spdk_bdev_part.
bdev_ioThe I/O to be submitted to the underlying bdev.
Returns
0 on success or non-zero if submit request failed.

◆ spdk_bdev_part_submit_request_ext()

int spdk_bdev_part_submit_request_ext ( struct spdk_bdev_part_channel ch,
struct spdk_bdev_io bdev_io,
spdk_bdev_io_completion_cb  cb 
)

Forwards I/O from an spdk_bdev_part to the underlying base bdev.

This function will apply the offset_blocks the user provided to spdk_bdev_part_construct to the I/O. The user should not manually apply this offset before submitting any I/O through this function.

This function enables user to specify a completion callback. It is required that the completion callback calls spdk_bdev_io_complete() for the forwarded I/O.

Parameters
chThe I/O channel associated with the spdk_bdev_part.
bdev_ioThe I/O to be submitted to the underlying bdev.
cbCalled when the forwarded I/O completes.
Returns
0 on success or non-zero if submit request failed.

◆ spdk_bdev_push_media_events()

int spdk_bdev_push_media_events ( struct spdk_bdev bdev,
const struct spdk_bdev_media_event events,
size_t  num_events 
)

Push media management events.

To send the notification that new events are available, spdk_bdev_notify_media_management needs to be called.

Parameters
bdevBlock device
eventsArray of media events
num_eventsSize of the events array
Returns
number of events pushed or negative errno in case of failure

◆ spdk_bdev_quiesce()

int spdk_bdev_quiesce ( struct spdk_bdev bdev,
struct spdk_bdev_module module,
spdk_bdev_quiesce_cb  cb_fn,
void *  cb_arg 
)

Quiesce a bdev.

All I/O submitted after this function is called will be queued until the bdev is unquiesced. A callback will be called when all outstanding I/O on this bdev submitted before calling this function have completed.

Only the module that registered the bdev may call this function.

Parameters
bdevBlock device.
moduleThe module that registered the bdev.
cb_fnCallback function to be called when the bdev is quiesced. Optional.
cb_argArgument to be supplied to cb_fn.
Returns
0 on success, or suitable errno value otherwise.

◆ spdk_bdev_quiesce_range()

int spdk_bdev_quiesce_range ( struct spdk_bdev bdev,
struct spdk_bdev_module module,
uint64_t  offset,
uint64_t  length,
spdk_bdev_quiesce_cb  cb_fn,
void *  cb_arg 
)

Quiesce a bdev LBA range.

Same as spdk_bdev_quiesce() but limited to the specified LBA range.

Parameters
bdevBlock device.
moduleThe module that registered the bdev.
offsetThe offset of the start of the range, in blocks, from the start of the block device.
lengthThe length of the range, in blocks.
cb_fnCallback function to be called when the range is quiesced. Optional.
cb_argArgument to be supplied to cb_fn.
Returns
0 on success, or suitable errno value otherwise.

◆ spdk_bdev_register()

int spdk_bdev_register ( struct spdk_bdev bdev)

Register a new bdev.

This function must be called from the SPDK app thread.

Parameters
bdevBlock device to register.
Returns
0 on success.
-EINVAL if the bdev name is NULL.
-EEXIST if a bdev or bdev alias with the same name already exists.

◆ spdk_bdev_reset_io_stat()

void spdk_bdev_reset_io_stat ( struct spdk_bdev_io_stat stat,
enum spdk_bdev_reset_stat_mode  mode 
)

Reset I/O statictics structure.

Parameters
statThe I/O statictics to reset.
modeThe mode to reset I/O statictics.

◆ spdk_bdev_unquiesce()

int spdk_bdev_unquiesce ( struct spdk_bdev bdev,
struct spdk_bdev_module module,
spdk_bdev_quiesce_cb  cb_fn,
void *  cb_arg 
)

Unquiesce a previously quiesced bdev.

All I/O queued after the bdev was quiesced will be submitted.

Only the module that registered the bdev may call this function.

Parameters
bdevBlock device.
moduleThe module that registered the bdev.
cb_fnCallback function to be called when the bdev is unquiesced. Optional.
cb_argArgument to be supplied to cb_fn.
Returns
0 on success, or suitable errno value otherwise.

◆ spdk_bdev_unquiesce_range()

int spdk_bdev_unquiesce_range ( struct spdk_bdev bdev,
struct spdk_bdev_module module,
uint64_t  offset,
uint64_t  length,
spdk_bdev_quiesce_cb  cb_fn,
void *  cb_arg 
)

Unquiesce a previously quiesced bdev LBA range.

Same as spdk_bdev_unquiesce() but limited to the specified LBA range. The specified range must match exactly a previously quiesced LBA range.

Parameters
bdevBlock device.
moduleThe module that registered the bdev.
offsetThe offset of the start of the range, in blocks, from the start of the block device.
lengthThe length of the range, in blocks.
cb_fnCallback function to be called when the range is unquiesced. Optional.
cb_argArgument to be supplied to cb_fn.
Returns
0 on success, or suitable errno value otherwise.

◆ spdk_bdev_unregister()

void spdk_bdev_unregister ( struct spdk_bdev bdev,
spdk_bdev_unregister_cb  cb_fn,
void *  cb_arg 
)

Start unregistering a bdev.

This will notify each currently open descriptor on this bdev of the hotremoval to request the upper layers to stop using this bdev and manually close all the descriptors with spdk_bdev_close(). The actual bdev unregistration may be deferred until all descriptors are closed.

The cb_fn will be called from the context of the same spdk_thread that called spdk_bdev_unregister.

Note: spdk_bdev_unregister() can be unsafe unless the bdev is not opened before and closed after unregistration. It is recommended to use spdk_bdev_unregister_by_name().

Parameters
bdevBlock device to unregister.
cb_fnCallback function to be called when the unregister is complete.
cb_argArgument to be supplied to cb_fn

◆ spdk_bdev_unregister_by_name()

int spdk_bdev_unregister_by_name ( const char *  bdev_name,
struct spdk_bdev_module module,
spdk_bdev_unregister_cb  cb_fn,
void *  cb_arg 
)

Start unregistering a bdev.

This will notify each currently open descriptor on this bdev of the hotremoval to request the upper layer to stop using this bdev and manually close all the descriptors with spdk_bdev_close(). The actual bdev unregistration may be deferred until all descriptors are closed.

The cb_fn will be called from the context of the same spdk_thread that called spdk_bdev_unregister.

Parameters
bdev_nameBlock device name to unregister.
moduleModule by which the block device was registered.
cb_fnCallback function to be called when the unregister is complete.
cb_argArgument to be supplied to cb_fn
Returns
0 on success, or suitable errno value otherwise

◆ spdk_scsi_nvme_translate()

void spdk_scsi_nvme_translate ( const struct spdk_bdev_io bdev_io,
int *  sc,
int *  sk,
int *  asc,
int *  ascq 
)

Translates NVMe status codes to SCSI status information.

The codes are stored in the user supplied integers.

Parameters
bdev_ioI/O containing status codes to translate.
scSCSI Status Code will be stored here.
skSCSI Sense Key will be stored here.
ascSCSI Additional Sense Code will be stored here.
ascqSCSI Additional Sense Code Qualifier will be stored here.