Skip to content

Commit 7c070f4

Browse files
committed
nvme: nvme_set_features use nvme_passthru_cmd directly
Drop nvme_set_features_args entirely. Signed-off-by: Dennis Maisenbacher <dennis.maisenbacher@wdc.com>
1 parent aa1fc39 commit 7c070f4

File tree

15 files changed

+194
-620
lines changed

15 files changed

+194
-620
lines changed

nvme.c

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6630,11 +6630,11 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
66306630
"for each Feature are vendor-specific and may not be modified."
66316631
"Use get-feature to determine which Features are supported by"
66326632
"the controller and are saveable/changeable.";
6633-
const char *feature_id = "feature identifier (required)";
6633+
const char *fid = "feature identifier (required)";
66346634
const char *data = "optional file for feature data (default stdin)";
66356635
const char *value = "new value of feature (required)";
66366636
const char *cdw12 = "feature cdw12, if used";
6637-
const char *save = "specifies that the controller shall save the attribute";
6637+
const char *sv = "specifies that the controller shall save the attribute";
66386638

66396639
_cleanup_nvme_root_ nvme_root_t r = NULL;
66406640
_cleanup_nvme_link_ nvme_link_t l = NULL;
@@ -6645,35 +6645,35 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
66456645
nvme_print_flags_t flags;
66466646

66476647
struct config {
6648-
__u32 namespace_id;
6649-
__u8 feature_id;
6648+
__u32 nsid;
6649+
__u8 fid;
66506650
__u64 value;
66516651
__u32 cdw12;
6652-
__u8 uuid_index;
6652+
__u8 uidx;
66536653
__u32 data_len;
66546654
char *file;
6655-
bool save;
6655+
bool sv;
66566656
};
66576657

66586658
struct config cfg = {
6659-
.namespace_id = 0,
6660-
.feature_id = 0,
6659+
.nsid = 0,
6660+
.fid = 0,
66616661
.value = 0,
6662-
.uuid_index = 0,
6662+
.uidx = 0,
66636663
.data_len = 0,
66646664
.file = "",
6665-
.save = false,
6665+
.sv = false,
66666666
};
66676667

66686668
NVME_ARGS(opts,
6669-
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
6670-
OPT_BYTE("feature-id", 'f', &cfg.feature_id, feature_id, feature_name),
6671-
OPT_SUFFIX("value", 'V', &cfg.value, value),
6672-
OPT_UINT("cdw12", 'c', &cfg.cdw12, cdw12),
6673-
OPT_BYTE("uuid-index", 'U', &cfg.uuid_index, uuid_index_specify),
6674-
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len),
6675-
OPT_FILE("data", 'd', &cfg.file, data),
6676-
OPT_FLAG("save", 's', &cfg.save, save));
6669+
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_desired),
6670+
OPT_BYTE("feature-id", 'f', &cfg.fid, fid, feature_name),
6671+
OPT_SUFFIX("value", 'V', &cfg.value, value),
6672+
OPT_UINT("cdw12", 'c', &cfg.cdw12, cdw12),
6673+
OPT_BYTE("uuid-index", 'U', &cfg.uidx, uuid_index_specify),
6674+
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len),
6675+
OPT_FILE("data", 'd', &cfg.file, data),
6676+
OPT_FLAG("save", 's', &cfg.sv, sv));
66776677

66786678
err = parse_and_open(&r, &l, argc, argv, desc, opts);
66796679
if (err)
@@ -6686,28 +6686,28 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
66866686
}
66876687

66886688
if (!argconfig_parse_seen(opts, "namespace-id")) {
6689-
err = nvme_get_nsid(l, &cfg.namespace_id);
6689+
err = nvme_get_nsid(l, &cfg.nsid);
66906690
if (err < 0) {
66916691
if (err != -ENOTTY) {
66926692
nvme_show_error("get-namespace-id: %s", nvme_strerror(-err));
66936693
return err;
66946694
}
6695-
cfg.namespace_id = NVME_NSID_ALL;
6695+
cfg.nsid = NVME_NSID_ALL;
66966696
}
66976697
}
66986698

6699-
if (!cfg.feature_id) {
6699+
if (!cfg.fid) {
67006700
nvme_show_error("feature-id required param");
67016701
return -EINVAL;
67026702
}
67036703

6704-
if (cfg.uuid_index > 127) {
6705-
nvme_show_error("invalid uuid index param: %u", cfg.uuid_index);
6704+
if (cfg.uidx > 127) {
6705+
nvme_show_error("invalid uuid index param: %u", cfg.uidx);
67066706
return -1;
67076707
}
67086708

67096709
if (!cfg.data_len)
6710-
nvme_get_feature_length(cfg.feature_id, cfg.value,
6710+
nvme_get_feature_length(cfg.fid, cfg.value,
67116711
NVME_DATA_TFR_HOST_TO_CTRL,
67126712
&cfg.data_len);
67136713

@@ -6724,7 +6724,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
67246724
* should use the buffer method if the value exceeds this
67256725
* length.
67266726
*/
6727-
if (cfg.feature_id == NVME_FEAT_FID_TIMESTAMP &&
6727+
if (cfg.fid == NVME_FEAT_FID_TIMESTAMP &&
67286728
argconfig_parse_seen(opts, "value")) {
67296729
memcpy(buf, &cfg.value, NVME_FEAT_TIMESTAMP_DATA_SIZE);
67306730
} else {
@@ -6746,33 +6746,20 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
67466746
}
67476747
}
67486748

6749-
struct nvme_set_features_args args = {
6750-
.args_size = sizeof(args),
6751-
.fid = cfg.feature_id,
6752-
.nsid = cfg.namespace_id,
6753-
.cdw11 = cfg.value,
6754-
.cdw12 = cfg.cdw12,
6755-
.save = cfg.save,
6756-
.uuidx = cfg.uuid_index,
6757-
.cdw15 = 0,
6758-
.data_len = cfg.data_len,
6759-
.data = buf,
6760-
.timeout = nvme_cfg.timeout,
6761-
.result = &result,
6762-
};
6763-
err = nvme_set_features(l, &args);
6749+
err = nvme_set_features(l, cfg.nsid, cfg.fid, cfg.sv, cfg.value, cfg.cdw12,
6750+
0, 0, cfg.uidx, buf, cfg.data_len, &result);
67646751
if (err < 0) {
67656752
nvme_show_error("set-feature: %s", nvme_strerror(-err));
67666753
} else if (!err) {
67676754
printf("set-feature:%#0*x (%s), value:%#0*"PRIx64", cdw12:%#0*x, save:%#x\n",
6768-
cfg.feature_id ? 4 : 2, cfg.feature_id,
6769-
nvme_feature_to_string(cfg.feature_id),
6755+
cfg.fid ? 4 : 2, cfg.fid,
6756+
nvme_feature_to_string(cfg.fid),
67706757
cfg.value ? 10 : 8, (uint64_t)cfg.value,
6771-
cfg.cdw12 ? 10 : 8, cfg.cdw12, cfg.save);
6772-
if (cfg.feature_id == NVME_FEAT_FID_LBA_STS_INTERVAL)
6758+
cfg.cdw12 ? 10 : 8, cfg.cdw12, cfg.sv);
6759+
if (cfg.fid == NVME_FEAT_FID_LBA_STS_INTERVAL)
67736760
nvme_show_lba_status_info(result);
67746761
if (buf) {
6775-
if (cfg.feature_id == NVME_FEAT_FID_LBA_RANGE)
6762+
if (cfg.fid == NVME_FEAT_FID_LBA_RANGE)
67766763
nvme_show_lba_range((struct nvme_lba_range_type *)buf, result, 0);
67776764
else
67786765
d(buf, cfg.data_len, 16, 1);

plugins/fdp/fdp.c

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,11 @@ static int fdp_update(int argc, char **argv, struct command *cmd, struct plugin
430430
static int fdp_set_events(int argc, char **argv, struct command *cmd, struct plugin *plugin)
431431
{
432432
const char *desc = "Enable or disable FDP events";
433-
const char *namespace_id = "Namespace identifier";
433+
const char *nsid = "Namespace identifier";
434434
const char *enable = "Enable/disable event";
435435
const char *event_types = "Comma-separated list of event types";
436436
const char *ph = "Placement Handle";
437-
const char *save = "specifies that the controller shall save the attribute";
437+
const char *sv = "specifies that the controller shall save the attribute";
438438

439439
_cleanup_nvme_root_ nvme_root_t r = NULL;
440440
_cleanup_nvme_link_ nvme_link_t l = NULL;
@@ -444,23 +444,23 @@ static int fdp_set_events(int argc, char **argv, struct command *cmd, struct plu
444444
int nev;
445445

446446
struct config {
447-
__u32 namespace_id;
447+
__u32 nsid;
448448
__u16 ph;
449449
char *event_types;
450450
bool enable;
451-
bool save;
451+
bool sv;
452452
};
453453

454454
struct config cfg = {
455455
.enable = false,
456-
.save = false,
456+
.sv = false,
457457
};
458458

459459
OPT_ARGS(opts) = {
460-
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
460+
OPT_UINT("namespace-id", 'n', &cfg.nsid, nsid),
461461
OPT_SHRT("placement-handle", 'p', &cfg.ph, ph),
462462
OPT_FLAG("enable", 'e', &cfg.enable, enable),
463-
OPT_FLAG("save", 's', &cfg.save, save),
463+
OPT_FLAG("save", 's', &cfg.sv, sv),
464464
OPT_LIST("event-types", 't', &cfg.event_types, event_types),
465465
OPT_END()
466466
};
@@ -481,35 +481,24 @@ static int fdp_set_events(int argc, char **argv, struct command *cmd, struct plu
481481
return -EINVAL;
482482
}
483483

484-
if (!cfg.namespace_id) {
485-
err = nvme_get_nsid(l, &cfg.namespace_id);
484+
if (!cfg.nsid) {
485+
err = nvme_get_nsid(l, &cfg.nsid);
486486
if (err < 0) {
487487
if (errno != ENOTTY) {
488488
fprintf(stderr, "get-namespace-id: %s\n", nvme_strerror(errno));
489489
return err;
490490
}
491491

492-
cfg.namespace_id = NVME_NSID_ALL;
492+
cfg.nsid = NVME_NSID_ALL;
493493
}
494494
}
495495

496496
for (unsigned int i = 0; i < nev; i++)
497497
buf[i] = (__u8)evts[i];
498498

499-
struct nvme_set_features_args args = {
500-
.args_size = sizeof(args),
501-
.fid = NVME_FEAT_FID_FDP_EVENTS,
502-
.save = cfg.save,
503-
.nsid = cfg.namespace_id,
504-
.cdw11 = (nev << 16) | cfg.ph,
505-
.cdw12 = cfg.enable ? 0x1 : 0x0,
506-
.data_len = sizeof(buf),
507-
.data = buf,
508-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
509-
.result = NULL,
510-
};
511-
512-
err = nvme_set_features(l, &args);
499+
err = nvme_set_features(l, cfg.nsid, NVME_FEAT_FID_FDP_EVENTS,
500+
cfg.sv, (nev << 16) | cfg.ph, cfg.enable ? 0x1 : 0x0,
501+
0, 0, 0, buf, sizeof(buf), NULL);
513502
if (err) {
514503
nvme_show_status(err);
515504
return err;;
@@ -533,16 +522,6 @@ static int fdp_feature(int argc, char **argv, struct command *cmd, struct plugin
533522
__u32 result;
534523
int err = -1;
535524

536-
struct nvme_set_features_args setf_args = {
537-
.args_size = sizeof(setf_args),
538-
.fid = NVME_FEAT_FID_FDP,
539-
.save = 1,
540-
.nsid = NVME_NSID_ALL,
541-
.data_len = 0,
542-
.data = NULL,
543-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
544-
};
545-
546525
struct config {
547526
bool disable;
548527
__u8 fdpcidx;
@@ -602,10 +581,8 @@ static int fdp_feature(int argc, char **argv, struct command *cmd, struct plugin
602581
return err;
603582
}
604583

605-
setf_args.cdw11 = cfg.endgid;
606-
setf_args.cdw12 = cfg.fdpcidx << 8 | (!cfg.disable);
607-
608-
err = nvme_set_features(l, &setf_args);
584+
err = nvme_set_features(l, NVME_NSID_ALL, NVME_FEAT_FID_FDP, 1, cfg.endgid,
585+
cfg.fdpcidx << 8 | (!cfg.disable), 0, 0, 0, NULL, 0, NULL);
609586
if (err) {
610587
nvme_show_status(err);
611588
return err;

0 commit comments

Comments
 (0)