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
33 changes: 33 additions & 0 deletions .github/actions/build-libnvme3/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build libnvme3
description: Build upstream libnvme 3.3 for Ubuntu runners that only ship libnvme 1.x

runs:
using: composite
steps:
- name: Install libnvme build dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y meson ninja-build libjson-c-dev \
libssl-dev libkeyutils-dev libkmod-dev

- name: Build and install libnvme3
shell: bash
run: |
src="$RUNNER_TEMP/nvme-cli"
prefix="$RUNNER_TEMP/libnvme3"
git clone --depth 1 --branch v3.3 https://github.com/linux-nvme/nvme-cli.git "$src"
test "$(git -C "$src" rev-parse HEAD)" = c19af560d1869636104de5ab4e41420cbfdef395

meson setup "$src/build" "$src" \
--prefix="$prefix" --libdir=lib \
-Dlibnvme=enabled -Dfabrics=enabled -Dnvme=disabled \
-Ddocs=false -Dpython=disabled -Dtests=false -Dexamples=false \
-Dliburing=disabled -Dnvme-discoverd=disabled -Dnvme-keysd=disabled \
-Dtop=disabled
meson install -C "$src/build"

{
echo "PKG_CONFIG_PATH=$prefix/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
echo "LD_LIBRARY_PATH=$prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
} >> "$GITHUB_ENV"
2 changes: 2 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v7

- uses: ./.github/actions/build-libnvme3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
sudo apt -y install ansible
ansible-playbook -b -i "localhost," -c local misc/install-test-dependencies.yml -e "test_dependencies=false"

- uses: ./.github/actions/build-libnvme3

- name: Install compiler
run: |
sudo apt -y install ${{ matrix.compiler }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/csmock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

- name: Run csmock build in the container
run: |
podman exec -it ${{ env.CI_CONTAINER }} bash -c "/ci/run_csmock_tests -c /ci/copr-builder.conf -p libblockdev-udisks -t ${{ env.CSMOCK_TOOLS }} -r ${{ matrix.chroot }}"
podman exec -it ${{ env.CI_CONTAINER }} bash -c "/ci/run_csmock_tests -c /ci/copr-builder.conf -p libblockdev-udisks -t ${{ env.CSMOCK_TOOLS }} -r ${{ matrix.chroot }} --copr-repo @storage/nvme-cli"

- name: Upload the csmock logs
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ jobs:

- name: Run the checks
run: |
python3 ../ci/run_spell_checks -p libblockdev -i gir
python3 ../ci/run_spell_checks -p libblockdev -i gir eto
working-directory: ./libblockdev
17 changes: 15 additions & 2 deletions .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ actions:
- 'sed -i -e "s/@WITH_..*@/1/g" -e "s/@MAJOR_VER@/3/g" dist/libblockdev.spec'
create-archive:
- './autogen.sh'
- './configure'
# Extra Copr repos are not available during SRPM creation.
- './configure --without-nvme'
- 'make'
# Keep NVMe enabled in the spec used for the binary RPM build.
- 'sed -i "s/^%define with_nvme 0$/%define with_nvme 1/" dist/libblockdev.spec'
- 'make local'
- 'bash -c "ls *.tar*"'
get-current-version:
- 'bash -c "grep Version: dist/libblockdev.spec.in | cut -f2 -d\":\" | tr -d \" \""'

jobs:
- job: copr_build
additional_repos:
- copr://@storage/nvme-cli
targets:
- fedora-rawhide-aarch64
- fedora-rawhide-ppc64le
Expand Down Expand Up @@ -108,6 +113,11 @@ jobs:
- centos-stream-10-x86_64
- centos-stream-10-aarch64
branch: master
tf_extra_params:
environments:
- artifacts:
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/g/storage/nvme-cli/repo/fedora-$releasever/group_storage-nvme-cli-fedora-$releasever.repo

- job: tests
identifier: fips
Expand Down Expand Up @@ -140,6 +150,8 @@ jobs:
tf_extra_params:
environments:
- artifacts:
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/g/storage/nvme-cli/repo/fedora-$releasever/group_storage-nvme-cli-fedora-$releasever.repo
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/g/storage/blivet-daily/repo/fedora-$releasever/group_storage-blivet-daily-fedora-$releasever.repo
tmt:
Expand All @@ -158,6 +170,8 @@ jobs:
tf_extra_params:
environments:
- artifacts:
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/g/storage/nvme-cli/repo/fedora-$releasever/group_storage-nvme-cli-fedora-$releasever.repo
- type: repository-file
id: https://copr.fedorainfracloud.org/coprs/g/storage/udisks-daily/repo/fedora-$releasever/group_storage-udisks-daily-fedora-$releasever.repo
tmt:
Expand Down Expand Up @@ -186,7 +200,6 @@ srpm_build_deps:
- libbytesize-devel
- libfdisk-devel
- libmount-devel
- libnvme-devel
- libuuid-devel
- libyaml-devel
- ndctl-devel
Expand Down
5 changes: 1 addition & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,7 @@ 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])], [])
],
[LIBBLOCKDEV_PKG_CHECK_MODULES([NVME], [libnvme3 >= 3.3])],
[])

AS_IF([test "x$with_smart" != "xno"],
Expand Down
2 changes: 1 addition & 1 deletion dist/libblockdev.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ with the libblockdev-nvdimm plugin/library.

%if %{with_nvme}
%package nvme
BuildRequires: libnvme-devel
BuildRequires: pkgconfig(libnvme3) >= 3.3
BuildRequires: libuuid-devel
Summary: The NVMe plugin for the libblockdev library
Requires: %{name}-utils%{?_isa} = %{version}-%{release}
Expand Down
2 changes: 2 additions & 0 deletions docs/libblockdev-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,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 @@ -853,6 +854,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
10 changes: 9 additions & 1 deletion misc/libblockdev-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
- automake
when: ansible_facts['distribution'] == 'Fedora'

- name: Enable copr repository with libnvme3
command: "dnf -y copr enable @storage/nvme-cli"
Comment thread
vojtechtrefny marked this conversation as resolved.
Resolved
when: ansible_facts['distribution'] == 'Fedora'

- name: Allow package vendor changes (Fedora)
command: "dnf config-manager setopt allow_vendor_change=True"
Comment thread
vojtechtrefny marked this conversation as resolved.
Resolved
when: ansible_facts['distribution'] == 'Fedora'

- name: Install dnf-plugins-core for dnf builddep (Fedora)
package: name=dnf-plugins-core state=present
when: ansible_facts['distribution'] == 'Fedora'
Expand All @@ -28,7 +36,7 @@
name:
- libfdisk-devel
- keyutils-libs-devel
- libnvme-devel
- libnvme3-devel
- e2fsprogs-devel
- json-glib-devel
- libatasmart-devel
Expand Down
94 changes: 80 additions & 14 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 @@ -1272,12 +1286,12 @@ gboolean bd_nvme_set_host_id (const gchar *host_id, GError **error);
* @subsysnqn: The name for the NVMe subsystem to connect to.
* @transport: The network fabric used for a NVMe-over-Fabrics network.
* @transport_addr: (nullable): The network address of the Controller. For transports using IP addressing (e.g. `rdma`) this should be an IP-based address.
* @transport_svcid: (nullable): The transport service ID. For transports using IP addressing (e.g. `tcp`, `rdma`) this field is the port number. The default port number for the `tcp` and `rdma` transports is `4420` and `8009` respectively when the well-known Discovery NQN is specified.
* @transport_svcid: (nullable): The transport service ID. For transports using IP addressing (e.g. `tcp`, `rdma`) this field is the port number. The default port number for the `tcp` and `rdma` transports is `4420`, or `8009` for `tcp` when the well-known Discovery NQN is specified.
* @host_traddr: (nullable): The network address used on the host to connect to the Controller. For TCP, this sets the source address on the socket.
* @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, 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,29 @@ 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().
* - `"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 `/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, @host_traddr and @host_iface arguments
* are applied, along with its host identity when @host_nqn or @host_id are not specified.
* The @transport_svcid, @host_nqn and @host_id arguments have to match as well when both the argument
* and the entry specify them, entries without them match any value. For @transport_svcid the default
* port is used when not specified, an entry for another port is not applied. Use the @extra `"config"` argument
* to either specify a different config file or disable use of it. A configuration file that fails
* to parse, including the default one, is an error, a missing default configuration file is not. The INI configuration file 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 anymore. 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.
* 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 +1370,16 @@ 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.
*
* 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.
*
* 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 +1393,43 @@ gboolean bd_nvme_disconnect (const gchar *subsysnqn, GError **error);
* Disconnects and removes a NVMe over Fabrics controller represented
* by a block device path.
*
* 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.
*
* 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
Loading