Skip to content
8 changes: 4 additions & 4 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,7 @@ static int io_mgmt_recv(int argc, char **argv, struct command *acmd, struct plug
cfg.nsid);

if (cfg.file) {
dfd = open(cfg.file, O_WRONLY | O_CREAT, 0644);
dfd = open(cfg.file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (dfd < 0) {
nvme_show_perror(cfg.file);
return -errno;
Expand Down Expand Up @@ -8485,7 +8485,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
flags = O_RDONLY;
} else {
dfd = mfd = STDOUT_FILENO;
flags = O_WRONLY | O_CREAT;
flags = O_WRONLY | O_CREAT | O_TRUNC;
}

if (strlen(cfg.data)) {
Expand Down Expand Up @@ -9363,7 +9363,7 @@ static int passthru(int argc, char **argv, bool admin,

if (cfg.opcode & 0x02) {
cfg.read = true;
flags = O_WRONLY | O_CREAT;
flags = O_WRONLY | O_CREAT | O_TRUNC;
dfd = mfd = STDOUT_FILENO;
}

Expand Down Expand Up @@ -10483,7 +10483,7 @@ static int libnvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc
fd = STDIN_FILENO;
send = true;
} else {
flags = O_WRONLY | O_CREAT;
flags = O_WRONLY | O_CREAT | O_TRUNC;
fd = STDOUT_FILENO;
send = false;
}
Expand Down
98 changes: 98 additions & 0 deletions plugins/feat/feat-nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
__u8 sel;
};

struct host_behavior_config {
__u8 acre;
__u8 etdas;
__u8 lbafee;
__u8 hdisns;
__u16 cdfe;
__u8 sel;
};

static const char *power_mgmt_feat = "power management feature";
static const char *sel = "[0-3]: current/default/saved/supported";
static const char *save = "Specifies that the controller shall save the attribute";
Expand All @@ -61,6 +70,7 @@
static const char *power_meas_feat = "power measurement feature";
static const char *err_recovery_feat = "error recovery feature";
static const char *num_queues_feat = "number of queues feature";
static const char *host_behavior_feat = "host behavior support feature";

static int feat_get_nsid(struct libnvme_transport_handle *hdl, __u32 nsid,
const __u8 fid, __u32 cdw11, __u8 sel, __u8 uidx,
Expand Down Expand Up @@ -975,3 +985,91 @@

return err;
}

static int host_behavior_set(struct libnvme_transport_handle *hdl, __u8 fid,
struct argconfig_commandline_options *opts,
struct host_behavior_config *cfg, bool sv)
{
enum nvme_get_features_sel gsel = NVME_GET_FEATURES_SEL_CURRENT;
struct libnvme_passthru_cmd cmd;
struct nvme_feat_host_behavior data = { 0 };
int err;

if (sv)
gsel = NVME_GET_FEATURES_SEL_SAVED;

nvme_init_get_features_host_behavior(&cmd, gsel, &data);
err = libnvme_submit_admin_passthru(hdl, &cmd);
if (err) {
nvme_show_err(err, "Get %s", host_behavior_feat);
return err;
}

if (argconfig_parse_seen(opts, "acre"))
data.acre = cfg->acre;
if (argconfig_parse_seen(opts, "etdas"))
data.etdas = cfg->etdas;
if (argconfig_parse_seen(opts, "lbafee"))
data.lbafee = cfg->lbafee;
if (argconfig_parse_seen(opts, "hdisns"))
data.hdisns = cfg->hdisns;
if (argconfig_parse_seen(opts, "cdfe"))
data.cdfe = cpu_to_le16(cfg->cdfe);

nvme_init_set_features_host_behavior(&cmd, sv, &data);
err = libnvme_submit_admin_passthru(hdl, &cmd);
if (err) {
nvme_show_err(err, "Set %s", host_behavior_feat);
return err;
}

nvme_show_init();

nvme_show_result("Set %s: (%s)", host_behavior_feat,
sv ? "Save" : "Not save");
nvme_feature_show_fields(fid, 0, (unsigned char *)&data);

nvme_show_finish();

return err;
}

static int feat_host_behavior_support(int argc, char **argv, struct command *acmd,

Check failure on line 1037 in plugins/feat/feat-nvme.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 82 exceeds 80 columns
struct plugin *plugin)
{
const char *acre_desc = "Advanced Command Retry Enable (0 or 1)";
const char *etdas_desc = "Extended Telemetry Data Area 4 Supported (0 or 1)";

Check failure on line 1041 in plugins/feat/feat-nvme.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 85 exceeds 80 columns
const char *lbafee_desc = "LBA Format Extension Enable (0 or 1)";
const char *hdisns_desc = "Host Dispersed Namespace Support (0 or 1)";
const char *cdfe_desc = "Copy Descriptor Formats Enable bitmask";
const __u8 fid = NVME_FEAT_FID_HOST_BEHAVIOR;

__cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = NULL;
__cleanup_nvme_transport_handle struct libnvme_transport_handle *hdl = NULL;

Check failure on line 1048 in plugins/feat/feat-nvme.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Missing a blank line after declarations

Check failure on line 1048 in plugins/feat/feat-nvme.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 84 exceeds 80 columns
int err;

struct host_behavior_config cfg = { 0 };

FEAT_ARGS(opts,
OPT_BYTE("acre", 'a', &cfg.acre, acre_desc),
OPT_BYTE("etdas", 'e', &cfg.etdas, etdas_desc),
OPT_BYTE("lbafee", 'l', &cfg.lbafee, lbafee_desc),
OPT_BYTE("hdisns", 'H', &cfg.hdisns, hdisns_desc),
OPT_SHRT("cdfe", 'c', &cfg.cdfe, cdfe_desc));

err = parse_and_open(&ctx, &hdl, argc, argv, HOST_BEHAVIOR_DESC, opts);
if (err)
return err;

if (argconfig_parse_seen(opts, "acre") ||
argconfig_parse_seen(opts, "etdas") ||
argconfig_parse_seen(opts, "lbafee") ||
argconfig_parse_seen(opts, "hdisns") ||
argconfig_parse_seen(opts, "cdfe"))
err = host_behavior_set(hdl, fid, opts, &cfg,
argconfig_parse_seen(opts, "save"));
else
err = feat_get(hdl, fid, 0, cfg.sel, 0, host_behavior_feat);

return err;
}
2 changes: 2 additions & 0 deletions plugins/feat/feat-nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define POWER_MEAS_DESC "Get and set power measurement feature"
#define ERR_RECOVERY_DESC "Get and set error recovery feature"
#define NUM_QUEUES_DESC "Get and set number of queues feature"
#define HOST_BEHAVIOR_DESC "Get and set host behavior support feature"

#define FEAT_ARGS(n, ...) \
NVME_ARGS(n, ##__VA_ARGS__, OPT_FLAG("save", 's', NULL, save), \
Expand All @@ -41,6 +42,7 @@
ENTRY("power-meas", POWER_MEAS_DESC, feat_power_meas)
ENTRY("err-recovery", ERR_RECOVERY_DESC, feat_err_recovery)
ENTRY("num-queues", NUM_QUEUES_DESC, feat_num_queues)
ENTRY("host-behavior-support", HOST_BEHAVIOR_DESC, feat_host_behavior_support)

Check failure on line 45 in plugins/feat/feat-nvme.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 94 exceeds 80 columns
)
);
#endif /* !FEAT_NVME || CMD_HEADER_MULTI_READ */
Expand Down
13 changes: 12 additions & 1 deletion tests/nvme_compare_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,19 @@ def setUp(self):
super().setUp()
if not self.compare_cmd_supported():
self.skipTest("because: Optional NVM Command 'Compare' (NVMCMPS) not supported")
self.data_size = 1024
self.start_block = 1023
self.setup_log_dir(self.__class__.__name__)
self.compare_file = self.test_log_dir + "/" + "compare_file.txt"
self.write_file = self.test_log_dir + "/" + self.write_file
self.create_data_file(self.write_file, self.data_size, "15")
self.create_data_file(self.compare_file, self.data_size, "25")
self.compare_meta_file = None
if self.ms > 0 and not self.ns_meta_ext:
self.write_meta_file = self.test_log_dir + "/" + self.write_meta_file
self.compare_meta_file = \
self.test_log_dir + "/" + "compare_meta_file.bin"
self.create_meta_file(self.write_meta_file, self.ms)
self.create_meta_file(self.compare_meta_file, self.ms)

def tearDown(self):
""" Post Section for TestNVMeCompareCmd """
Expand All @@ -83,6 +89,11 @@ def nvme_compare(self, cmp_file):
f"--start-block={str(self.start_block)} " + \
f"--block-count={str(self.block_count)} " + \
f"--data-size={str(self.data_size)} --data={cmp_file}"
if self.prinfo:
compare_cmd += f" --prinfo={self.prinfo}"
if self.compare_meta_file:
compare_cmd += \
f" --metadata-size={self.ms} --metadata={self.compare_meta_file}"
return self.exec_cmd(compare_cmd)

def test_nvme_compare(self):
Expand Down
Loading
Loading