Skip to content

Commit bee791f

Browse files
ikegami-tigaw
authored andcommitted
feat: add volatile-wc command
This is for Volatile Write Cache feature to get and set. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent aedf4e0 commit bee791f

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

plugins/feat/feat-nvme.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static const char *hctm_feat = "host controlled thermal management feature";
4747
static const char *timestamp_feat = "timestamp feature";
4848
static const char *temp_thresh_feat = "temperature threshold feature";
4949
static const char *arbitration_feat = "arbitration feature";
50+
static const char *volatile_wc_feat = "volatile write cache feature";
5051

5152
static int feat_get(struct nvme_dev *dev, const __u8 fid, __u32 cdw11, __u8 sel, const char *feat)
5253
{
@@ -560,3 +561,66 @@ static int feat_arbitration(int argc, char **argv, struct command *cmd, struct p
560561

561562
return arbitration_set(dev_fd(dev), fid, opts, &cfg);
562563
}
564+
565+
static int volatile_wc_set(struct nvme_dev *dev, const __u8 fid, bool wce, bool save)
566+
{
567+
__u32 result;
568+
int err;
569+
570+
struct nvme_set_features_args args = {
571+
.args_size = sizeof(args),
572+
.fd = dev_fd(dev),
573+
.fid = fid,
574+
.cdw11 = NVME_SET(wce, FEAT_VWC_WCE),
575+
.save = save,
576+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
577+
.result = &result,
578+
};
579+
580+
err = nvme_set_features(&args);
581+
582+
nvme_show_init();
583+
584+
if (err > 0) {
585+
nvme_show_status(err);
586+
} else if (err < 0) {
587+
nvme_show_perror("Set %s", volatile_wc_feat);
588+
} else {
589+
nvme_show_result("Set %s: 0x%04x (%s)", volatile_wc_feat, args.cdw11,
590+
save ? "Save" : "Not save");
591+
nvme_feature_show_fields(fid, args.cdw11, NULL);
592+
}
593+
594+
nvme_show_finish();
595+
596+
return err;
597+
}
598+
599+
static int feat_volatile_wc(int argc, char **argv, struct command *cmd, struct plugin *plugin)
600+
{
601+
const __u8 fid = NVME_FEAT_FID_VOLATILE_WC;
602+
const char *wce = "volatile write cache enable";
603+
604+
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
605+
int err;
606+
607+
struct config {
608+
bool wce;
609+
__u8 sel;
610+
};
611+
612+
struct config cfg = { 0 };
613+
614+
FEAT_ARGS(opts, OPT_FLAG("wce", 'w', &cfg.wce, wce));
615+
616+
err = parse_and_open(&dev, argc, argv, VOLATILE_WC_DESC, opts);
617+
if (err)
618+
return err;
619+
620+
if (argconfig_parse_seen(opts, "wce"))
621+
err = volatile_wc_set(dev, fid, cfg.wce, argconfig_parse_seen(opts, "save"));
622+
else
623+
err = feat_get(dev, fid, 0, cfg.sel, volatile_wc_feat);
624+
625+
return err;
626+
}

plugins/feat/feat-nvme.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define TIMESTAMP_DESC "Get and set timestamp feature"
1717
#define TEMP_THRESH_DESC "Get and set temperature threshold feature"
1818
#define ARBITRATION_DESC "Get and set arbitration feature"
19+
#define VOLATILE_WC_DESC "Get and set volatile write cache feature"
1920

2021
#define FEAT_ARGS(n, ...) \
2122
NVME_ARGS(n, ##__VA_ARGS__, OPT_FLAG("save", 's', NULL, save), \
@@ -29,6 +30,7 @@ PLUGIN(NAME("feat", "NVMe feature extensions", FEAT_PLUGIN_VERSION),
2930
ENTRY("timestamp", TIMESTAMP_DESC, feat_timestamp)
3031
ENTRY("temp-thresh", TEMP_THRESH_DESC, feat_temp_thresh)
3132
ENTRY("arbitration", ARBITRATION_DESC, feat_arbitration)
33+
ENTRY("volatile-wc", VOLATILE_WC_DESC, feat_volatile_wc)
3234
)
3335
);
3436
#endif /* !FEAT_NVME || CMD_HEADER_MULTI_READ */

0 commit comments

Comments
 (0)