[PATCH v2 nvme-cli 4/4] fabrics: Take the hostnqn parameter from a conf file if not given

Sagi Grimberg sagi at grimberg.me
Mon Aug 8 04:58:00 PDT 2016


In order to allow persistent hostnqns, take the hostnqn parameter
for /etc/nvme/hostnqn if exists.

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
 fabrics.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/fabrics.c b/fabrics.c
index 54ed8e17b527..90308f07d0fb 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -57,6 +57,7 @@ struct config {
 #define BUF_SIZE		4096
 #define PATH_NVME_FABRICS	"/dev/nvme-fabrics"
 #define PATH_NVMF_DISC		"/etc/nvme/nvmf_disc"
+#define PATH_NVMF_HOSTNQN	"/etc/nvme/hostnqn"
 #define MAX_DISC_ARGS		10
 
 enum {
@@ -405,6 +406,25 @@ static void save_discovery_log(struct nvmf_disc_rsp_page_hdr *log, int numrec)
 	close(fd);
 }
 
+static int nvmf_hostnqn_file(void)
+{
+	FILE *f;
+	char hostnqn[255];
+
+	f = fopen(PATH_NVMF_HOSTNQN, "r");
+	if (f == NULL)
+		return false;
+
+	if (fgets(hostnqn, sizeof(hostnqn), f) == NULL)
+		return false;
+
+	cfg.hostnqn = strdup(hostnqn);
+	if (!cfg.hostnqn)
+		return false;
+
+	return true;
+}
+
 static int build_options(char *argstr, int max_len)
 {
 	int len;
@@ -449,7 +469,7 @@ static int build_options(char *argstr, int max_len)
 		max_len -= len;
 	}
 
-	if (cfg.hostnqn) {
+	if (cfg.hostnqn || nvmf_hostnqn_file()) {
 		len = snprintf(argstr, max_len, ",hostnqn=%s", cfg.hostnqn);
 		if (len < 0)
 			return -EINVAL;
-- 
1.9.1




More information about the Linux-nvme mailing list