From: Hannes Reinecke <hare@suse.de>
Date: Fri, 5 Apr 2024 14:31:25 +0000 (+0200)
Subject: ioctl: add nvme_set_features_host_behavior2()
X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=eff57ae736dc14a22229b9f50b68abd6001edc97;p=users%2Fsagi%2Flibnvme.git

ioctl: add nvme_set_features_host_behavior2()

All 'set features' commands have an 'result' field as the last
argument, so add an alternative function nvme_set_features_host_behavior2()
to follow the same calling convention.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---

diff --git a/src/libnvme.map b/src/libnvme.map
index b3c87201..c2a23e3a 100644
--- a/src/libnvme.map
+++ b/src/libnvme.map
@@ -11,6 +11,7 @@ LIBNVME_1.9 {
 		nvme_update_key;
 		nvme_ctrl_get_cntlid;
 		nvme_set_features_timestamp2;
+		nvme_set_features_host_behavior2;
 };
 
 LIBNVME_1_8 {
diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c
index 726171e4..d54b367c 100644
--- a/src/nvme/ioctl.c
+++ b/src/nvme/ioctl.c
@@ -661,7 +661,19 @@ int nvme_set_features_lba_sts_interval(int fd, __u16 lsiri, __u16 lsipi,
 }
 
 int nvme_set_features_host_behavior(int fd, bool save,
-	struct nvme_feat_host_behavior *data)
+		struct nvme_feat_host_behavior *data)
+{
+	__u32 result = 0;
+	int err;
+
+	err = nvme_set_features_host_behavior2(fd, save, data, &result);
+	if (err && result)
+		err = result;
+	return err;
+}
+
+int nvme_set_features_host_behavior2(int fd, bool save,
+		struct nvme_feat_host_behavior *data, __u32 *result)
 {
 	struct nvme_set_features_args args = {
 		.args_size = sizeof(args),
@@ -676,7 +688,7 @@ int nvme_set_features_host_behavior(int fd, bool save,
 		.data_len = sizeof(*data),
 		.data = data,
 		.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
-		.result = NULL,
+		.result = result,
 	};
 
 	return nvme_set_features(&args);
diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h
index d9987f6b..a952a761 100644
--- a/src/nvme/ioctl.h
+++ b/src/nvme/ioctl.h
@@ -2833,10 +2833,24 @@ int nvme_set_features_lba_sts_interval(int fd, __u16 lsiri, __u16 lsipi,
  * @save:	Save value across power states
  * @data:	Pointer to structure nvme_feat_host_behavior
  *
- * Return: 0 if the ioctl was successful or -1 with errno set otherwise.
+ * Return: The nvme command status if a response was received (see
+ * &enum nvme_status_field) or -1 with errno set otherwise.
  */
 int nvme_set_features_host_behavior(int fd, bool save,
-				    struct nvme_feat_host_behavior *data);
+			struct nvme_feat_host_behavior *data);
+
+/**
+ * nvme_set_features_host_behavior2() - Set host behavior feature
+ * @fd:		File descriptor of nvme device
+ * @save:	Save value across power states
+ * @data:	Pointer to structure nvme_feat_host_behavior
+ * @result:	The command completion result from CQE dword0
+ *
+ * Return: 0 if the ioctl was successful, -1 with errno set to EPROTO when
+ * a non-zero state is returned in @result, or -1 with errno set otherwise.
+ */
+int nvme_set_features_host_behavior2(int fd, bool save,
+			struct nvme_feat_host_behavior *data, __u32 *result);
 
 /**
  * nvme_set_features_sanitize() - Set sanitize feature
@@ -2847,7 +2861,6 @@ int nvme_set_features_host_behavior(int fd, bool save,
  *
  * Return: 0 if the ioctl was successful, -1 with errno set to EPROTO when
  * a non-zero state is returned in @result, or -1 with errno set otherwise.
- * Return: 0 if the ioctl was successful or -1 with errno set otherwise.
  */
 int nvme_set_features_sanitize(int fd, bool nodrm, bool save, __u32 *result);