config.log
cscope.*
+
+.build
+++ /dev/null
-libnvme
--------
-
-This is the libnvme development C library. libnvme provides type
-defintions for NVMe specification structures, enumerations, and bit
-fields, helper functions to construct, dispatch, and decode commands
-and payloads, and utilities to connect, scan, and manage nvme devices
-on a Linux system.
-
-The public specification is the authority to resolve any protocol
-discrepencies with this library. For more info on NVM Express, please see:
-
- http://nvmexpress.org
-
-Subscribe to linux-nvme@lists.infradead.org for linux-nvme related discussions
-and development for both kernel and userspace. The list is archived here:
-
- http://lists.infradead.org/mailman/listinfo/linux-nvme
-
-License
--------
-
-Except where otherwise stated, all software contained within this repo is
-currently licensed LGPL, see COPYING for more information.
-
-Keith Busch 2020-02-06
--- /dev/null
+# libnvme
+
+This is the libnvme development C library. libnvme provides type
+defintions for NVMe specification structures, enumerations, and bit
+fields, helper functions to construct, dispatch, and decode commands
+and payloads, and utilities to connect, scan, and manage nvme devices
+on a Linux system.
+
+The public specification is the authority to resolve any protocol
+discrepencies with this library. For more info on NVM Express, please
+see:
+
+ http://nvmexpress.org
+
+Subscribe to linux-nvme@lists.infradead.org for linux-nvme related
+discussions and development for both kernel and userspace. The list is
+archived here:
+
+ http://lists.infradead.org/mailman/listinfo/linux-nvme
+
+# License
+
+Except where otherwise stated, all software contained within this repo
+is currently licensed LGPL, see COPYING for more information.
+
+Keith Busch 2020-02-06
+
+------
+
+# Building with meson
+
+## What is the meson build system?
+
+Here's an excerpt from the meson web site: *Meson is **an open source
+build system** meant to be both extremely fast, and, even more
+importantly, as user friendly as possible. The main design point of
+Meson is that every moment a developer spends writing or debugging
+build definitions is a second wasted.*
+
+Several well-known projects such as `systemd` and `Gnome` use meson as
+their build system. A summary of projects using meson can be found
+[here](https://mesonbuild.com/Users.html). For more info on meson,
+please consult the following sites:
+
+**Wiki page**: https://en.wikipedia.org/wiki/Meson_(software)
+
+**meson documentation**: https://mesonbuild.com/
+
+**meson repo**: https://github.com/mesonbuild/meson
+
+## Prerequisite
+
+First, install meson.
+
+**Debian / Ubuntu**:
+
+```bash
+sudo apt-get install meson
+```
+
+**Fedora / Red Hat**:
+
+```bash
+sudo dnf install meson
+```
+
+## To compile libnvme
+
+Using meson is similar to projects that use a `configure` script before running `make`.
+
+To `configure` the project:
+
+```
+meson .build
+```
+
+One nice feature of meson is that it doesn't mix build artifacts
+(e.g. `*.o`, `*.so`, etc.) with source code. In the above example,
+"`.build`" is the name of the directory where the build configuration
+as well as all the build artifacts will be saved. This directory can
+be named anything as long as it's not an existing source directory. To
+completely "clean" all the build artifacts, one need only delete the
+`.build` directory.
+
+To compile:
+
+```
+cd .build
+ninja
+```
+
+Or:
+
+```
+ninja -C .build
+```
+
+## To install libnvme
+
+To install `libnvme`:
+
+```
+cd .build
+meson install
+```
+
+## To run unit tests
+
+To run unit tests:
+
+```
+cd .build
+meson test
+```
+
+## To clean after a build
+
+To perform the equivalent of a `make clean` without deleting the build configuration.
+
+```
+cd .build
+ninja -t clean
+```
+
+Or:
+
+```
+ninja -C .build -t clean
+```
+
+## To purge everything
+
+To completely clean all build artifacts, including the build configuration.
+
+```
+rm -rf .build
+```
+
+## Supported build options
+
+A few build options can be specified on the command line when invoking meson.
+
+| Option | Values [default] | Description |
+| ------- | ------------------- | ------------------------------------------------------------ |
+| systemd | [auto], true, false | Whether to link libsystemd to libnvme. When set to `auto`, the default, meson will check for the presence of library and will only link to it if it is found. When set to `true`, meson will make this library a mandatory dependency. When set to `false`, meson will not link the library to libnvme, even if the library is available. |
+
+### Changing the build options from the command-line (i.e. w/o modifying any files)
+
+Here's an example where we tell meson that we do not want to link
+against the `systemd` library:
+
+```bash
+meson .build -Dsystemd=false
+```
+
+To configure a build for debugging purposes (i.e. optimization turned
+off and debug symbols enabled):
+
+```bash
+meson .build -Dbuildtype=debug
+```
+
+To enable address sanitizer (advanced debugging of memory issues):
+
+```bash
+meson .build -Db_sanitize=address
+```
+
+To list configuration options that are available and possible values:
+
+```bash
+meson configure .build
+```
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# This file is part of libnvme.
+# Copyright (c) 2021 Dell Inc.
+#
+# Authors: Martin Belanger <Martin.Belanger@dell.com>
+#
+configurator = executable(
+ 'configurator',
+ ['tools/configurator/configurator.c'],
+ c_args: ['-D_GNU_SOURCE'],
+)
+
+config_h = custom_target(
+ 'config.h',
+ output: 'config.h',
+ capture: true,
+ command: [configurator, ]
+)
+
+
--- /dev/null
+# SPDX-License-Identifier: BSD-3
+#
+# This file is part of STorage Appliance Services (STAS).
+# Copyright (c) 2021 Dell Inc.
+#
+# Authors: Martin Belanger <Martin.Belanger@dell.com>
+#
+
+# Requires python3-sphinx and python3-sphinx-rtd-theme
+
+sphinx_sources = [
+ 'conf.py',
+ 'libnvme.rst',
+ 'index.rst'
+]
+
+man_pages = [
+ 'libnvme.1'
+]
+
+mandir1 = join_paths(get_option('mandir'), 'man1')
+
+if get_option('man')
+ sphinx_build = find_program('sphinx-build-3', 'sphinx-build')
+
+ custom_target(
+ 'man',
+ command: [sphinx_build,
+ '-b', 'man',
+ meson.current_source_dir(),
+ meson.current_build_dir()],
+ input: sphinx_sources,
+ output: man_pages,
+ install: true,
+ install_dir: mandir1,
+ )
+endif
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# This file is part of libnvme.
+# Copyright (c) 2021 Dell Inc.
+#
+# Authors: Martin Belanger <Martin.Belanger@dell.com>
+#
+executable(
+ 'telemetry-listen',
+ ['telemetry-listen.c'],
+ link_with: libnvme_static,
+ include_directories: incdir)
+
+executable(
+ 'display-columnar',
+ ['display-columnar.c'],
+ link_with: libnvme_static,
+ include_directories: incdir)
+
+executable(
+ 'discover-loop',
+ ['discover-loop.c'],
+ link_with: libnvme_static,
+ include_directories: incdir)
+
--- /dev/null
+Name: @NAME@
+Version: @VERSION@
+Release: 0
+Summary: Linux-native nvme device management library
+License: @LICENSE@
+Source: %{name}-%{version}.tar.gz
+BuildRoot: %{_tmppath}/%{name}-root
+URL: http://github.com/linux-nvme/libnvme
+BuildRequires: gcc
+
+%description
+Provides library functions for accessing and managing nvme devices on a Linux
+system.
+
+%package devel
+Summary: Development files for Linux-native nvme
+Requires: libnvme
+Provides: libnvme.so.1
+
+%description devel
+This package provides header files to include and libraries to link with
+for Linux-native nvme device maangement.
+
+%prep
+%autosetup -c
+
+%build
+%meson
+%meson_build
+
+%install
+%meson_install
+
+%check
+%meson_test
+
+%files
+%defattr(-,root,root)
+%attr(0755,root,root) %{_libdir}/libnvme.so.*
+%doc COPYING
+
+%files devel
+%defattr(-,root,root)
+%attr(-,root,root) %{_includedir}/nvme/
+%attr(0644,root,root) %{_includedir}/libnvme.h
+%attr(0755,root,root) %{_libdir}/libnvme.so
+%attr(0644,root,root) %{_libdir}/libnvme.a
+%attr(0644,root,root) %{_libdir}/pkgconfig/*
+%attr(0644,root,root) %{_mandir}/man2/*
+
+%changelog
+* Thu Dec 12 2019 Keith Busch <kbusch@kernel.org> - 0.1
+- Initial version
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# This file is part of libnvme.
+# Copyright (c) 2021 Dell Inc.
+#
+# Authors: Martin Belanger <Martin.Belanger@dell.com>
+#
+
+################################################################################
+# Building libnvme using meson and ninja:
+# meson .build
+# ninja -C .build
+#
+# Installing the code after building:
+# cd .build
+# sudo meson install
+#
+# Running unit tests:
+# cd .build
+# meson test
+#
+# In these examples, ".build" is the name of the directory where the build
+# artifacts are saved. The directory need not be called ".build", but it must
+# be a unique (non-existing) directory.
+#
+# Changing build options from the command line:
+# Build options can be changed at the command line without modifying the
+# "meson.build" files. This is particularly useful during debugging. For
+# example, the "buildtype" option allows to disable optimization to
+# facilitate debugging. This option can be specified on the command line as
+# follows:
+#
+# meson .build -Dbuildtype=debug
+#
+# Doing so overrides the value found in the meson.build, which is set to
+# "buildtype=release" below. The buildtype option can take any of the
+# following values.
+#
+# plain: no extra build flags are used, even for compiler warnings,
+# useful for distro packagers and other cases where you need
+# to specify all arguments by yourself
+#
+# debug: debug info is generated but the result is not optimized,
+# this is the default
+#
+# debugoptimized: debug info is generated and the code is optimized (on most
+# compilers this means -g -O2)
+#
+# release: full optimization, no debug info
+#
+# default_options: https://mesonbuild.com/Builtin-options.html#compiler-options
+#
+# Examples: meson .build -Dbuildtype=debug
+# meson .build -Db_sanitize=address
+# meson .build -Djson-c=true
+#
+# References: https://mesonbuild.com/
+# https://ninja-build.org/
+#
+################################################################################
+project(
+ 'libnvme', ['c', 'cpp'],
+ meson_version: '>= 0.47.0',
+ version: '0.1',
+ license: 'LGPLv2+',
+ default_options: [
+ 'buildtype=release',
+ 'prefix=/usr',
+ ]
+)
+
+################################################################################
+cc = meson.get_compiler('c')
+
+prefixdir = get_option('prefix')
+libdir = join_paths(prefixdir, get_option('libdir'))
+includedir = join_paths(prefixdir, get_option('includedir'))
+datadir = join_paths(prefixdir, get_option('datadir'))
+mandir = join_paths(prefixdir, get_option('mandir'))
+bindir = join_paths(prefixdir, get_option('bindir'))
+
+pkgconfiglibdir = get_option('pkgconfiglibdir') == '' ? join_paths(libdir, 'pkgconfig') : get_option('pkgconfiglibdir')
+
+################################################################################
+conf = configuration_data()
+
+# Check for libuuid availability
+libuuid = dependency('uuid', required: true)
+conf.set('CONFIG_LIBUUID', libuuid.found(), description: 'Is libuuid required?')
+
+# Check for libjson-c availability
+libjson = dependency('json-c', required: false)
+if not libjson.found()
+ libjson = cc.find_library('json-c', required: true)
+endif
+conf.set('CONFIG_JSONC', libjson.found(), description: 'Is json-c required?')
+
+# Check for libsystemd availability
+want_systemd = get_option('systemd')
+if want_systemd != 'false'
+ libsystemd = dependency('libsystemd', required: want_systemd == 'true')
+ have = libsystemd.found()
+else
+ libsystemd = []
+ have = false
+endif
+conf.set('CONFIG_SYSTEMD', have, description: 'Is libsystemd required?')
+
+################################################################################
+# The following commented-out text is the beginning of an effort to replace
+# ccan/tools/configurator. It is not complete yet. Eventually we would like
+# to replace everything that ccan/tools/configurator does with meson.
+# To be continued...
+################################################################################
+#args = ['-g3', '-ggdb', '-Wall', '-Wundef', '-Wmissing-prototypes', '-Wmissing-declarations', '-Wstrict-prototypes', '-Wold-style-definition']
+#conf.set10(
+# 'HAVE_STRUCT_TIMESPEC',
+# cc.compiles(
+# '''
+# #include <time.h>
+# static void func(void) {
+# struct timespec ts;
+# ts.tv_sec = ts.tv_nsec = 1;
+# }
+# int main(int argc, char *argv[]) {
+# (void)func();
+# return 0;
+# }
+# ''',
+# no_builtin_args: true,
+# args: args,
+# name: 'struct timespec'
+# ),
+# description: 'Is struct timespec defined?'
+#)
+#conf.set10(
+# 'HAVE_ASPRINTF',
+# cc.compiles(
+# '''
+# #define _GNU_SOURCE
+# #include <stdio.h>
+# static char *func(int x) {
+# char *p;
+# if (asprintf(&p, "%u", x) == -1)
+# p = NULL;
+# return p;
+# }
+# int main(int argc, char *argv[]) {
+# (void)func(1000);
+# return 0;
+# }
+# ''',
+# no_builtin_args: true,
+# args: args,
+# name: 'asprintf()'
+# ),
+# description: 'Is asprintf() supported?'
+#)
+
+configure_file(
+ output: 'config-host.h',
+ configuration: conf
+)
+
+################################################################################
+substs = configuration_data()
+substs.set('NAME', meson.project_name())
+substs.set('VERSION', meson.project_version())
+substs.set('LICENSE', meson.project_license()[0])
+configure_file(
+ input: 'libnvme.spec.in',
+ output: 'libnvme.spec',
+ configuration: substs,
+)
+
+################################################################################
+pkg = import('pkgconfig')
+pkg.generate(
+ filebase: meson.project_name(),
+ name: meson.project_name(),
+ version: meson.project_version(),
+ description: 'Manage "libnvme" subsystem devices (Non-volatile Memory Express)',
+ url: 'http://github.com/linux-nvme/libnvme/',
+ libraries: ['-L${libdir}', '-lnvme'],
+ requires: [libuuid, libjson, libsystemd],
+)
+
+################################################################################
+add_project_arguments('-include', 'config-host.h', language : 'c')
+add_global_arguments(['-fomit-frame-pointer', '-D_GNU_SOURCE'], language : 'c')
+incdir = include_directories(['ccan', 'src'])
+
+################################################################################
+subdir('ccan')
+subdir('src')
+subdir('pynvme')
+subdir('test')
+subdir('examples')
+subdir('doc')
+
--- /dev/null
+# -*- mode: meson -*-
+
+option('pkgconfiglibdir', type : 'string', value : '', description : 'directory for standard pkg-config files')
+
+option('man', type : 'boolean', value : false, description : 'build and install man pages (requires sphinx-build)')
+
+option('systemd', type : 'combo', choices : ['auto', 'true', 'false'], description : 'libsystemd support')
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# This file is part of libnvme.
+# Copyright (c) 2021 Dell Inc.
+#
+# Authors: Martin Belanger <Martin.Belanger@dell.com>
+#
+python3 = import('python').find_installation('python3')
+swig = find_program('swig', required: true)
+pymod_swig = custom_target(
+ 'nvme.py',
+ input: ['nvme.i', config_h],
+ output: ['nvme.py', 'nvme_wrap.c'],
+ command: [swig, '-python', '-py3', '-o', '@OUTPUT1@', '@INPUT0@'],
+ install: true,
+ install_dir: [python3.get_install_dir(pure: false, subdir: 'libnvme'), false],
+)
+
+pynvme_clib = python3.extension_module(
+ '_nvme',
+ pymod_swig[1],
+ dependencies : python3.dependency(),
+ include_directories: incdir,
+ link_with: libnvme_static,
+ install: true,
+ subdir: 'libnvme',
+)
+
+python3.install_sources(
+ ['__init__.py', ],
+ pure: false,
+ subdir: 'libnvme',
+)
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# This file is part of libnvme.
+# Copyright (c) 2021 Dell Inc.
+#
+# Authors: Martin Belanger <Martin.Belanger@dell.com>
+#
+sources = [
+ 'nvme/cleanup.c',
+ 'nvme/fabrics.c',
+ 'nvme/filters.c',
+ 'nvme/ioctl.c',
+ 'nvme/log.c',
+ 'nvme/tree.c',
+ 'nvme/util.c',
+ config_h,
+]
+
+if conf.get('CONFIG_JSONC')
+ sources += 'nvme/json.c'
+endif
+
+deps = [
+ libuuid,
+ libsystemd,
+ libjson,
+]
+
+source_dir = meson.current_source_dir()
+mapfile = 'libnvme.map'
+version_script_arg = join_paths(source_dir, mapfile)
+
+libnvme_shared = shared_library(
+ 'nvme', # produces libnvme.so
+ sources,
+ version: meson.project_version(),
+ soversion: '1',
+ link_args: ['-Wl,--version-script=' + version_script_arg],
+ dependencies: deps,
+ link_depends: mapfile,
+ include_directories: incdir,
+ install: true,
+)
+
+libnvme_static = static_library(
+ 'nvme', # produces libnvme.a
+ sources,
+ link_args: ['-Wl,--version-script=' + version_script_arg],
+ dependencies: deps,
+ link_depends: mapfile,
+ include_directories: incdir,
+ install : false
+)
+
+mode = ['rw-r--r--', 0, 0]
+install_headers('libnvme.h', install_mode: mode)
+install_headers([
+ 'nvme/fabrics.h',
+ 'nvme/filters.h',
+ 'nvme/ioctl.h',
+ 'nvme/log.h',
+ 'nvme/tree.h',
+ 'nvme/types.h',
+ 'nvme/util.h',
+ ],
+ subdir: 'nvme',
+ install_mode: mode,
+)
+
+
+
--- /dev/null
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# This file is part of libnvme.
+# Copyright (c) 2021 Dell Inc.
+#
+# Authors: Martin Belanger <Martin.Belanger@dell.com>
+#
+main = executable(
+ 'main-test',
+ ['test.c'],
+ link_with: libnvme_static,
+ include_directories: incdir
+)
+
+cpp = executable(
+ 'test-cpp',
+ ['cpp.cc'],
+ link_with: libnvme_static,
+ include_directories: incdir
+)
+
+register = executable(
+ 'test-register',
+ ['register.c'],
+ link_with: libnvme_static,
+ include_directories: incdir
+)
+
+zns = executable(
+ 'test-zns',
+ ['zns.c'],
+ link_with: libnvme_static,
+ include_directories: incdir
+)
+
+test('main', main)
+test('main', main, args: ['nvme10'])
+test('cpp', main)
+test('register', main, args: ['nvme10'])
+test('zns', main)