Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
steps:
- uses: actions/checkout@v5
- name: enable foreign arch
uses: dbhi/qus/action@main
uses: docker/setup-qemu-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand Down
76 changes: 27 additions & 49 deletions fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static const char *nvmf_concat = "enable secure concatenation";
static const char *nvmf_config_file = "Use specified JSON configuration file or 'none' to disable";
static const char *nvmf_context = "execution context identification string";

struct fabric_args {
struct nvmf_args {
const char *subsysnqn;
const char *transport;
const char *traddr;
Expand All @@ -111,7 +111,7 @@ struct fabric_args {
};

#define NVMF_ARGS(n, f, c, ...) \
struct argconfig_commandline_options n[] = { \
NVME_ARGS(n, \
OPT_STRING("transport", 't', "STR", &f.transport, nvmf_tport), \
OPT_STRING("nqn", 'n', "STR", &f.subsysnqn, nvmf_nqn), \
OPT_STRING("traddr", 'a', "STR", &f.traddr, nvmf_traddr), \
Expand Down Expand Up @@ -141,9 +141,9 @@ struct fabric_args {
OPT_FLAG("data-digest", 'G', &c.data_digest, nvmf_data_digest), \
OPT_FLAG("tls", 0, &c.tls, nvmf_tls), \
OPT_FLAG("concat", 0, &c.concat, nvmf_concat), \
__VA_ARGS__, \
OPT_END() \
}
##__VA_ARGS__ \
)


static void save_discovery_log(char *raw, struct nvmf_discovery_log *log)
{
Expand All @@ -169,7 +169,7 @@ static void save_discovery_log(char *raw, struct nvmf_discovery_log *log)
}

static int setup_common_context(struct nvmf_context *fctx,
struct fabric_args *fa);
struct nvmf_args *fa);

struct cb_fabrics_data {
struct nvme_fabrics_config *cfg;
Expand Down Expand Up @@ -272,7 +272,7 @@ static int cb_parser_next_line(struct nvmf_context *fctx, void *user_data)
{
struct cb_fabrics_data *cfd = user_data;
struct nvme_fabrics_config cfg;
struct fabric_args fa = {};
struct nvmf_args fa = {};
char *ptr, *p, line[4096];
int argc, ret = 0;
bool force = false;
Expand Down Expand Up @@ -317,7 +317,7 @@ static int cb_parser_next_line(struct nvmf_context *fctx, void *user_data)
}

static int setup_common_context(struct nvmf_context *fctx,
struct fabric_args *fa)
struct nvmf_args *fa)
{
int err;

Expand All @@ -344,7 +344,7 @@ static int setup_common_context(struct nvmf_context *fctx,
}

static int create_common_context(struct nvme_global_ctx *ctx,
bool persistent, struct fabric_args *fa,
bool persistent, struct nvmf_args *fa,
struct nvme_fabrics_config *cfg,
void *user_data, struct nvmf_context **fctxp)
{
Expand Down Expand Up @@ -390,7 +390,7 @@ static int create_common_context(struct nvme_global_ctx *ctx,

static int create_discovery_context(struct nvme_global_ctx *ctx,
bool persistent, const char *device,
struct fabric_args *fa,
struct nvmf_args *fa,
struct nvme_fabrics_config *cfg,
void *user_data, struct nvmf_context **fctxp)
{
Expand Down Expand Up @@ -476,11 +476,9 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
nvme_print_flags_t flags;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_free_ struct nvmf_context *fctx = NULL;
unsigned int verbose = 0;
int ret;
char *format = "normal";
struct nvme_fabrics_config cfg;
struct fabric_args fa = { .subsysnqn = NVME_DISC_SUBSYS_NAME };
struct nvmf_args fa = { .subsysnqn = NVME_DISC_SUBSYS_NAME };
char *device = NULL;
bool force = false;
bool json_config = false;
Expand All @@ -489,12 +487,10 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)

NVMF_ARGS(opts, fa, cfg,
OPT_STRING("device", 'd', "DEV", &device, "use existing discovery controller device"),
OPT_FMT("output-format", 'o', &format, output_format),
OPT_FILE("raw", 'r', &raw, "save raw output to file"),
OPT_FLAG("persistent", 'p', &persistent, "persistent discovery connection"),
OPT_FLAG("quiet", 0, &quiet, "suppress already connected errors"),
OPT_STRING("config", 'J', "FILE", &config_file, nvmf_config_file),
OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),
OPT_FLAG("dump-config", 'O', &dump_config, "Dump configuration file to stdout"),
OPT_FLAG("force", 0, &force, "Force persistent discovery controller creation"),
OPT_FLAG("nbft", 0, &nbft, "Only look at NBFT tables"),
Expand All @@ -508,7 +504,7 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
if (ret)
return ret;

ret = validate_output_format(format, &flags);
ret = validate_output_format(nvme_args.output_format, &flags);
if (ret < 0) {
nvme_show_error("Invalid output format");
return ret;
Expand All @@ -517,7 +513,7 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
if (!strcmp(config_file, "none"))
config_file = NULL;

log_level = map_log_level(verbose, quiet);
log_level = map_log_level(nvme_args.verbose, quiet);

ctx = nvme_create_global_ctx(stderr, log_level);
if (!ctx) {
Expand Down Expand Up @@ -590,21 +586,17 @@ int fabrics_connect(const char *desc, int argc, char **argv)
_cleanup_free_ char *hid = NULL;
char *config_file = NULL;
char *context = NULL;
unsigned int verbose = 0;
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
_cleanup_free_ struct nvmf_context *fctx = NULL;
_cleanup_nvme_ctrl_ nvme_ctrl_t c = NULL;
int ret;
nvme_print_flags_t flags;
struct nvme_fabrics_config cfg = { 0 };
struct fabric_args fa = { 0 };
char *format = "normal";
struct nvmf_args fa = { 0 };

NVMF_ARGS(opts, fa, cfg,
OPT_STRING("config", 'J', "FILE", &config_file, nvmf_config_file),
OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),
OPT_FLAG("dump-config", 'O', &dump_config, "Dump JSON configuration to stdout"),
OPT_FMT("output-format", 'o', &format, "Output format: normal|json"),
OPT_STRING("context", 0, "STR", &context, nvmf_context));

nvmf_default_config(&cfg);
Expand All @@ -613,7 +605,7 @@ int fabrics_connect(const char *desc, int argc, char **argv)
if (ret)
return ret;

ret = validate_output_format(format, &flags);
ret = validate_output_format(nvme_args.output_format, &flags);
if (ret < 0) {
nvme_show_error("Invalid output format");
return ret;
Expand Down Expand Up @@ -644,7 +636,7 @@ int fabrics_connect(const char *desc, int argc, char **argv)
}

do_connect:
log_level = map_log_level(verbose, quiet);
log_level = map_log_level(nvme_args.verbose, quiet);

ctx = nvme_create_global_ctx(stderr, log_level);
if (!ctx) {
Expand Down Expand Up @@ -746,17 +738,13 @@ int fabrics_disconnect(const char *desc, int argc, char **argv)
struct config {
char *nqn;
char *device;
unsigned int verbose;
};

struct config cfg = { 0 };

OPT_ARGS(opts) = {
NVME_ARGS(opts,
OPT_STRING("nqn", 'n', "NAME", &cfg.nqn, nvmf_nqn),
OPT_STRING("device", 'd', "DEV", &cfg.device, device),
OPT_INCR("verbose", 'v', &cfg.verbose, "Increase logging verbosity"),
OPT_END()
};
OPT_STRING("device", 'd', "DEV", &cfg.device, device));

ret = argconfig_parse(argc, argv, desc, opts);
if (ret)
Expand All @@ -773,7 +761,7 @@ int fabrics_disconnect(const char *desc, int argc, char **argv)
return -EINVAL;
}

log_level = map_log_level(cfg.verbose, false);
log_level = map_log_level(nvme_args.verbose, false);

ctx = nvme_create_global_ctx(stderr, log_level);
if (!ctx) {
Expand Down Expand Up @@ -834,22 +822,18 @@ int fabrics_disconnect_all(const char *desc, int argc, char **argv)

struct config {
char *transport;
unsigned int verbose;
};

struct config cfg = { 0 };

OPT_ARGS(opts) = {
OPT_STRING("transport", 'r', "STR", (char *)&cfg.transport, nvmf_tport),
OPT_INCR("verbose", 'v', &cfg.verbose, "Increase logging verbosity"),
OPT_END()
};
NVME_ARGS(opts,
OPT_STRING("transport", 'r', "STR", (char *)&cfg.transport, nvmf_tport));

ret = argconfig_parse(argc, argv, desc, opts);
if (ret)
return ret;

log_level = map_log_level(cfg.verbose, false);
log_level = map_log_level(nvme_args.verbose, false);

ctx = nvme_create_global_ctx(stderr, log_level);
if (!ctx) {
Expand Down Expand Up @@ -900,13 +884,11 @@ int fabrics_config(const char *desc, int argc, char **argv)
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
char *config_file = PATH_NVMF_CONFIG;
struct nvme_fabrics_config cfg;
struct fabric_args fa = { };
unsigned int verbose = 0;
struct nvmf_args fa = { };
int ret;

NVMF_ARGS(opts, fa, cfg,
OPT_STRING("config", 'J', "FILE", &config_file, nvmf_config_file),
OPT_INCR("verbose", 'v', &verbose, "Increase logging verbosity"),
OPT_FLAG("scan", 'R', &scan_tree, "Scan current NVMeoF topology"),
OPT_FLAG("modify", 'M', &modify_config, "Modify JSON configuration file"),
OPT_FLAG("dump", 'O', &dump_config, "Dump JSON configuration to stdout"),
Expand All @@ -921,7 +903,7 @@ int fabrics_config(const char *desc, int argc, char **argv)
if (!strcmp(config_file, "none"))
config_file = NULL;

log_level = map_log_level(verbose, quiet);
log_level = map_log_level(nvme_args.verbose, quiet);

ctx = nvme_create_global_ctx(stderr, log_level);
if (!ctx) {
Expand Down Expand Up @@ -1015,16 +997,12 @@ int fabrics_dim(const char *desc, int argc, char **argv)
char *nqn;
char *device;
char *tas;
unsigned int verbose;
} cfg = { 0 };

OPT_ARGS(opts) = {
NVME_ARGS(opts,
OPT_STRING("nqn", 'n', "NAME", &cfg.nqn, "Comma-separated list of DC nqn"),
OPT_STRING("device", 'd', "DEV", &cfg.device, "Comma-separated list of DC nvme device handle."),
OPT_STRING("task", 't', "TASK", &cfg.tas, "[register|deregister]"),
OPT_INCR("verbose", 'v', &cfg.verbose, "Increase logging verbosity"),
OPT_END()
};
OPT_STRING("task", 't', "TASK", &cfg.tas, "[register|deregister]"));

ret = argconfig_parse(argc, argv, desc, opts);
if (ret)
Expand Down Expand Up @@ -1052,7 +1030,7 @@ int fabrics_dim(const char *desc, int argc, char **argv)
return -EINVAL;
}

log_level = map_log_level(cfg.verbose, false);
log_level = map_log_level(nvme_args.verbose, false);

ctx = nvme_create_global_ctx(stderr, log_level);
if (!ctx) {
Expand Down
1 change: 1 addition & 0 deletions libnvme/src/libnvme.ld
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ LIBNVME_2_0 {
nvme_set_application;
nvme_set_dry_run;
nvme_set_etdas;
nvme_set_ioctl_probing;
nvme_set_keyring;
nvme_set_property;
nvme_set_root;
Expand Down
13 changes: 10 additions & 3 deletions libnvme/src/nvme/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable)
ctx->dry_run = enable;
}

void nvme_set_ioctl_probing(struct nvme_global_ctx *ctx, bool enable)
{
ctx->ioctl_probing = enable;
}

void nvme_transport_handle_set_submit_entry(struct nvme_transport_handle *hdl,
void *(*submit_entry)(struct nvme_transport_handle *hdl,
struct nvme_passthru_cmd *cmd))
Expand Down Expand Up @@ -108,9 +113,11 @@ static int __nvme_transport_handle_open_direct(struct nvme_transport_handle *hdl
return -EINVAL;
}

ret = ioctl(hdl->fd, NVME_IOCTL_ADMIN64_CMD, &dummy);
if (ret > 0)
hdl->ioctl64 = true;
if (hdl->ctx->ioctl_probing) {
ret = ioctl(hdl->fd, NVME_IOCTL_ADMIN64_CMD, &dummy);
if (ret > 0)
hdl->ioctl64 = true;
}

return 0;
}
Expand Down
12 changes: 12 additions & 0 deletions libnvme/src/nvme/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,4 +742,16 @@ int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx,
*/
void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable);

/**
* nvme_set_ioctl_probing() - Enable/disable 64-bit IOCTL probing
* @ctx: struct nvme_global_ctx object
* @enable: Enable/disable 64-bit IOCTL probing
*
* When IOCTL probing is enabled, a 64-bit IOCTL command is issued to
* figure out if the passthru interface supports it.
*
* IOCTL probing is enabled per default.
*/
void nvme_set_ioctl_probing(struct nvme_global_ctx *ctx, bool enable);

#endif /* _LIBNVME_LINUX_H */
1 change: 1 addition & 0 deletions libnvme/src/nvme/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ struct nvme_global_ctx {
struct list_head hosts;
struct nvme_log log;
bool mi_probe_enabled;
bool ioctl_probing;
bool create_only;
bool dry_run;
struct nvme_fabric_options *options;
Expand Down
4 changes: 3 additions & 1 deletion libnvme/src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level)
int fd;

ctx = calloc(1, sizeof(*ctx));
if (!ctx)
if (!ctx)
return NULL;

if (fp) {
Expand All @@ -353,6 +353,8 @@ struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level)
list_head_init(&ctx->hosts);
list_head_init(&ctx->endpoints);

ctx->ioctl_probing = true;

return ctx;
}

Expand Down
4 changes: 2 additions & 2 deletions logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static struct submit_data sb;
bool is_printable_at_level(int level)
{
return ((log_level >= level) &&
(strcmp(nvme_cfg.output_format, "normal") == 0));
(strcmp(nvme_args.output_format, "normal") == 0));
}

int map_log_level(int verbose, bool quiet)
Expand Down Expand Up @@ -132,7 +132,7 @@ void nvme_submit_exit(struct nvme_transport_handle *hdl,
bool nvme_decide_retry(struct nvme_transport_handle *hdl,
struct nvme_passthru_cmd *cmd, int err)
{
if (!nvme_cfg.no_retries)
if (!nvme_args.no_retries)
return false;

if (err != -EAGAIN ||
Expand Down
4 changes: 2 additions & 2 deletions nvme-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@

static bool verbose_mode(void)
{
return json_print_ops.flags & VERBOSE || nvme_cfg.output_format_ver == 2;
return json_print_ops.flags & VERBOSE || nvme_args.output_format_ver == 2;

Check failure on line 205 in nvme-print-json.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 82 exceeds 80 columns
}

static void json_id_iocs(struct nvme_id_iocs *iocs)
Expand Down Expand Up @@ -4893,7 +4893,7 @@
static void json_print_list_items(struct nvme_global_ctx *ctx)
{
if (json_print_ops.flags & VERBOSE) {
if (nvme_cfg.output_format_ver == 2)
if (nvme_args.output_format_ver == 2)
json_detail_list_v2(ctx);
else
json_detail_list(ctx);
Expand Down
2 changes: 1 addition & 1 deletion nvme-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define nvme_print(name, flags, ...) \
do { \
struct print_ops *ops = nvme_print_ops(flags); \
if (ops && ops->name && !nvme_cfg.dry_run) \
if (ops && ops->name && !nvme_args.dry_run) \
ops->name(__VA_ARGS__); \
} while (false)

Expand Down
Loading