Draft
nvme: add --set-option key=value generic library configuration interface#32
Conversation
Implement the idea from linux-nvme#3530 to replace LIBNVME_* environment variable configuration with a generic --set-option key=value command-line interface. libnvme changes: - Add `force_4k`, `hostnqn` and `hostid` fields to struct libnvme_global_ctx - Read LIBNVME_FORCE_4K, LIBNVME_HOSTNQN and LIBNVME_HOSTID env vars into the global context at creation time (backward compat shim) - Add public setters: libnvme_set_force_4k(), libnvme_set_hostnqn(), libnvme_set_hostid() - Implement libnvme_set_probe_enabled() (was declared but not implemented) - Export the new symbols through the version linker script (libnvme.ld) - Remove the static `force_4k` global and __attribute__((constructor)) from nvme-cmds.c; use hdl->ctx->force_4k instead - In libnvmf_host_get_ids(), check ctx->hostnqn / ctx->hostid before falling back to libnvmf_read_hostnqn() / libnvmf_read_hostid() nvme-cli changes: - Add `const char *set_option` to struct nvme_args - Add --set-option KEY=VALUE to the NVME_ARGS global options group; supports comma-separated pairs (e.g. force_4k=1,hostnqn=nqn.xxx) - Supported keys: force_4k, mi_probe_enabled, hostnqn, hostid - Add nvme_create_global_ctx() wrapper in nvme.c that creates a context and applies any --set-option pairs; all call sites now use this wrapper - Replace libnvme_create_global_ctx() calls in nvme.c, fabrics.c, nvme-print-stdout-top.c and all plugins with nvme_create_global_ctx()
Copilot
AI
changed the title
nvme-cli: add --set-option key=value generic library option interface
nvme: add --set-option key=value generic library configuration interface
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several
LIBNVME_*environment variables control library behaviour but have no programmatic equivalent, forcing shell-level workarounds. This adds a generic--set-option key=valueglobal option that hooks these into the global context API.libnvme (submodule)
force_4k,hostnqn,hostidfields tostruct libnvme_global_ctx; readLIBNVME_FORCE_{4K,HOSTNQN,HOSTID}env vars into them at context creation for backward compatlibnvme_set_force_4k(),libnvme_set_hostnqn(),libnvme_set_hostid()setters; implementlibnvme_set_probe_enabled()(was declared but missing)nvme-cmds.c: remove process-widestatic bool force_4k+__attribute__((constructor)); usehdl->ctx->force_4kdirectlyfabrics.c/libnvmf_host_get_ids(): checkctx->hostnqn/hostidbefore the env-var/file fallbacknvme-cli
--set-option KEY=VALUEto globalNVME_ARGS; comma-separated pairs supportednvme_create_global_ctx()wrapper that creates a context and applies--set-optionpairs; replace alllibnvme_create_global_ctx()call sites throughout nvme.c, fabrics.c, nvme-print-stdout-top.c and all plugins# instead of: LIBNVME_FORCE_4K=1 LIBNVME_HOSTNQN=nqn.xxx nvme discover nvme --set-option force_4k=1,hostnqn=nqn.xxx discoverSupported keys:
force_4k,mi_probe_enabled,hostnqn,hostid. Boolean keys accept1/true/enableand0/false/disable. Environment variables still work unchanged.