File 0008-nvme-cli-minor-cleanup-for-submit_io.patch of Package nvme-cli.11833
From 239b44138378aaa33f474893767bd2566d36d3cf Mon Sep 17 00:00:00 2001
From: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Date: Mon, 28 Jan 2019 23:12:02 -0800
Subject: [PATCH] nvme-cli: minor cleanup for submit_io()
This is a cleanup patch which adds errno based error messages when
write() failure, this also fixes minor typo and removes unnecessary
braces.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
[fixed typo in changelog, minor style code change]
Signed-off-by: Keith Busch <keith.busch@intel.com>
---
nvme.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/nvme.c b/nvme.c
index 8922ec2..a6686dd 100644
--- a/nvme.c
+++ b/nvme.c
@@ -4245,7 +4245,7 @@ static int submit_io(int opcode, char *command, const char *desc,
dsmgmt |= ((__u32)cfg.dspec) << 16;
}
- if (strlen(cfg.data)){
+ if (strlen(cfg.data)) {
dfd = open(cfg.data, flags, mode);
if (dfd < 0) {
perror(cfg.data);
@@ -4254,7 +4254,7 @@ static int submit_io(int opcode, char *command, const char *desc,
}
mfd = dfd;
}
- if (strlen(cfg.metadata)){
+ if (strlen(cfg.metadata)) {
mfd = open(cfg.metadata, flags, mode);
if (mfd < 0) {
perror(cfg.metadata);
@@ -4347,11 +4347,13 @@ static int submit_io(int opcode, char *command, const char *desc,
printf("%s:%s(%04x)\n", command, nvme_status_to_string(err), err);
else {
if (!(opcode & 1) && write(dfd, (void *)buffer, cfg.data_size) < 0) {
- fprintf(stderr, "failed to write buffer to output file\n");
+ fprintf(stderr, "write: %s: failed to write buffer to output file\n",
+ strerror(errno));
err = EINVAL;
} else if (!(opcode & 1) && cfg.metadata_size &&
write(mfd, (void *)mbuffer, cfg.metadata_size) < 0) {
- fprintf(stderr, "failed to write meta-data buffer to output file\n");
+ fprintf(stderr, "write: %s: failed to write meta-data buffer to output file\n",
+ strerror(errno));
err = EINVAL;
} else
fprintf(stderr, "%s: Success\n", command);
--
2.13.7