nvme-cli: move 0001-add-libnvme_cli.patch to meta-gbmc-staging layer
The patch was created by jianghao@google.com to expose the the printing
function.
Patch Tracking Bug: b/275094975
Upstream info / review: N/A
Upstream-Status: Pending
Tested: Fusion link
Google-Bug-Id: 339513319
Fusion-link: https://fusion2.corp.google.com/08bb5416-e21f-39a5-b86e-cfcdab821b89
Change-Id: I4fff3d132cbbc83ece910ac9439289905565fb05
Signed-off-by: Jinliang Wang <jinliangw@google.com>
diff --git a/recipes-connectivity/nvme-cli/nvme-cli/0001-add-libnvme_cli.patch b/recipes-connectivity/nvme-cli/nvme-cli/0001-add-libnvme_cli.patch
new file mode 100644
index 0000000..e19eb7c
--- /dev/null
+++ b/recipes-connectivity/nvme-cli/nvme-cli/0001-add-libnvme_cli.patch
@@ -0,0 +1,155 @@
+From 079d95cbf05162e80771aed93341ea458484a6c6 Mon Sep 17 00:00:00 2001
+From: Hao Jiang <jianghao@google.com>
+Date: Fri, 4 Nov 2022 14:17:38 -0700
+Subject: [PATCH] add libnvme_cli
+
+Re-construct the function of cli into a library. This is to expose the
+intenal function to the caller so the printing function could be reused.
+
+Patch Tracking Bug: b/275094975
+Upstream info / review: N/A
+Upstream-Status: Pending
+Justification: Currently the patch is not capable to upstream since
+the nvme-cli is not a good place for such util library. Hao will talk
+with the maintainers of libnvme whether such util can be move from cli
+into libnvme.
+
+Signed-off-by: Hao Jiang <jianghao@google.com>
+---
+ meson.build | 28 ++++++++++++++++++++++++++--
+ nvme-print.h | 20 +++++++++++++-------
+ nvme.h | 21 ++++++++-------------
+ plugins/huawei/huawei-nvme.c | 1 +
+ 4 files changed, 48 insertions(+), 22 deletions(-)
+
+diff --git a/meson.build b/meson.build
+index 719aa0e5..226e2036 100644
+--- a/meson.build
++++ b/meson.build
+@@ -256,12 +256,36 @@ endif
+ subdir('util')
+ subdir('Documentation')
+
+-executable(
+- 'nvme',
++libnvme_cli = library(
++ 'nvme-cli',
+ sources,
+ dependencies: [ libnvme_dep, libnvme_mi_dep, json_c_dep, libz_dep,
+ libhugetlbfs_dep ],
+ link_args: '-ldl',
++ include_directories: [incdir, '.'],
++ version: meson.project_version(),
++ install: true,
++)
++
++libnvme_cli_dep = declare_dependency(
++ include_directories: [incdir, '.'],
++ link_with: libnvme_cli,
++)
++
++pkg = import('pkgconfig')
++pkg.generate(libnvme_cli,
++ filebase: 'libnvme-cli',
++ name: 'libnvme-cli',
++ version: meson.project_version(),
++ description: 'NVMe cli util library',
++ url: 'http://github.com/linux-nvme/nvme-cli/',
++)
++
++install_headers('nvme-print.h')
++
++executable(
++ 'nvme',
++ link_with: libnvme_cli,
+ include_directories: incdir,
+ install: true,
+ install_dir: sbindir
+diff --git a/nvme-print.h b/nvme-print.h
+index f30f63eb..f71183a1 100644
+--- a/nvme-print.h
++++ b/nvme-print.h
+@@ -2,16 +2,22 @@
+ #ifndef NVME_PRINT_H
+ #define NVME_PRINT_H
+
+-#include "nvme.h"
+ #include <inttypes.h>
+
+-#include <ccan/list/list.h>
++enum nvme_print_flags
++{
++ NORMAL = 0,
++ VERBOSE = 1 << 0, /* verbosely decode complex values for humans */
++ JSON = 1 << 1, /* display in json format */
++ VS = 1 << 2, /* hex dump vendor specific data areas */
++ BINARY = 1 << 3, /* binary dump raw bytes */
++};
+
+-typedef struct nvme_effects_log_node {
+- enum nvme_csi csi;
+- struct nvme_cmd_effects_log effects;
+- struct list_node node;
+-} nvme_effects_log_node_t;
++enum nvme_cli_topo_ranking
++{
++ NVME_CLI_TOPO_NAMESPACE,
++ NVME_CLI_TOPO_CTRL,
++};
+
+ void d(unsigned char *buf, int len, int width, int group);
+ void d_raw(unsigned char *buf, unsigned len);
+diff --git a/nvme.h b/nvme.h
+index c13ca8e9..c70f9b82 100644
+--- a/nvme.h
++++ b/nvme.h
+@@ -29,19 +29,7 @@
+ #include "plugin.h"
+ #include "util/json.h"
+ #include "util/argconfig.h"
+-
+-enum nvme_print_flags {
+- NORMAL = 0,
+- VERBOSE = 1 << 0, /* verbosely decode complex values for humans */
+- JSON = 1 << 1, /* display in json format */
+- VS = 1 << 2, /* hex dump vendor specific data areas */
+- BINARY = 1 << 3, /* binary dump raw bytes */
+-};
+-
+-enum nvme_cli_topo_ranking {
+- NVME_CLI_TOPO_NAMESPACE,
+- NVME_CLI_TOPO_CTRL,
+-};
++#include <ccan/list/list.h>
+
+ #define SYS_NVME "/sys/class/nvme"
+
+@@ -121,6 +109,13 @@ static inline void nvme_strip_spaces(char *s, int l)
+ }
+
+ /* nvme-print.c */
++typedef struct nvme_effects_log_node
++{
++ enum nvme_csi csi;
++ struct nvme_cmd_effects_log effects;
++ struct list_node node;
++} nvme_effects_log_node_t;
++
+ const char *nvme_select_to_string(int sel);
+
+ void d(unsigned char *buf, int len, int width, int group);
+diff --git a/plugins/huawei/huawei-nvme.c b/plugins/huawei/huawei-nvme.c
+index 572086ce..18aff3a3 100644
+--- a/plugins/huawei/huawei-nvme.c
++++ b/plugins/huawei/huawei-nvme.c
+@@ -31,6 +31,7 @@
+ #include "nvme.h"
+ #include "libnvme.h"
+ #include "plugin.h"
++#include "nvme-print.h"
+
+ #include "util/suffix.h"
+
+--
+2.39.0.314.g84b9a713c41-goog
+
diff --git a/recipes-connectivity/nvme-cli/nvme-cli_2.1.2.git.bb b/recipes-connectivity/nvme-cli/nvme-cli_2.1.2.git.bb
index eb436c8..744fbea 100644
--- a/recipes-connectivity/nvme-cli/nvme-cli_2.1.2.git.bb
+++ b/recipes-connectivity/nvme-cli/nvme-cli_2.1.2.git.bb
@@ -11,6 +11,11 @@
SRCREV = "c045535fb0e0e3d3059ed65f18ff9f541e2ad0ac"
S = "${WORKDIR}/git"
+
+SRC_URI:append:gbmc = " \
+ file://0001-add-libnvme_cli.patch \
+"
+
inherit bash-completion systemd meson pkgconfig
do_install:append() {