Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
eeb5edb
rpmb: fix the RPMBS output on big-endian hosts
dwsuse Nov 19, 2026
eec7cd6
plugins: look for a plugin in plugins/cmds-<plugin> too
dwsuse Nov 19, 2026
79a6d44
plugins: name the modules after the directory of their plugin
dwsuse Nov 19, 2026
9ac73b1
plugins: move the plugins of nvme into plugins/cmds-<plugin>
dwsuse Nov 19, 2026
0149c37
plugin: load plugins for top-level commands
dwsuse Nov 18, 2026
4b794fa
tests: check the index of the top-level commands
dwsuse Nov 18, 2026
b9b13fe
tests: run the tests of the deprecated keys commands
dwsuse Nov 18, 2026
69b2a36
deprecated: move the deprecated commands into a plugin
dwsuse Nov 18, 2026
05f237f
tests: check the sandbox for resv report, dir receive and rpmb info
dwsuse Nov 18, 2026
0598031
resv: move the printers into the plugin
dwsuse Nov 18, 2026
22e4efa
dir: move the printers into the plugin
dwsuse Nov 18, 2026
82d40c1
id: move the RPMBS printers into the plugin
dwsuse Nov 18, 2026
7c2cf28
tests: check the output of get-lba-status
dwsuse Nov 18, 2026
f2364c4
cmds-io: move the I/O commands into a plugin
dwsuse Nov 18, 2026
320d15f
cmds-io: move the LBA status printers into the plugin
dwsuse Nov 18, 2026
5d0a2f1
cmds-admin: move the controller and media management commands into a
dwsuse Nov 18, 2026
ce66db9
tests: check the sandbox for the register printers
dwsuse Nov 18, 2026
53db3d8
cmds-regs: move the register commands into a plugin
dwsuse Nov 18, 2026
843c4f0
cmds-regs: move the register printers into the plugin
dwsuse Nov 18, 2026
c0e45d1
cmds-regs: move the register table into the plugin
dwsuse Nov 18, 2026
470fc30
cmds-passthru: move the passthru commands into a plugin
dwsuse Nov 18, 2026
a7d00eb
nvme: pass the get-log values to nvme_show_log directly
dwsuse Nov 18, 2026
3d04196
log: move get-log into the plugin
dwsuse Nov 18, 2026
e1e5649
feat: move get-feature and set-feature into the plugin
dwsuse Nov 18, 2026
39df7e0
tests: check the feature decoders for a dry run
dwsuse Nov 18, 2026
9015169
nvme-print: add nvme_print_decoder_always
dwsuse Nov 18, 2026
83f282e
feat: move the feature printers into the plugin
dwsuse Nov 18, 2026
a98ce08
nvme-print: move the nvme_resources helpers into their own file
dwsuse Nov 18, 2026
bd97de8
cmds-list: move the device enumeration commands into a plugin
dwsuse Nov 18, 2026
e22097d
cmds-list: move the printers into the plugin
dwsuse Nov 18, 2026
08104e0
cmds-list: move dashboard and iostat into the plugin
dwsuse Nov 18, 2026
94be8bc
cmds-admin: move the relatives printer into the plugin
dwsuse Nov 18, 2026
a00b05f
tests: check the fabrics printers
dwsuse Nov 18, 2026
7ec3435
tests: check that a plugin command keeps root
dwsuse Nov 18, 2026
ba9c74c
nvme-print: remove the connect_msg printer
dwsuse Nov 18, 2026
98a24fb
config: move config-create into the plugin
dwsuse Nov 18, 2026
195d2ed
nvme: start with an empty list of top-level commands
dwsuse Nov 18, 2026
ad8c090
fabrics: move the commands into a plugin
dwsuse Nov 18, 2026
847e8c7
fabrics: move the printers into the plugin
dwsuse Nov 18, 2026
fcd16c7
doc: describe where the top-level commands live
dwsuse Nov 18, 2026
dca93f9
NEWS: the top-level commands are plugins
dwsuse Nov 19, 2026
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
67 changes: 44 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,36 @@ string, a callback, and optionally an alias, a `deprecated` flag, or a

### Add a command to an existing group

The built-in (no-plugin-prefix) commands are split by feature area across
`src/nvme-cmds-*.c` (e.g. `src/nvme-cmds-io.c` for read/write/flush/...,
`src/nvme-cmds-registers.c` for register access, etc.). Pick the file that
matches your command's area, or add a new `src/nvme-cmds-<area>.c` if none
fit -- just add the one line to `src/meson.build`'s `sources` list. Each
such file ends with a block like this one from `src/nvme-cmds-discovery.c`:
The top-level commands (`nvme read`, `nvme connect`, ...) live in plugins
without a command group of their own, one per feature area: e.g.
`plugins/cmds-io` for read/write/flush, `plugins/cmds-admin` for format,
sanitize and reset, `plugins/cmds-fabrics` for connect and discover. Pick
the plugin that matches the area of your command. Each ends with a block
like this one from `plugins/cmds-io/cmds-io-plugin.c`:

```c
static struct command get_log_cmd = {
.name = "get-log",
.help = "Generic NVMe get log, returns log in raw format",
.fn = get_log,
static struct command flush_cmd_cmd = {
.name = "flush",
.help = "Submit a Flush command, return results",
.fn = flush_cmd,
};

static struct command *commands[] = {
&get_log_cmd,
&flush_cmd_cmd,
/* ... */
NULL,
};

static void __shr_constructor register_group(void)
NVME_PLUGIN_INIT(register_plugin)
{
plugin_add_group(&builtin, "Log Page & Identify", commands);
plugin_add_group(&builtin, "I/O Commands", commands);
}
```

To add a command, write its callback function, add a `struct command`
literal for it, and add that entry to the `commands[]` array. The
callback's prototype is:
literal for it, add that entry to the `commands[]` array, and add its name
to `plugin_commands` in the plugin's `meson.build` (see "Top-level
commands in a plugin" below). The callback's prototype is:

```c
int f(int argc, char **argv, struct command *command, struct plugin *plugin);
Expand All @@ -97,16 +98,16 @@ int f(int argc, char **argv, struct command *command, struct plugin *plugin);
`argc`/`argv` are adjusted to start after the sub-command. For
`nvme foo --option=bar`, `argc` is 1 and `argv` starts at `--option`.
Use `.alias = "other-name"` for an alias, and `.deprecated = true` for a
deprecated command (deprecated built-ins live in
`src/nvme-cmds-deprecated.c`, gated by `#ifdef CONFIG_DEPRECATED_CMDS`).
deprecated command (the deprecated top-level commands live in the
`plugins/cmds-deprecated` plugin, built with `-Ddeprecated-cmds=enabled`).
Set `.no_device = true` for a command that doesn't take a positional
`<device>` argument (e.g. `nvme list` or `nvme gen-hostnqn`) -- this drops
`<device>` from its usage line and, when none of a plugin's commands need
one, from that plugin's `--help` output too.

The `title` passed to `plugin_add_group()` (`"Log Page & Identify"` above)
is the heading shown for that group's commands in `nvme help`; pass `NULL`
for no heading (that's what plugins normally do, see below).
The `title` passed to `plugin_add_group()` (`"I/O Commands"` above) is the
heading of the group in `nvme help`. Pass `NULL` for no heading, as plugins
with their own command group normally do (see below).

### Add a new plugin

Expand Down Expand Up @@ -180,9 +181,29 @@ group's commands instead of in the flat "core NVMe/NVMeoF plugins" list.
This only affects display -- the plugin is still invoked as `nvme foo bar`,
not merged into the flat top-level command namespace.

#### Top-level commands in a plugin

A plugin can add top-level commands, `nvme bar` rather than `nvme foo bar`.
Its `NVME_PLUGIN_INIT()` function calls
`plugin_add_group(&builtin, title, commands)` with one of the titles of
`builtin_groups` in `src/nvme.c`. The title gives the commands their place
in `nvme help` and in the command lists. A plugin with only top-level
commands calls no `register_extension()` and sets
`plugin_extension = false` in its `meson.build`. The `meson.build` lists
the top-level commands and their aliases:

```meson
plugin_commands = ['bar', 'baz']
plugin_command_aliases = {'bar': 'old-bar'}
```

nvme looks a top-level command it doesn't have up in these lists and
loads the module. The `command-index` test checks that the lists name
exactly the commands of the plugin.

#### Multi-file plugins

A plugin can span multiple `.c` files (see `plugins/ocp` or
A plugin can span multiple `.c` files (see `plugins/cmds-ocp` or
`plugins/solidigm` for real examples): put the `struct plugin` definition
and any shared declarations in a small header, and `#include` it from each
file. A plugin has one `NVME_PLUGIN_INIT()` function. To show the commands
Expand All @@ -199,7 +220,7 @@ Neither needs hardware. `Documentation/TESTING.md` describes the tools.
**Mock tests** run the real `nvme` binary against a mocked controller:
`tests/cli/libmock_nvme.c` intercepts the ioctls and hands every command
to a Python object in the test, which answers it (`tests/cli/nvme_mock.py`).
Vendor tests live in `tests/cli/<plugin>/`; `tests/cli/ocp/` (a shared
Vendor tests live in `tests/cli/<plugin>/`; `tests/cli/cmds_ocp/` (a shared
controller class, one file per command), `tests/cli/wdc/` (several
models) and `tests/cli/micron/` are examples. A test

Expand Down Expand Up @@ -507,7 +528,7 @@ how to triage and fix findings. Give it precise input data:
checks.

For example: "Add mock tests for `nvme <plugin> <command>` in
`tests/cli/<plugin>/` following `tests/cli/ocp/`. The log layout is in
`tests/cli/<plugin>/` following `tests/cli/cmds_ocp/`. The log layout is in
`<file>`, the output of a real drive in `<file>`. Use non-zero values in
every field and check normal and JSON output. Then add the command to the
device fuzz table, sweep it and compare its coverage with and without the
Expand Down
18 changes: 13 additions & 5 deletions Documentation/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,12 @@ $ make PLUGINS=""
## Plugin modules

The plugins are modules of their own, which nvme loads when a command
uses them, so a command loads at most the module of its plugin. nvme
loads all modules only for the lists of commands, `nvme help` and
`nvme utils dump-command-metadata`, and for a command it doesn't know.
uses them. The top-level commands live in modules too: `cmds-io` for the
I/O commands, `cmds-fabrics` for connect and discover, `cmds-list` for
list and top, and so on. A command loads only the module which provides
it, and the plugins that module needs. nvme loads all modules only for
the lists of commands, `nvme help` and `nvme utils dump-command-metadata`,
and for a command it doesn't know.
The `plugin-modules` option decides:

```shell
Expand All @@ -301,11 +304,16 @@ $ meson setup .build -Dplugin-modules=disabled
| `disabled` | linked into nvme |

The modules are installed in `<libdir>/nvme-cli/<version>/plugins`, with
the `runtime` install tag. A module works only with an nvme of the same
the `runtime` install tag. A module is named after the directory of its
plugin, e.g. `sandisk.so` for `nvme sndk`. A module works only with an nvme of the same
version, built with the same `src/plugin.h`: nvme ignores another one with
a warning.
Without the module of a plugin, `nvme <plugin>` says the plugin is not
installed, so a distribution can package plugins on their own.
installed, and without the module of a top-level command, nvme says the
command is not installed. So a distribution can package plugins on their
own. An initramfs needs the modules of the commands it runs, e.g.
`cmds-fabrics.so` for `nvme connect-all`, `cmds-list.so` for
`nvme list-subsys` and `cmds-nbft.so` for `nvme nbft show`.

Run from the build tree, nvme takes the modules of the build tree
(`.build/plugins`). The environment variable `NVME_PLUGIN_DIR` names
Expand Down
11 changes: 6 additions & 5 deletions Documentation/PRIVSEP.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,14 @@ writes its report to a file.

Some printers stay in process (`nvme_print_sandboxed()`):

- the libnvme tree printers (`list`, `list-subsys`, `show-topology`,
`relatives`), which read sysfs while they print and decode no device
data;
- the libnvme tree printers (`list`, `list-subsys`, `show-topology`),
which read sysfs while they print and decode no device data;
- plugin printers run through `nvme_print_decoder()` with `sandbox` set
to false, e.g. the zns zone list printers, which pass a JSON object from
one call to the next;
- `top`, which is interactive, and `config_conn_list`;
one call to the next, the cmds-admin `relatives` printer, which reads
sysfs like the libnvme tree printers, and the connection list of
`config show`, which prints no device data;
- `top`, which is interactive;
- `show_init`/`show_finish`, and the status and error messages, unless
a sandboxed printer prints them.

Expand Down
8 changes: 4 additions & 4 deletions Documentation/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ Firmware Table, which `nvme nbft show` parses and prints (`nbft`).

The `iostat` target fuzzes the I/O statistics of `nvme top`: the block
layer stat files of the namespaces and paths of a captured sysfs tree,
which libnvme parses, and the rates `src/nvme-iostat.c` computes from two
samples. The first line of an input is the time between the samples in
milliseconds, the target takes over `clock_gettime()` for it. It needs a
dynamically linked Linux build.
which libnvme parses, and the rates `plugins/cmds-list/nvme-iostat.c`
computes from two samples. The first line of an input is the time between
the samples in milliseconds, the target takes over `clock_gettime()` for
it. It needs a dynamically linked Linux build.

The `device` target fuzzes what nvme-cli does with the data a device
returns. It runs one of the commands which print, or size a buffer by,
Expand Down
4 changes: 2 additions & 2 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ M: Broc Going <bgoing@micron.com> (@brgoing)
M: Jeff Lien <jeff.lien@sandisk.com> (@jeff-lien-sndk)
M: Brandon Paupore <brandon.paupore@sandisk.com> (@brandon-paupore-sndk)
S: Supported
F: plugins/ocp/
F: tests/cli/ocp/
F: plugins/cmds-ocp/
F: tests/cli/cmds_ocp/

SAMSUNG PLUGIN
M: Hyuntae Kim <h1219.kim@samsung.com> (@h1219-kim)
Expand Down
20 changes: 11 additions & 9 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@
in a build without libkmod. nvme declares it in an ELF `.note.dlopen`
note. Static builds still link it.

* The plugins are modules, which nvme loads when a command uses them:
a command loads at most the module of its plugin, so nvme starts as
fast as before. They are installed in
`<libdir>/nvme-cli/<version>/plugins`. Without the module of a
plugin, `nvme <plugin>` says the plugin is not installed, so packages
can ship plugins on their own. The new `plugin-modules` option
(`auto` by default) decides; static builds, Windows and fuzz builds
link the plugins in, as before. An initramfs which runs a plugin
command needs its module, e.g. `nbft.so` for `nvme nbft show`. See
* The plugins and the top-level commands are modules, which nvme loads
when a command uses them: a command loads only the module which
provides it, so nvme starts as fast as before, and the nvme binary
shrinks to about a third. They are installed in
`<libdir>/nvme-cli/<version>/plugins`. Without the module, nvme says
the plugin or the command is not installed, so packages can ship
plugins on their own. The new `plugin-modules` option (`auto` by
default) decides; static builds, Windows and fuzz builds link the
plugins in, as before. An initramfs needs the modules of the commands
it runs, e.g. `cmds-fabrics.so` for `nvme connect-all`, `cmds-list.so`
for `nvme list-subsys` and `cmds-nbft.so` for `nvme nbft show`. See
[BUILDING.md](Documentation/BUILDING.md).

### Fabrics
Expand Down
2 changes: 0 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ conf.set('LIBNVME_PRIVSEP_HELPER',
conf.set('CONFIG_LOOPBACK', want_ioctl_tests,
description: 'Is the ioctl loopback test transport enabled')
conf.set('CONFIG_TOP', want_top, description: 'Is nvme top enabled')
conf.set('CONFIG_DEPRECATED_CMDS', want_deprecated_cmds,
description: 'Deprecated commands enabled')

if host_system == 'windows'
kernel32_dep = cc.find_library('kernel32', required: true)
Expand Down
2 changes: 1 addition & 1 deletion plugins/amzn/amzn-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "global-ctx.h"
#include "nvme-print.h"
#include "plugin.h"
#include "plugins/id/id.h"
#include "plugins/cmds-id/id.h"

#define AMZN_NVME_STATS_LOGPAGE_ID 0xD0
#define AMZN_NVME_STATS_DETAIL_IO_VERSION 1
Expand Down
11 changes: 3 additions & 8 deletions src/nvme-cmds-ctrl.c → plugins/cmds-admin/cmds-admin-ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <libnvme.h>

#include <shared/compiler-attributes-util.h>

#include "argconfig.h"
#include "cleanup.h"
#include "global-ctx.h"
Expand All @@ -30,6 +28,8 @@
#include "nvme-print.h"
#include "plugin.h"

#include "cmds-admin.h"

static const char *only_ctrl_dev = "Only controller device is allowed";

static int virtual_mgmt(int argc, char **argv, struct command *acmd, struct plugin *plugin)
Expand Down Expand Up @@ -216,15 +216,10 @@ static struct command virtual_mgmt_cmd = {
.fn = virtual_mgmt,
};

static struct command *commands[] = {
struct command *admin_ctrl_commands[] = {
&reset_cmd,
&subsystem_reset_cmd,
&ns_rescan_cmd,
&virtual_mgmt_cmd,
NULL,
};

static void __shr_constructor register_group(void)
{
plugin_add_group(&builtin, "Controller Management", commands);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <ccan/array_size/array_size.h>
#include <ccan/endian/endian.h>
#include <ccan/minmax/minmax.h>
#include <shared/compiler-attributes-util.h>
#include <shared/fs-util.h>
#include <shared/mmio-util.h>
#include <shared/parse-util.h>
Expand All @@ -49,6 +48,9 @@
#include "nvme-print.h"
#include "plugin.h"

#include "cmds-admin.h"
#include "cmds-admin-print.h"

static const char *ish = "Ignore Shutdown (for NVMe-MI command)";
static const char dash[51] = {[0 ... 49] = '=', '\0'};
static const char space[51] = {[0 ... 49] = ' ', '\0'};
Expand Down Expand Up @@ -1027,7 +1029,11 @@ static struct command *commands[] = {
NULL,
};

static void __shr_constructor register_group(void)
NVME_PLUGIN_INIT(register_plugin)
{
plugin_add_group(&builtin, "Controller Management",
admin_ctrl_commands);
plugin_add_group(&builtin, "Media Management", commands);
plugin_add_group(&builtin, "Security & Access Control",
admin_security_commands);
}
Loading