util.h
libnvme utility functions
-
enum libnvme_connect_err
nvme connect error codes
Constants
ENVME_CONNECT_RESOLVEfailed to resolve host
ENVME_CONNECT_ADDRFAMunrecognized address family
ENVME_CONNECT_TRADDRfailed to get traddr
ENVME_CONNECT_TARGneed a transport (-t) argument
ENVME_CONNECT_AARGneed a address (-a) argument
ENVME_CONNECT_OPENfailed to open nvme-fabrics device
ENVME_CONNECT_WRITEfailed to write to nvme-fabrics device
ENVME_CONNECT_READfailed to read from nvme-fabrics device
ENVME_CONNECT_PARSEfailed to parse ctrl info
ENVME_CONNECT_INVAL_TRinvalid transport type
ENVME_CONNECT_LOOKUP_SUBSYS_NAMEfailed to lookup subsystem name
ENVME_CONNECT_LOOKUP_SUBSYSfailed to lookup subsystem
ENVME_CONNECT_ALREADYthe connect attempt failed, already connected
ENVME_CONNECT_INVALinvalid arguments/configuration
ENVME_CONNECT_ADDRINUSEhostnqn already in use
ENVME_CONNECT_NODEVinvalid interface
ENVME_CONNECT_OPNOTSUPPnot supported
ENVME_CONNECT_CONNREFUSEDconnection refused
ENVME_CONNECT_ADDRNOTAVAILcannot assign requested address
ENVME_CONNECT_IGNOREDconnect attempt is ignored due to configuration
ENVME_CONNECT_NOKEYthe TLS key is missing
-
__u8 libnvme_status_to_errno(int status, bool fabrics)
Converts nvme return status to errno
Parameters
int statusReturn status from an nvme passthrough command
bool fabricsSet to true if
statusis to a fabrics target.
Return
An errno representing the nvme status if it is an nvme status field, or unchanged status is < 0 since errno is already set.
-
const char *libnvme_status_to_string(int status, bool fabrics)
Returns string describing nvme return status.
Parameters
int statusReturn status from an nvme passthrough command
bool fabricsSet to true if
statusis to a fabrics target.
Return
String representation of the nvme status if it is an nvme status field, or a standard errno string if status is < 0.
-
const char *libnvme_sanitize_ns_status_to_string(__u16 sc)
Returns sanitize ns status string.
Parameters
__u16 scReturn status code from an sanitize ns command
Return
The sanitize ns status string if it is a specific status code.
-
const char *libnvme_set_features_status_to_string(__u16 sc)
Returns set features status string.
Parameters
__u16 scReturn status code from an set features command
Return
The set features status string if it is a specific status code.
-
const char *libnvme_opcode_status_to_string(int status, bool admin, __u8 opcode)
Returns nvme opcode status string.
Parameters
int statusReturn status from an nvme passthrough command
bool adminSet to true if an admin command
__u8 opcodeOpcode from an nvme passthrough command
Return
The nvme opcode status string if it is an nvme status field, or a standard errno string if status is < 0.
-
const char *libnvme_errno_to_string(int err)
Returns string describing nvme connect failures
Parameters
int errReturned error code from libnvme_add_ctrl()
Return
String representation of the nvme connect error codes
-
const char *libnvme_strerror(int err)
Returns string describing nvme errors and errno
Parameters
int errReturned error codes from all libnvme functions
Return
String representation of either the nvme connect error codes (positive values) or errno string (negative values)
-
struct nvmf_ext_attr *libnvmf_exat_ptr_next(struct nvmf_ext_attr *p)
Increment p to the next element in the array.
Parameters
struct nvmf_ext_attr *pPointer to an element of an array of “struct nvmf_ext_attr”.
Description
Extended attributes are saved to an array of “struct nvmf_ext_attr” where each element of the array is of variable size. In order to move to the next element in the array one must increment the pointer to the current element (p) by the size of the current element.
Return
Pointer to the next element in the array.
-
enum libnvme_version
Selector for version to be returned by libnvme_get_version
Constants
LIBNVME_VERSION_PROJECTProject release version
LIBNVME_VERSION_GITGit reference
-
const char *libnvme_get_version(enum libnvme_version type)
Return version libnvme string
Parameters
enum libnvme_version typeSelects which version type (see struct libnvme_version)
Return
Returns version string for known types or else “n/a”
-
int libnvme_uuid_to_string(unsigned char uuid[NVME_UUID_LEN], char *str)
Return string represenation of encoded UUID
Parameters
unsigned char uuid[NVME_UUID_LEN]Binary encoded input UUID
char *strOutput string represenation of UUID
Return
Returns error code if type conversion fails.
-
int libnvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN])
Return encoded UUID represenation of string UUID
Parameters
const char *strOutput string represenation of UUID
unsigned char uuid[NVME_UUID_LEN]Binary encoded input UUID
Return
Returns error code if type conversion fails.
-
int libnvme_random_uuid(unsigned char uuid[NVME_UUID_LEN])
Generate random UUID
Parameters
unsigned char uuid[NVME_UUID_LEN]Generated random UUID
Description
Generate random number according https://www.rfc-editor.org/rfc/rfc4122#section-4.4
Return
Returns error code if generating of random number fails.
-
int libnvme_find_uuid(struct nvme_id_uuid_list *uuid_list, const unsigned char uuid[NVME_UUID_LEN])
Find UUID position on UUID list
Parameters
struct nvme_id_uuid_list *uuid_listUUID list returned by identify UUID
const unsigned char uuid[NVME_UUID_LEN]Binary encoded input UUID
Return
The array position where given UUID is present, or negative error code otherwise.
-
char *libnvme_basename(const char *path)
Return the final path component (the one after the last ‘/’)
Parameters
const char *pathA string containing a filesystem path
Return
A pointer into the original null-terminated path string.