Skip to content

nvme: add --set-option key=value generic library configuration interface#32

Draft
igaw with Copilot wants to merge 2 commits into
masterfrom
copilot/implement-idea-document-3530
Draft

nvme: add --set-option key=value generic library configuration interface#32
igaw with Copilot wants to merge 2 commits into
masterfrom
copilot/implement-idea-document-3530

Conversation

Copilot AI commented Jul 9, 2026

Copy link
Copy Markdown

Several LIBNVME_* environment variables control library behaviour but have no programmatic equivalent, forcing shell-level workarounds. This adds a generic --set-option key=value global option that hooks these into the global context API.

libnvme (submodule)

  • Add force_4k, hostnqn, hostid fields to struct libnvme_global_ctx; read LIBNVME_FORCE_{4K,HOSTNQN,HOSTID} env vars into them at context creation for backward compat
  • Add and export libnvme_set_force_4k(), libnvme_set_hostnqn(), libnvme_set_hostid() setters; implement libnvme_set_probe_enabled() (was declared but missing)
  • nvme-cmds.c: remove process-wide static bool force_4k + __attribute__((constructor)); use hdl->ctx->force_4k directly
  • fabrics.c / libnvmf_host_get_ids(): check ctx->hostnqn/hostid before the env-var/file fallback

nvme-cli

  • Add --set-option KEY=VALUE to global NVME_ARGS; comma-separated pairs supported
  • Add nvme_create_global_ctx() wrapper that creates a context and applies --set-option pairs; replace all libnvme_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 discover

Supported keys: force_4k, mi_probe_enabled, hostnqn, hostid. Boolean keys accept 1/true/enable and 0/false/disable. Environment variables still work unchanged.

Copilot AI added 2 commits July 9, 2026 15:43
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 assigned Copilot and igaw Jul 9, 2026
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
Copilot finished work on behalf of igaw July 9, 2026 15:47
Copilot AI requested a review from igaw July 9, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants