Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ AC_ARG_WITH([nvme],
[],
[with_nvme=yes])

AC_ARG_WITH([libnvme],
AS_HELP_STRING([--with-libnvme=auto|libnvme3|libnvme1], [libnvme flavour to use for the nvme plugin @<:@default=auto@:>@]),
[],
[with_libnvme=auto])

AC_SUBST([WITH_NVME], [0])
AM_CONDITIONAL(WITH_NVME, test "x$with_nvme" != "xno")
AS_IF([test "x$with_nvme" != "xno"],
Expand Down Expand Up @@ -279,11 +284,19 @@ AS_IF([test "x$with_nvdimm" != "xno"],
[])

AS_IF([test "x$with_nvme" != "xno"],
[LIBBLOCKDEV_PKG_CHECK_MODULES([NVME], [libnvme >= 1.3])
AS_IF([$PKG_CONFIG --atleast-version=1.4 libnvme],
[AC_DEFINE([HAVE_LIBNVME_1_4])], [])
[AS_IF([test "x$with_libnvme" = "xauto"],
[PKG_CHECK_EXISTS([libnvme3 >= 3.2], [with_libnvme=libnvme3], [with_libnvme=libnvme1])])
AS_CASE([$with_libnvme],
[libnvme3], [LIBBLOCKDEV_PKG_CHECK_MODULES([NVME], [libnvme3 >= 3.2])
AC_DEFINE([HAVE_LIBNVME3], [], [Define if the nvme plugin uses libnvme3])],
[libnvme1], [LIBBLOCKDEV_PKG_CHECK_MODULES([NVME], [libnvme >= 1.3])
AS_IF([$PKG_CONFIG --atleast-version=1.4 libnvme],
[AC_DEFINE([HAVE_LIBNVME_1_4])], [])],
[AC_MSG_ERROR([Invalid value '$with_libnvme' for --with-libnvme, use auto, libnvme3 or libnvme1])])
],
[])
AM_CONDITIONAL(WITH_LIBNVME3, test "x$with_nvme" != "xno" -a "x$with_libnvme" = "xlibnvme3")
AS_IF([test "x$with_nvme" != "xno"], [nvme_info="yes ($with_libnvme)"], [nvme_info="no"])

AS_IF([test "x$with_smart" != "xno"],
[LIBBLOCKDEV_PKG_CHECK_MODULES([SMART], [libatasmart >= 0.17])
Expand Down Expand Up @@ -393,7 +406,7 @@ echo "
MDRAID plugin: ${with_mdraid}
MPath plugin ${with_mpath}
NVDIMM plugin (deprecated): ${with_nvdimm}
NVMe plugin: ${with_nvme}
NVMe plugin: ${nvme_info}
Part plugin: ${with_part}
S390 plugin: ${s390_info}
SMART plugin (libatasmart): ${with_smart}
Expand Down
2 changes: 2 additions & 0 deletions docs/libblockdev-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ bd_nvme_get_sanitize_log
bd_nvme_sanitize_log_free
bd_nvme_sanitize_log_copy
BDNVMESanitizeAction
BDNVMEDisconnectFlags
bd_nvme_sanitize
bd_nvme_get_host_nqn
bd_nvme_get_host_id
Expand All @@ -844,6 +845,7 @@ bd_nvme_set_host_id
bd_nvme_connect
bd_nvme_disconnect
bd_nvme_disconnect_by_path
bd_nvme_disconnect_full
bd_nvme_find_ctrls_for_ns
bd_nvme_find_namespaces_for_ctrl
</SECTION>
Expand Down
100 changes: 87 additions & 13 deletions src/lib/plugin_apis/nvme.api
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ GQuark bd_nvme_error_quark (void) {
* @BD_NVME_ERROR_CONNECT_NODEV: Invalid interface.
* @BD_NVME_ERROR_CONNECT_OPNOTSUPP: Operation not supported.
* @BD_NVME_ERROR_CONNECT_REFUSED: Connection refused.
* @BD_NVME_ERROR_OWNED: The controller is not owned by the caller (see bd_nvme_disconnect()).
*/
/* BpG-skip-end */
typedef enum {
Expand All @@ -53,6 +54,7 @@ typedef enum {
BD_NVME_ERROR_CONNECT_NODEV,
BD_NVME_ERROR_CONNECT_OPNOTSUPP,
BD_NVME_ERROR_CONNECT_REFUSED,
BD_NVME_ERROR_OWNED,
} BDNVMEError;

typedef enum {
Expand Down Expand Up @@ -1004,6 +1006,18 @@ typedef enum {
BD_NVME_SANITIZE_ACTION_CRYPTO_ERASE = 3,
} BDNVMESanitizeAction;

/* BpG-skip */
/**
* BDNVMEDisconnectFlags:
* @BD_NVME_DISCONNECT_NONE: No flags.
* @BD_NVME_DISCONNECT_FORCE: Disconnect controllers regardless of their owner in the libnvme controller ownership registry.
*/
/* BpG-skip-end */
typedef enum {
BD_NVME_DISCONNECT_NONE = 0,
BD_NVME_DISCONNECT_FORCE = 1 << 0,
} BDNVMEDisconnectFlags;


/**
* bd_nvme_get_controller_info:
Expand Down Expand Up @@ -1277,7 +1291,7 @@ gboolean bd_nvme_set_host_id (const gchar *host_id, GError **error);
* @host_iface: (nullable): The network interface used on the host to connect to the Controller (e.g. IP `eth1`, `enp2s0`). This forces the connection to be made on a specific interface instead of letting the system decide.
* @host_nqn: (nullable): Overrides the default Host NQN that identifies the NVMe Host. If this option is %NULL, the default is read from `/etc/nvme/hostnqn` first.
* If that does not exist, the autogenerated NQN value from the NVMe Host kernel module is used next. The Host NQN uniquely identifies the NVMe Host.
* @host_id: (nullable): User-defined host UUID or %NULL to use default (as defined in `/etc/nvme/hostid`)
* @host_id: (nullable): User-defined host UUID or %NULL to use default (as defined in `/etc/nvme/hostid`).
* @extra: (nullable) (array zero-terminated=1): Additional arguments.
* @error: (out) (nullable): Place to store error (if any).
*
Expand All @@ -1291,14 +1305,16 @@ gboolean bd_nvme_set_host_id (const gchar *host_id, GError **error);
* - `"loop"`: A NVMe over Fabrics target on the local host.
*
* In addition to the primary options it's possible to supply @extra arguments:
* - `"config"`: Use the specified JSON configuration file instead of the default file (see below) or
* - `"config"`: Use the specified configuration file instead of the default file (see below) or
* specify `"none"` to avoid reading any configuration file.
* - `"dhchap_key"`: NVMe In-band authentication secret in ASCII format as described
* in the NVMe 2.0 specification. When not specified, the secret is by default read
* from `/etc/nvme/hostkey`. In case that file does not exist no in-band authentication
* is attempted.
* - `"dhchap_ctrl_key"`: NVMe In-band authentication controller secret for bi-directional authentication.
* When not specified, no bi-directional authentication is attempted.
* - `"kxchap_secret"`: NVMe In-band authentication (KX-HMAC-CHAP, formerly DH-HMAC-CHAP) host secret
* in ASCII format as described in the NVMe specification. When not specified,
* the secret is taken from the configuration file or, with libnvme-1.x, read from
* `/etc/nvme/hostkey`, if present. Otherwise no in-band authentication is attempted.
* - `"kxchap_ctrl_secret"`: NVMe In-band authentication controller secret for bi-directional authentication.
* When not specified, the secret is taken from the configuration file, if present.
* Otherwise no bi-directional authentication is attempted.
* - `"dhchap_key"`, `"dhchap_ctrl_key"`: Deprecated aliases for `"kxchap_secret"` and `"kxchap_ctrl_secret"`.
* - `"nr_io_queues"`: The number of I/O queues.
* - `"nr_write_queues"`: Number of additional queues that will be used for write I/O.
* - `"nr_poll_queues"`: Number of additional queues that will be used for polling latency sensitive I/O.
Expand All @@ -1314,17 +1330,33 @@ gboolean bd_nvme_set_host_id (const gchar *host_id, GError **error);
* - `"data_digest"`: Generates/verifies data digest (TCP). Boolean value.
* - `"tls"`: Enable TLS encryption (TCP). Boolean value.
* - `"hostsymname"`: TP8010: NVMe host symbolic name.
* - `"owner"`: Register a newly created controller with this owner in the libnvme controller ownership
* registry (`/run/nvme/registry/`) instead of the default `"libblockdev"`, e.g. `"udisks"`.
* An empty string leaves the controller without an owner. An already connected controller
* keeps its owner. See bd_nvme_disconnect() and bd_nvme_disconnect_full().
* Only supported with libnvme3, ignored with libnvme-1.x.
* - `"keyring"`: Keyring to store and lookup keys. String value.
* - `"tls_key"`: TLS PSK for the connection. String value.
*
* Boolean values can be expressed by "0"/"1", "on"/"off" or "True"/"False" case-insensitive
* strings. Failed numerical or boolean string conversions will result in the option being ignored.
*
* By default additional options are read from the default configuration file `/etc/nvme/config.json`.
* This follows the default behaviour of `nvme-cli`. Use the @extra `"config"` argument
* to either specify a different config file or disable use of it. The JSON configuration
* file format is documented in [https://raw.githubusercontent.com/linux-nvme/libnvme/master/doc/config-schema.json](https://raw.githubusercontent.com/linux-nvme/libnvme/master/doc/config-schema.json).
* As a rule @extra key names are kept consistent with the JSON config file schema.
* By default additional options are read from the default configuration file, following the
* default behaviour of `nvme-cli`. Use the @extra `"config"` argument to either specify a different
* config file or disable use of it. The configuration file format depends on the libnvme flavour
* libblockdev has been built with:
* - libnvme3: The INI configuration file `/etc/nvme/nvme-fabrics.conf` (and its `/etc/nvme/nvme-fabrics.conf.d/`
* drop-in directory). Parameters of the first connection entry matching the @subsysnqn, @transport,
* @transport_addr, @transport_svcid, @host_traddr and @host_iface arguments are applied, along with
* its host identity when @host_nqn or @host_id are not specified. The format is documented
* in [https://github.com/linux-nvme/nvme-cli/blob/master/libnvme/design/CONFIG.md](https://github.com/linux-nvme/nvme-cli/blob/master/libnvme/design/CONFIG.md),
* legacy JSON configuration files are not supported. Unlike `nvme-cli`, libblockdev doesn't convert
* an existing `/etc/nvme/config.json` automatically, a warning is logged instead. Use `nvme config-convert`
* to convert it.
* - libnvme-1.x: The JSON configuration file `/etc/nvme/config.json`. The format is documented
* in [https://raw.githubusercontent.com/linux-nvme/libnvme/master/doc/config-schema.json](https://raw.githubusercontent.com/linux-nvme/libnvme/master/doc/config-schema.json).
* As a rule @extra key names are kept consistent with the JSON config file schema.
*
* Any @extra option generally overrides particular option specified in a configuration file.
*
* Returns: %TRUE if the subsystem was connected successfully, %FALSE otherwise with @error set.
Expand All @@ -1342,8 +1374,17 @@ gboolean bd_nvme_connect (const gchar *subsysnqn, const gchar *transport, const
* This may disconnect multiple controllers with matching @subsysnqn and %TRUE
* is only returned when all controllers were disconnected successfully.
*
* With libnvme3, only controllers owned by libblockdev according to the libnvme controller
* ownership registry are disconnected, i.e. the ones connected by bd_nvme_connect() without
* a specific `"owner"`. Controllers connected by other components, e.g. boot volumes
* connected via NBFT or connections managed by a discovery daemon, are left untouched.
* See bd_nvme_disconnect_full() to disconnect controllers of a different owner.
* libnvme-1.x has no ownership registry, all matching controllers are disconnected.
*
* Returns: %TRUE if all matching controllers were disconnected successfully, %FALSE with @error
* set in case of a disconnect error or when no matching controllers were found.
* The #BD_NVME_ERROR_OWNED error is returned when none of the matching controllers
* are owned by libblockdev.
*
* Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
*/
Expand All @@ -1357,13 +1398,46 @@ gboolean bd_nvme_disconnect (const gchar *subsysnqn, GError **error);
* Disconnects and removes a NVMe over Fabrics controller represented
* by a block device path.
*
* With libnvme3, only a controller owned by libblockdev according to the libnvme controller
* ownership registry is disconnected, see bd_nvme_disconnect() and bd_nvme_disconnect_full().
*
* Returns: %TRUE if the controller was disconnected successfully,
* %FALSE otherwise with @error set.
*
* Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
*/
gboolean bd_nvme_disconnect_by_path (const gchar *path, GError **error);

/**
* bd_nvme_disconnect_full:
* @subsysnqn: (nullable): The name of the NVMe subsystem to disconnect.
* @path: (nullable): NVMe controller device to disconnect (e.g. `/dev/nvme0`).
* @owner: (nullable): The owner of the controllers to disconnect or %NULL for libblockdev.
* @flags: Flags to control the disconnect.
* @error: (out) (nullable): Place to store error (if any).
*
* Disconnects and removes existing NVMe over Fabrics controllers matching @subsysnqn
* or the controller represented by @path. Exactly one of @subsysnqn and @path has to
* be specified.
*
* Only controllers registered to @owner in the libnvme controller ownership registry
* (`/run/nvme/registry/`) are disconnected, see the `"owner"` argument of bd_nvme_connect().
* With the #BD_NVME_DISCONNECT_FORCE flag all matching controllers are disconnected
* regardless of their owner, including controllers without any owner. Use with care,
* this may disconnect devices other components depend on, e.g. the root filesystem.
*
* libnvme-1.x has no ownership registry, @owner and @flags are ignored and all matching
* controllers are disconnected, same as with bd_nvme_disconnect().
*
* Returns: %TRUE if all matching controllers were disconnected successfully, %FALSE with @error
* set in case of a disconnect error or when no matching controllers were found.
* The #BD_NVME_ERROR_OWNED error is returned when none of the matching controllers
* are owned by @owner.
*
* Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
*/
gboolean bd_nvme_disconnect_full (const gchar *subsysnqn, const gchar *path, const gchar *owner, BDNVMEDisconnectFlags flags, GError **error);

/**
* bd_nvme_find_ctrls_for_ns:
* @ns_sysfs_path: NVMe namespace sysfs path.
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/nvme/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ libbd_nvme_la_SOURCES = \
nvme.h \
nvme.c \
nvme-private.h \
nvme-backend.h \
nvme-info.c \
nvme-error.c \
nvme-op.c \
nvme-fabrics.c \
../check_deps.c \
../check_deps.h

if WITH_LIBNVME3
libbd_nvme_la_SOURCES += nvme-libnvme3.h nvme-libnvme3.c
else
libbd_nvme_la_SOURCES += nvme-libnvme1.h nvme-libnvme1.c
endif

libbd_nvmeincludedir = $(includedir)/blockdev
libbd_nvmeinclude_HEADERS = nvme.h
Loading
Loading