已合并
实现nvme ocp get-dssd-power-state-feature命令 #36
kouwq创建于 9月1日
实现nvme ocp get-dssd-power-state-feature命令 #36
已合并
共 4 个文件变更+2562-1
| @@ -0,0 +1,31 @@ | |||
| 1 | +From a6a01bd2418dd97ee869d376671c5bfe580a23c0 Mon Sep 17 00:00:00 2001 | ||
| 2 | +From: Brandon Paupore <brandon.paupore@wdc.com> | ||
| 3 | +Date: Thu, 14 Dec 2023 14:15:31 -0600 | ||
| 4 | +Subject: [PATCH] ocp: fix for power-state argument checking | ||
| 5 | + | ||
| 6 | +Noticed this as part of supporting set-telemetry-profile, it seems that | ||
| 7 | +the power-state option is not being detected properly. With this fix the | ||
| 8 | +function is able to enter set_dssd_power_state when given the option or | ||
| 9 | +its alias. | ||
| 10 | + | ||
| 11 | +Signed-off-by: Brandon Paupore <brandon.paupore@wdc.com> | ||
| 12 | +--- | ||
| 13 | + plugins/ocp/ocp-nvme.c | 2 +- | ||
| 14 | + 1 file changed, 1 insertion(+), 1 deletion(-) | ||
| 15 | + | ||
| 16 | +diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c | ||
| 17 | +index 53ae0f40c..d11656932 100644 | ||
| 18 | +--- a/plugins/ocp/ocp-nvme.c | ||
| 19 | ++++ b/plugins/ocp/ocp-nvme.c | ||
| 20 | +@@ -2143,7 +2143,7 @@ static int set_dssd_power_state_feature(int argc, char **argv, struct command *c | ||
| 21 | + if (err) | ||
| 22 | + return err; | ||
| 23 | + | ||
| 24 | +- if (argconfig_parse_seen(opts, "power state")) | ||
| 25 | ++ if (argconfig_parse_seen(opts, "power-state")) | ||
| 26 | + err = set_dssd_power_state(dev, nsid, fid, cfg.power_state, | ||
| 27 | + cfg.save, | ||
| 28 | + !argconfig_parse_seen(opts, "no-uuid")); | ||
| 29 | +-- | ||
| 30 | +2.43.0 | ||
| 31 | + | ||
| @@ -0,0 +1,284 @@ | |||
| 1 | +From 7a35395e9c8c507e0ae291e9676d987ef7c781de Mon Sep 17 00:00:00 2001 | ||
| 2 | +From: Arthur Shau <arthurshau@meta.com> | ||
| 3 | +Date: Thu, 9 May 2024 11:41:16 -0700 | ||
| 4 | +Subject: [PATCH] ocp: Add Get DSSD Power State Feature (FID: C7h) | ||
| 5 | + | ||
| 6 | +Implements the Get DSSD Power State Feature (FID C7h). Also added an | ||
| 7 | +optional flag that you can pass to the plugin command to print out | ||
| 8 | +all three values at once. | ||
| 9 | + | ||
| 10 | +Signed-off-by: Arthur Shau <arthurshau@meta.com> | ||
| 11 | +--- | ||
| 12 | + .../nvme-ocp-get-dssd-power-state-feature.txt | 74 +++++++++++++ | ||
| 13 | + completions/_nvme | 15 +++ | ||
| 14 | + completions/bash-nvme-completion.sh | 6 +- | ||
| 15 | + plugins/ocp/ocp-nvme.c | 100 ++++++++++++++++++ | ||
| 16 | + plugins/ocp/ocp-nvme.h | 3 +- | ||
| 17 | + 5 files changed, 196 insertions(+), 2 deletions(-) | ||
| 18 | + create mode 100644 Documentation/nvme-ocp-get-dssd-power-state-feature.txt | ||
| 19 | + | ||
| 20 | +diff --git a/Documentation/nvme-ocp-get-dssd-power-state-feature.txt b/Documentation/nvme-ocp-get-dssd-power-state-feature.txt | ||
| 21 | +new file mode 100644 | ||
| 22 | +index 0000000..716de05 | ||
| 23 | +--- /dev/null | ||
| 24 | ++++ b/Documentation/nvme-ocp-get-dssd-power-state-feature.txt | ||
| 25 | +@@ -0,0 +1,74 @@ | ||
| 26 | ++get-dssd-power-state-feature(1) | ||
| 27 | ++=============================== | ||
| 28 | ++ | ||
| 29 | ++NAME | ||
| 30 | ++---- | ||
| 31 | ++nvme-ocp-get-dssd-power-state-feature - Get DSSD Power State | ||
| 32 | ++ | ||
| 33 | ++SYNOPSIS | ||
| 34 | ++-------- | ||
| 35 | ++[verse] | ||
| 36 | ++'nvme ocp get-dssd-power-state-feature' <device> | ||
| 37 | ++ [--sel=<select> | -S <select>] [--all | -a] | ||
| 38 | ++ [--no-uuid | -n] | ||
| 39 | ++ | ||
| 40 | ++DESCRIPTION | ||
| 41 | ++----------- | ||
| 42 | ++For the NVMe device given, retrieves OCP DSSD Power State. | ||
| 43 | ++Passing --all calls NVMe Get Feature three times, returning all three of | ||
| 44 | ++the Current, Default, and Saved values. | ||
| 45 | ++ | ||
| 46 | ++The <device> parameter is mandatory and may be either the NVMe character | ||
| 47 | ++device (ex: /dev/nvme0) or block device (ex: /dev/nvme0n1). | ||
| 48 | ++ | ||
| 49 | ++This will only work on OCP compliant devices supporting this feature. | ||
| 50 | ++Results for any other device are undefined. | ||
| 51 | ++ | ||
| 52 | ++On success it returns 0, error code otherwise. | ||
| 53 | ++ | ||
| 54 | ++OPTIONS | ||
| 55 | ++------- | ||
| 56 | ++-S <select>:: | ||
| 57 | ++--sel=<select>:: | ||
| 58 | ++ Select (SEL): This field specifies which value of the attributes | ||
| 59 | ++ to return in the provided data: | ||
| 60 | +++ | ||
| 61 | ++[] | ||
| 62 | ++|================== | ||
| 63 | ++|Select|Description | ||
| 64 | ++|0|Current | ||
| 65 | ++|1|Default | ||
| 66 | ++|2|Saved | ||
| 67 | ++|3|Supported capabilities | ||
| 68 | ++|4-7|Reserved | ||
| 69 | ++|================== | ||
| 70 | ++ | ||
| 71 | ++-a:: | ||
| 72 | ++--all:: | ||
| 73 | ++ Print out all 3 values at once - Current DSSD Power State, | ||
| 74 | ++ Default DSSD Power State, and Saved DSSD Power State | ||
| 75 | ++ | ||
| 76 | ++-n:: | ||
| 77 | ++--no-uuid:: | ||
| 78 | ++ Do not try to automatically detect UUID index for this command (required | ||
| 79 | ++ for old OCP 1.0 support) | ||
| 80 | ++ | ||
| 81 | ++EXAMPLES | ||
| 82 | ++-------- | ||
| 83 | ++* Has the program issue a get-dssd-power-state-feature command to get the Curent DSSD Power State in watts. | ||
| 84 | +++ | ||
| 85 | ++------------ | ||
| 86 | ++# nvme ocp get-dssd-power-state-feature /dev/nvme0 -S 0 | ||
| 87 | ++------------ | ||
| 88 | +++ | ||
| 89 | ++ | ||
| 90 | ++* Has the program issue a get-dssd-power-state-feature command to get all three DSSD Power States in watts. | ||
| 91 | +++ | ||
| 92 | ++------------ | ||
| 93 | ++# nvme ocp get-dssd-power-state-feature /dev/nvme0 -a | ||
| 94 | ++------------ | ||
| 95 | ++ | ||
| 96 | ++ | ||
| 97 | ++NVME | ||
| 98 | ++---- | ||
| 99 | ++Part of the nvme-user suite. | ||
| 100 | +diff --git a/completions/_nvme b/completions/_nvme | ||
| 101 | +index e90fc42..bb8fb47 100644 | ||
| 102 | +--- a/completions/_nvme | ||
| 103 | ++++ b/completions/_nvme | ||
| 104 | +@@ -254,6 +254,20 @@ _nvme () { | ||
| 105 | + _arguments '*:: :->subcmds' | ||
| 106 | + _describe -t commands "nvme ocp set-dssd-power-state-feature options" _set_dssd_power_state_feature | ||
| 107 | + ;; | ||
| 108 | ++ (get-dssd-power-state-feature) | ||
| 109 | ++ local _get_dssd_power_state_feature | ||
| 110 | ++ _get_dssd_power_state_feature=( | ||
| 111 | ++ /dev/nvme':supply a device to use (required)' | ||
| 112 | ++ --sel=':select from 0 - current, 1 - default, 2 - saved, 3 - supported' | ||
| 113 | ++ -S':alias to --sel' | ||
| 114 | ++ --all=':Print out all 3 values at once - current, default, and saved' | ||
| 115 | ++ -a':alias to --all' | ||
| 116 | ++ --no-uuid':Skip UUID index search' | ||
| 117 | ++ -n':alias for --no-uuid' | ||
| 118 | ++ ) | ||
| 119 | ++ _arguments '*:: :->subcmds' | ||
| 120 | ++ _describe -t commands "nvme ocp get-dssd-power-state-feature options" _get_dssd_power_state_feature | ||
| 121 | ++ ;; | ||
| 122 | + (telemetry-string-log) | ||
| 123 | + local _telemetry_string_log | ||
| 124 | + _telemetry_string_log=( | ||
| 125 | +@@ -2254,6 +2268,7 @@ _nvme () { | ||
| 126 | + vs-fw-activate-history':Get firmware activation history log' | ||
| 127 | + device-capability-log':Get Device capability log' | ||
| 128 | + set-dssd-power-state-feature':Set DSSD Power State' | ||
| 129 | ++ get-dssd-power-state-feature':Get DSSD Power State' | ||
| 130 | + telemetry-string-log':Retrieve Telemetry string Log Page' | ||
| 131 | + ) | ||
| 132 | + _arguments '*:: :->subcmds' | ||
| 133 | +diff --git a/completions/bash-nvme-completion.sh b/completions/bash-nvme-completion.sh | ||
| 134 | +index d862aab..2ed31f7 100644 | ||
| 135 | +--- a/completions/bash-nvme-completion.sh | ||
| 136 | ++++ b/completions/bash-nvme-completion.sh | ||
| 137 | +@@ -1441,6 +1441,9 @@ plugin_ocp_opts () { | ||
| 138 | + "set-dssd-power-state-feature") | ||
| 139 | + opts+=" --power-state= -p --no-uuid -n --save -s" | ||
| 140 | + ;; | ||
| 141 | ++ "get-dssd-power-state-feature") | ||
| 142 | ++ opts+=" --sel= -S --all -a --no-uuid -n" | ||
| 143 | ++ ;; | ||
| 144 | + "telemetry-string-log") | ||
| 145 | + opts+=" --output-file= -o" | ||
| 146 | + ;; | ||
| 147 | +@@ -1519,7 +1522,8 @@ _nvme_subcmds () { | ||
| 148 | + clear-fw-activate-history eol-plp-failure-mode \ | ||
| 149 | + clear-pcie-correctable-error-counters \ | ||
| 150 | + vs-fw-activate-history device-capability-log \ | ||
| 151 | +- set-dssd-power-state-feature telemetry-string-log" | ||
| 152 | ++ set-dssd-power-state-feature get-dssd-power-state-feature \ | ||
| 153 | ++ telemetry-string-log" | ||
| 154 | + ) | ||
| 155 | + | ||
| 156 | + # Associative array mapping plugins to corresponding option completions | ||
| 157 | +diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c | ||
| 158 | +index d116569..468b559 100644 | ||
| 159 | +--- a/plugins/ocp/ocp-nvme.c | ||
| 160 | ++++ b/plugins/ocp/ocp-nvme.c | ||
| 161 | +@@ -2153,6 +2153,106 @@ static int set_dssd_power_state_feature(int argc, char **argv, struct command *c | ||
| 162 | + return err; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | ++/////////////////////////////////////////////////////////////////////////////// | ||
| 166 | ++/////////////////////////////////////////////////////////////////////////////// | ||
| 167 | ++/////////////////////////////////////////////////////////////////////////////// | ||
| 168 | ++/////////////////////////////////////////////////////////////////////////////// | ||
| 169 | ++/// DSSD Power State (Feature Identifier C7h) Get Feature | ||
| 170 | ++ | ||
| 171 | ++static int get_dssd_power_state(struct nvme_dev *dev, const __u32 nsid, | ||
| 172 | ++ const __u8 fid, __u8 sel, bool uuid) | ||
| 173 | ++{ | ||
| 174 | ++ __u32 result; | ||
| 175 | ++ int err; | ||
| 176 | ++ int uuid_index = 0; | ||
| 177 | ++ | ||
| 178 | ++ if (uuid) { | ||
| 179 | ++ /* OCP 2.0 requires UUID index support */ | ||
| 180 | ++ err = ocp_get_uuid_index(dev, &uuid_index); | ||
| 181 | ++ if (err || !uuid_index) { | ||
| 182 | ++ nvme_show_error("ERROR: No OCP UUID index found"); | ||
| 183 | ++ return err; | ||
| 184 | ++ } | ||
| 185 | ++ } | ||
| 186 | ++ | ||
| 187 | ++ struct nvme_get_features_args args = { | ||
| 188 | ++ .args_size = sizeof(args), | ||
| 189 | ++ .fd = dev_fd(dev), | ||
| 190 | ++ .fid = fid, | ||
| 191 | ++ .nsid = nsid, | ||
| 192 | ++ .sel = sel, | ||
| 193 | ++ .cdw11 = 0, | ||
| 194 | ++ .uuidx = uuid_index, | ||
| 195 | ++ .data_len = 0, | ||
| 196 | ++ .data = NULL, | ||
| 197 | ++ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, | ||
| 198 | ++ .result = &result, | ||
| 199 | ++ }; | ||
| 200 | ++ | ||
| 201 | ++ err = nvme_get_features(&args); | ||
| 202 | ++ if (!err) { | ||
| 203 | ++ printf("get-feature:0xC7 %s value: %#08x\n", nvme_select_to_string(sel), result); | ||
| 204 | ++ | ||
| 205 | ++ if (sel == NVME_GET_FEATURES_SEL_SUPPORTED) | ||
| 206 | ++ nvme_show_select_result(fid, result); | ||
| 207 | ++ } else { | ||
| 208 | ++ nvme_show_error("Could not get feature: 0xC7 with sel: %d\n", sel); | ||
| 209 | ++ } | ||
| 210 | ++ | ||
| 211 | ++ return err; | ||
| 212 | ++} | ||
| 213 | ++ | ||
| 214 | ++static int get_dssd_power_state_feature(int argc, char **argv, struct command *cmd, | ||
| 215 | ++ struct plugin *plugin) | ||
| 216 | ++{ | ||
| 217 | ++ const char *desc = "Define DSSD Power State (Feature Identifier C7h) Get Feature."; | ||
| 218 | ++ const char *all = "Print out all 3 values at once - Current, Default, and Saved"; | ||
| 219 | ++ const char *sel = "[0-3]: current/default/saved/supported/"; | ||
| 220 | ++ const __u32 nsid = 0; | ||
| 221 | ++ const __u8 fid = 0xC7; | ||
| 222 | ++ struct nvme_dev *dev; | ||
| 223 | ++ int i, err; | ||
| 224 | ++ | ||
| 225 | ++ struct config { | ||
| 226 | ++ __u8 sel; | ||
| 227 | ++ bool all; | ||
| 228 | ++ }; | ||
| 229 | ++ | ||
| 230 | ++ struct config cfg = { | ||
| 231 | ++ .sel = 0, | ||
| 232 | ++ .all = false, | ||
| 233 | ++ }; | ||
| 234 | ++ | ||
| 235 | ++ OPT_ARGS(opts) = { | ||
| 236 | ++ OPT_BYTE("sel", 'S', &cfg.sel, sel), | ||
| 237 | ++ OPT_FLAG("all", 'a', NULL, all), | ||
| 238 | ++ OPT_FLAG("no-uuid", 'n', NULL, | ||
| 239 | ++ "Skip UUID index search (UUID index not required for OCP 1.0)"), | ||
| 240 | ++ OPT_END() | ||
| 241 | ++ }; | ||
| 242 | ++ | ||
| 243 | ++ err = parse_and_open(&dev, argc, argv, desc, opts); | ||
| 244 | ++ if (err) | ||
| 245 | ++ return err; | ||
| 246 | ++ | ||
| 247 | ++ if (argconfig_parse_seen(opts, "all")) { | ||
| 248 | ++ for (i = 0; i < 3; i++) { | ||
| 249 | ++ err = get_dssd_power_state(dev, nsid, fid, i, | ||
| 250 | ++ !argconfig_parse_seen(opts, "no-uuid")); | ||
| 251 | ++ if (err) | ||
| 252 | ++ break; | ||
| 253 | ++ } | ||
| 254 | ++ } else if (argconfig_parse_seen(opts, "sel")) | ||
| 255 | ++ err = get_dssd_power_state(dev, nsid, fid, cfg.sel, | ||
| 256 | ++ !argconfig_parse_seen(opts, "no-uuid")); | ||
| 257 | ++ else | ||
| 258 | ++ nvme_show_error("Required to have --sel as an argument, or pass the --all flag."); | ||
| 259 | ++ | ||
| 260 | ++ dev_close(dev); | ||
| 261 | ++ | ||
| 262 | ++ return err; | ||
| 263 | ++} | ||
| 264 | ++ | ||
| 265 | + /////////////////////////////////////////////////////////////////////////////// | ||
| 266 | + /////////////////////////////////////////////////////////////////////////////// | ||
| 267 | + /////////////////////////////////////////////////////////////////////////////// | ||
| 268 | +diff --git a/plugins/ocp/ocp-nvme.h b/plugins/ocp/ocp-nvme.h | ||
| 269 | +index 95539b0..4167b7b 100644 | ||
| 270 | +--- a/plugins/ocp/ocp-nvme.h | ||
| 271 | ++++ b/plugins/ocp/ocp-nvme.h | ||
| 272 | +@@ -26,7 +26,8 @@ PLUGIN(NAME("ocp", "OCP cloud SSD extensions", NVME_VERSION), | ||
| 273 | + ENTRY("unsupported-reqs-log", "Get Unsupported Requirements Log Page", ocp_unsupported_requirements_log) | ||
| 274 | + ENTRY("error-recovery-log", "Retrieve Error Recovery Log Page", ocp_error_recovery_log) | ||
| 275 | + ENTRY("device-capability-log", "Get Device capabilities Requirements Log Page", ocp_device_capabilities_log) | ||
| 276 | +- ENTRY("set-dssd-power-state-feature", "Get Device capabilities Requirements Log Page", set_dssd_power_state_feature) | ||
| 277 | ++ ENTRY("set-dssd-power-state-feature", "Set DSSD Power State feature", set_dssd_power_state_feature) | ||
| 278 | ++ ENTRY("get-dssd-power-state-feature", "Get DSSD Power State feature", get_dssd_power_state_feature) | ||
| 279 | + ENTRY("set-plp-health-check-interval", "Set PLP Health Check Interval", set_plp_health_check_interval) | ||
| 280 | + ENTRY("get-plp-health-check-interval", "Get PLP Health Check Interval", get_plp_health_check_interval) | ||
| 281 | + ENTRY("telemetry-string-log", "Retrieve Telemetry string Log Page", ocp_telemetry_str_log_format) | ||
| 282 | +-- | ||
| 283 | +2.43.0 | ||
| 284 | + | ||
| @@ -1,6 +1,6 @@ | |||
| 1 | Name: nvme-cli | 1 | Name: nvme-cli |
| 2 | Version: 2.8 | 2 | Version: 2.8 |
| 3 | -Release: 3 | 3 | +Release: 4 |
| 4 | Summary: NVMe management command line interface | 4 | Summary: NVMe management command line interface |
| 5 | 5 | ||
| 6 | License: GPLv2+ | 6 | License: GPLv2+ |
| @@ -10,6 +10,9 @@ Source0: https://github.com/linux-nvme/%{name}/archive/v%{version}.tar.gz | |||
| 10 | Patch0001: 0001-nvme-Don-t-seg-fault-if-given-device-is-not-char-block-device.patch | 10 | Patch0001: 0001-nvme-Don-t-seg-fault-if-given-device-is-not-char-block-device.patch |
| 11 | Patch0002: 0002-fabrics-do-not-report-error-when-no-modules-are-load.patch | 11 | Patch0002: 0002-fabrics-do-not-report-error-when-no-modules-are-load.patch |
| 12 | Patch0003: 0003-nvme-do-not-report-error-when-nvme_core-module-is-no.patch | 12 | Patch0003: 0003-nvme-do-not-report-error-when-nvme_core-module-is-no.patch |
| 13 | +Patch0004: 0004-ocp-fix-for-power-state-argument-checking.patch | ||
| 14 | +Patch0005: 0005-ocp-Add-Get-DSSD-Power-State-Feature-FID-C7h.patch | ||
| 15 | +Patch0006: 0006-doc-generate-nvme-ocp-get-set-dssd-power-state-featu.patch | ||
| 13 | 16 | ||
| 14 | Requires: libnvme | 17 | Requires: libnvme |
| 15 | 18 | ||
| @@ -64,6 +67,9 @@ rm -f %{buildroot}/usr/lib/dracut/dracut.conf.d/70-nvmf-autoconnect.conf | |||
| 64 | %{_mandir}/man1/nvme*.gz | 67 | %{_mandir}/man1/nvme*.gz |
| 65 | 68 | ||
| 66 | %changelog | 69 | %changelog |
| 70 | +* Tue Sep 1 2026 kouwenqi <kouwenqi@kylinos.cn> - 2.8-4 | ||
| 71 | +- ocp: Add Get DSSD Power State Feature (FID: C7h) | ||
| 72 | + | ||
| 67 | * Mon Jun 1 2026 kouwenqi <kouwenqi@kylinos.cn> - 2.8-3 | 73 | * Mon Jun 1 2026 kouwenqi <kouwenqi@kylinos.cn> - 2.8-3 |
| 68 | - do not report error when nvme_core module is not loaded | 74 | - do not report error when nvme_core module is not loaded |
| 69 | 75 | ||