Skip to content

Commit 4943cfe

Browse files
ikegami-tigaw
authored andcommitted
feat: add err-recovery command
This is for Error Recovery feature to get and set. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 40a3bbd commit 4943cfe

4 files changed

Lines changed: 92 additions & 4 deletions

File tree

nvme.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ static struct program nvme = {
187187
};
188188

189189
const char *uuid_index = "UUID index";
190+
const char *namespace_id_desired = "identifier of desired namespace";
190191

191192
static const char *app_tag = "app tag for end-to-end PI";
192193
static const char *app_tag_mask = "app tag mask for end-to-end PI";
@@ -214,7 +215,6 @@ static const char *lsp = "log specific field";
214215
static const char *mos = "management operation specific";
215216
static const char *mo = "management operation";
216217
static const char *namespace_desired = "desired namespace";
217-
static const char *namespace_id_desired = "identifier of desired namespace";
218218
static const char *namespace_id_optional = "optional namespace attached to controller";
219219
static const char *nssf = "NVMe Security Specific Field";
220220
static const char *only_char_dev = "Only character device is allowed";

nvme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static inline DEFINE_CLEANUP_FUNC(
120120
#define _cleanup_nvme_transport_handle_ __cleanup__(cleanup_nvme_transport_handle)
121121

122122
extern const char *uuid_index;
123+
extern const char *namespace_id_desired;
123124
extern struct nvme_args nvme_args;
124125

125126
int validate_output_format(const char *format, nvme_print_flags_t *flags);

plugins/feat/feat-nvme.c

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ struct arbitration_config {
4141
__u8 sel;
4242
};
4343

44+
struct err_recovery_config {
45+
__u8 tler;
46+
__u8 dulbe;
47+
__u8 sel;
48+
};
49+
4450
static const char *power_mgmt_feat = "power management feature";
4551
static const char *sel = "[0-3]: current/default/saved/supported";
4652
static const char *save = "Specifies that the controller shall save the attribute";
@@ -53,9 +59,11 @@ static const char *volatile_wc_feat = "volatile write cache feature";
5359
static const char *power_limit_feat = "power limit feature";
5460
static const char *power_thresh_feat = "power threshold feature";
5561
static const char *power_meas_feat = "power measurement feature";
62+
static const char *err_recovery_feat = "error recovery feature";
5663

57-
static int feat_get(struct nvme_transport_handle *hdl, const __u8 fid,
58-
__u32 cdw11, __u8 sel, __u8 uidx, const char *feat)
64+
static int feat_get_nsid(struct nvme_transport_handle *hdl, __u32 nsid,
65+
const __u8 fid, __u32 cdw11, __u8 sel, __u8 uidx,
66+
const char *feat)
5967
{
6068
__u64 result;
6169
int err;
@@ -72,7 +80,7 @@ static int feat_get(struct nvme_transport_handle *hdl, const __u8 fid,
7280
return -ENOMEM;
7381
}
7482

75-
err = nvme_get_features(hdl, 0, fid, sel, cdw11, uidx, buf, len,
83+
err = nvme_get_features(hdl, nsid, fid, sel, cdw11, uidx, buf, len,
7684
&result);
7785

7886
nvme_show_init();
@@ -94,6 +102,12 @@ static int feat_get(struct nvme_transport_handle *hdl, const __u8 fid,
94102
return err;
95103
}
96104

105+
static int feat_get(struct nvme_transport_handle *hdl, const __u8 fid,
106+
__u32 cdw11, __u8 sel, __u8 uidx, const char *feat)
107+
{
108+
return feat_get_nsid(hdl, 0, fid, cdw11, sel, uidx, feat);
109+
}
110+
97111
static int power_mgmt_set(struct nvme_transport_handle *hdl, const __u8 fid,
98112
__u8 ps, __u8 wh, bool sv)
99113
{
@@ -831,3 +845,74 @@ static int feat_power_meas(int argc, char **argv, struct command *cmd,
831845

832846
return err;
833847
}
848+
849+
static int err_recovery_set(struct nvme_transport_handle *hdl, const __u8 fid,
850+
__u32 nsid, __u16 tler, bool dulbe, bool sv)
851+
{
852+
__u32 cdw11 = NVME_SET(tler, FEAT_ERROR_RECOVERY_TLER) |
853+
NVME_SET(dulbe, FEAT_ERROR_RECOVERY_DULBE);
854+
__u64 result;
855+
int err;
856+
857+
err = nvme_set_features(hdl, nsid, fid, sv, cdw11, 0, 0, 0, 0, NULL, 0,
858+
&result);
859+
860+
nvme_show_init();
861+
862+
if (err > 0) {
863+
nvme_show_status(err);
864+
} else if (err < 0) {
865+
nvme_show_perror("Set %s", err_recovery_feat);
866+
} else {
867+
nvme_show_result("Set %s: 0x%04x (%s)", err_recovery_feat,
868+
cdw11, sv ? "Save" : "Not save");
869+
nvme_feature_show_fields(fid, cdw11, NULL);
870+
}
871+
872+
nvme_show_finish();
873+
874+
return err;
875+
}
876+
877+
static int feat_err_recovery(int argc, char **argv, struct command *acmd,
878+
struct plugin *plugin)
879+
{
880+
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl =
881+
NULL;
882+
_cleanup_nvme_global_ctx_ struct nvme_global_ctx *ctx = NULL;
883+
884+
const char *dulbe =
885+
"deallocated or unwritten logical block error enable";
886+
const char *tler = "time limited error recovery";
887+
const __u8 fid = NVME_FEAT_FID_ERR_RECOVERY;
888+
889+
int err;
890+
891+
struct config {
892+
__u32 nsid;
893+
__u16 tler;
894+
bool dulbe;
895+
__u8 sel;
896+
};
897+
898+
struct config cfg = { 0 };
899+
900+
FEAT_ARGS(opts,
901+
OPT_UINT("nsid", 'n', &cfg.nsid, namespace_id_desired),
902+
OPT_SHRT("tler", 't', &cfg.tler, tler),
903+
OPT_FLAG("dulbe", 'd', &cfg.dulbe, dulbe));
904+
905+
err = parse_and_open(&ctx, &hdl, argc, argv, ERR_RECOVERY_DESC, opts);
906+
if (err)
907+
return err;
908+
909+
if (argconfig_parse_seen(opts, "tler") ||
910+
argconfig_parse_seen(opts, "dulbe"))
911+
err = err_recovery_set(hdl, fid, cfg.nsid, cfg.tler, cfg.dulbe,
912+
argconfig_parse_seen(opts, "save"));
913+
else
914+
err = feat_get_nsid(hdl, cfg.nsid, fid, 0, cfg.sel, 0,
915+
err_recovery_feat);
916+
917+
return err;
918+
}

plugins/feat/feat-nvme.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define POWER_LIMIT_DESC "Get and set power limit feature"
2121
#define POWER_THRESH_DESC "Get and set power threshold feature"
2222
#define POWER_MEAS_DESC "Get and set power measurement feature"
23+
#define ERR_RECOVERY_DESC "Get and set error recovery feature"
2324

2425
#define FEAT_ARGS(n, ...) \
2526
NVME_ARGS(n, ##__VA_ARGS__, OPT_FLAG("save", 's', NULL, save), \
@@ -37,6 +38,7 @@ PLUGIN(NAME("feat", "NVMe feature extensions", FEAT_PLUGIN_VERSION),
3738
ENTRY("power-limit", POWER_LIMIT_DESC, feat_power_limit)
3839
ENTRY("power-thresh", POWER_THRESH_DESC, feat_power_thresh)
3940
ENTRY("power-meas", POWER_MEAS_DESC, feat_power_meas)
41+
ENTRY("err-recovery", ERR_RECOVERY_DESC, feat_err_recovery)
4042
)
4143
);
4244
#endif /* !FEAT_NVME || CMD_HEADER_MULTI_READ */

0 commit comments

Comments
 (0)