Blame README.md

Packit dd4ba5
# nvme-cli
Packit dd4ba5
NVM-Express user space tooling for Linux.
Packit dd4ba5
Packit dd4ba5
To install, run:
Packit dd4ba5
Packit dd4ba5
    $ make
Packit dd4ba5
    # make install
Packit dd4ba5
Packit dd4ba5
If not sure how to use, find the top-level documentation with:
Packit dd4ba5
Packit dd4ba5
    $ man nvme
Packit dd4ba5
Packit dd4ba5
Or find a short summary with:
Packit dd4ba5
Packit dd4ba5
    $ nvme help
Packit dd4ba5
Packit dd4ba5
## Distro Support
Packit dd4ba5
Packit dd4ba5
### Alpine Linux
Packit dd4ba5
Packit dd4ba5
nvme-cli is tested on Alpine Linux 3.3.  Install it using:
Packit dd4ba5
Packit dd4ba5
    # apk update && apk add nvme-cli nvme-cli-doc
Packit dd4ba5
Packit dd4ba5
if you just use the device you're after, it will work flawless.
Packit dd4ba5
```
Packit dd4ba5
# nvme smart-log /dev/nvme0
Packit dd4ba5
Smart Log for NVME device:/dev/nvme0 namespace-id:ffffffff
Packit dd4ba5
critical_warning                    : 0
Packit dd4ba5
temperature                         : 49 C
Packit dd4ba5
available_spare                     : 100%
Packit dd4ba5
```
Packit dd4ba5
Packit dd4ba5
### Arch Linux
Packit dd4ba5
Packit dd4ba5
nvme-cli is available in the `[community]` repository. It can be installed with:
Packit dd4ba5
Packit dd4ba5
    # pacman -S nvme-cli
Packit dd4ba5
Packit dd4ba5
The development version can be installed from AUR, e.g.:
Packit dd4ba5
Packit dd4ba5
    $ yay -S nvme-cli-git
Packit dd4ba5
Packit dd4ba5
### Fedora
Packit dd4ba5
Packit dd4ba5
nvme-cli is available in Fedora 23 and up.  Install it with your favorite
Packit dd4ba5
package manager.  For example:
Packit dd4ba5
Packit dd4ba5
    $ sudo dnf install nvme-cli
Packit dd4ba5
Packit dd4ba5
### FreeBSD
Packit dd4ba5
Packit dd4ba5
`nvme-cli` is available in the FreeBSD Ports Collection.  A prebuilt binary
Packit dd4ba5
package can be installed with:
Packit dd4ba5
Packit dd4ba5
```console
Packit dd4ba5
# pkg install nvme-cli
Packit dd4ba5
```
Packit dd4ba5
Packit dd4ba5
### Gentoo
Packit dd4ba5
Packit dd4ba5
nvme-cli is available and tested in portage:
Packit dd4ba5
```
Packit dd4ba5
$ emerge -av nvme-cli
Packit dd4ba5
```
Packit dd4ba5
Packit dd4ba5
### Nix(OS)
Packit dd4ba5
Packit dd4ba5
The attribute is named `nvme-cli` and can e.g. be installed with:
Packit dd4ba5
```
Packit dd4ba5
$ nix-env -f '<nixpkgs>' -iA nvme-cli
Packit dd4ba5
```
Packit dd4ba5
Packit dd4ba5
### openSUSE
Packit dd4ba5
Packit dd4ba5
nvme-cli is available in openSUSE Leap 42.2 or later and Tumbleweed. You can install it using zypper.
Packit dd4ba5
For example:
Packit dd4ba5
Packit dd4ba5
    $ sudo zypper install nvme-cli
Packit dd4ba5
Packit dd4ba5
### Ubuntu
Packit dd4ba5
Packit dd4ba5
nvme-cli is supported in the Universe package sources for Xenial for
Packit dd4ba5
many architectures. For a complete list try running:
Packit dd4ba5
  ```
Packit dd4ba5
  rmadison nvme-cli
Packit dd4ba5
   nvme-cli | 0.3-1 | xenial/universe | source, amd64, arm64, armhf, i386, powerpc, ppc64el, s390x
Packit dd4ba5
  ```
Packit dd4ba5
A Debian based package for nvme-cli is currently maintained as a
Packit dd4ba5
Ubuntu PPA. Right now there is support for Trusty, Vivid and Wiley. To
Packit dd4ba5
install nvme-cli using this approach please perform the following
Packit dd4ba5
steps:
Packit dd4ba5
   1. Add the sbates PPA to your sources. One way to do this is to run
Packit dd4ba5
   ```
Packit dd4ba5
   sudo add-apt-repository ppa:sbates
Packit dd4ba5
   ```
Packit dd4ba5
   2. Perform an update of your repository list:
Packit dd4ba5
   ```
Packit dd4ba5
   sudo apt-get update
Packit dd4ba5
   ```
Packit dd4ba5
   3. Get nvme-cli!
Packit dd4ba5
   ```
Packit dd4ba5
   sudo apt-get install nvme-cli
Packit dd4ba5
   ```
Packit dd4ba5
   4. Test the code.
Packit dd4ba5
   ```
Packit dd4ba5
   sudo nvme list
Packit dd4ba5
   ```
Packit dd4ba5
   In the case of no NVMe devices you will see
Packit dd4ba5
   ```
Packit dd4ba5
   No NVMe devices detected.
Packit dd4ba5
   ```
Packit dd4ba5
   otherwise you will see information about each NVMe device installed
Packit dd4ba5
   in the system.
Packit dd4ba5
Packit dd4ba5
### OpenEmbedded/Yocto
Packit dd4ba5
Packit dd4ba5
An [nvme-cli recipe](https://layers.openembedded.org/layerindex/recipe/88631/)
Packit dd4ba5
is available as part of the `meta-openembeded` layer collection.
Packit dd4ba5
Packit dd4ba5
### Buildroot
Packit dd4ba5
Packit dd4ba5
`nvme-cli` is available as [buildroot](https://buildroot.org) package. The
Packit dd4ba5
package is named `nvme`.
Packit dd4ba5
Packit dd4ba5
### Other Distros
Packit dd4ba5
Packit dd4ba5
TBD
Packit dd4ba5
Packit dd4ba5
## Developers
Packit dd4ba5
Packit dd4ba5
You may wish to add a new command or possibly an entirely new plug-in
Packit dd4ba5
for some special extension outside the spec.
Packit dd4ba5
Packit dd4ba5
This project provides macros that help generate the code for you. If
Packit dd4ba5
you're interested in how that works, it is very similar to how trace
Packit dd4ba5
events are created by Linux kernel's 'ftrace' component.
Packit dd4ba5
Packit dd4ba5
### Add command to existing built-in
Packit dd4ba5
Packit dd4ba5
The first thing to do is define a new command entry in the command
Packit dd4ba5
list. This is declared in nvme-builtin.h. Simply append a new "ENTRY" into
Packit dd4ba5
the list. The ENTRY normally takes three arguments: the "name" of the 
Packit dd4ba5
subcommand (this is what the user will type at the command line to invoke
Packit dd4ba5
your command), a short help description of what your command does, and the
Packit dd4ba5
name of the function callback that you're going to write. Additionally,
Packit dd4ba5
You can declare an alias name of subcommand with fourth argument, if needed.
Packit dd4ba5
Packit dd4ba5
After the ENTRY is defined, you need to implement the callback. It takes
Packit dd4ba5
four arguments: argc, argv, the command structure associated with the
Packit dd4ba5
callback, and the plug-in structure that contains that command. The
Packit dd4ba5
prototype looks like this:
Packit dd4ba5
Packit dd4ba5
  ```c
Packit dd4ba5
  int f(int argc, char **argv, struct command *cmd, struct plugin *plugin);
Packit dd4ba5
  ```
Packit dd4ba5
Packit dd4ba5
The argc and argv are adjusted from the command line arguments to start
Packit dd4ba5
after the sub-command. So if the command line is "nvme foo --option=bar",
Packit dd4ba5
the argc is 1 and argv starts at "--option".
Packit dd4ba5
Packit dd4ba5
You can then define argument parsing for your sub-command's specific
Packit dd4ba5
options then do some command specific action in your callback.
Packit dd4ba5
Packit dd4ba5
### Add a new plugin
Packit dd4ba5
Packit dd4ba5
The nvme-cli provides macros to make define a new plug-in simpler. You
Packit dd4ba5
can certainly do all this by hand if you want, but it should be easier
Packit dd4ba5
to get going using the macros. To start, first create a header file
Packit dd4ba5
to define your plugin. This is where you will give your plugin a name,
Packit dd4ba5
description, and define all the sub-commands your plugin implements.
Packit dd4ba5
Packit dd4ba5
There is a very important order on how to define the plugin. The following
Packit dd4ba5
is a basic example on how to start this:
Packit dd4ba5
Packit dd4ba5
File: foo-plugin.h
Packit dd4ba5
```c
Packit dd4ba5
#undef CMD_INC_FILE
Packit dd4ba5
#define CMD_INC_FILE plugins/foo/foo-plugin
Packit dd4ba5
Packit dd4ba5
#if !defined(FOO) || defined(CMD_HEADER_MULTI_READ)
Packit dd4ba5
#define FOO
Packit dd4ba5
Packit dd4ba5
#include "cmd.h"
Packit dd4ba5
Packit dd4ba5
PLUGIN(NAME("foo", "Foo plugin"),
Packit dd4ba5
	COMMAND_LIST(
Packit dd4ba5
		ENTRY("bar", "foo bar", bar)
Packit dd4ba5
		ENTRY("baz", "foo baz", baz)
Packit dd4ba5
		ENTRY("qux", "foo quz", qux)
Packit dd4ba5
	)
Packit dd4ba5
);
Packit dd4ba5
Packit dd4ba5
#endif
Packit dd4ba5
Packit dd4ba5
#include "define_cmd.h"
Packit dd4ba5
```
Packit dd4ba5
Packit dd4ba5
In order to have the compiler generate the plugin through the xmacro
Packit dd4ba5
expansion, you need to include this header in your source file, with
Packit dd4ba5
pre-defining macro directive to create the commands.
Packit dd4ba5
Packit dd4ba5
To get started from the above example, we just need to define "CREATE_CMD"
Packit dd4ba5
and include the header:
Packit dd4ba5
Packit dd4ba5
File: foo-plugin.c
Packit dd4ba5
```c
Packit dd4ba5
#include "nvme.h"
Packit dd4ba5
Packit dd4ba5
#define CREATE_CMD
Packit dd4ba5
#include "foo-plugin.h"
Packit dd4ba5
```
Packit dd4ba5
Packit dd4ba5
After that, you just need to implement the functions you defined in each
Packit dd4ba5
ENTRY, then append the object file name to the Makefile's "OBJS".