Blame SOURCES/0002-idbm_rec_write-seperate-old-and-new-style-writes.patch

62f653
From b9d89091daab823eb2dc72c6c568af7897f83137 Mon Sep 17 00:00:00 2001
62f653
From: Chris Leech <cleech@redhat.com>
62f653
Date: Tue, 13 Aug 2013 11:34:31 -0700
62f653
Subject: [PATCH 02/32] idbm_rec_write, seperate old and new style writes
62f653
62f653
Duplicates a small bit of code, but easier to understand and extened.
62f653
---
62f653
 usr/idbm.c | 116 +++++++++++++++++++++++++++++++++++++++++--------------------
62f653
 1 file changed, 79 insertions(+), 37 deletions(-)
62f653
62f653
diff --git a/usr/idbm.c b/usr/idbm.c
62f653
index ab3577878e86..21ff61ab2bd8 100644
62f653
--- a/usr/idbm.c
62f653
+++ b/usr/idbm.c
62f653
@@ -2001,7 +2001,7 @@ mkdir_portal:
62f653
 	return f;
62f653
 }
62f653
 
62f653
-static int idbm_rec_write(node_rec_t *rec)
62f653
+static int idbm_rec_write_new(node_rec_t *rec)
62f653
 {
62f653
 	struct stat statb;
62f653
 	FILE *f;
62f653
@@ -2013,38 +2013,8 @@ static int idbm_rec_write(node_rec_t *rec)
62f653
 		log_error("Could not alloc portal");
62f653
 		return ISCSI_ERR_NOMEM;
62f653
 	}
62f653
-
62f653
-	snprintf(portal, PATH_MAX, "%s", NODE_CONFIG_DIR);
62f653
-	if (access(portal, F_OK) != 0) {
62f653
-		if (mkdir(portal, 0660) != 0) {
62f653
-			log_error("Could not make %s: %s", portal,
62f653
-				  strerror(errno));
62f653
-			rc = ISCSI_ERR_IDBM;
62f653
-			goto free_portal;
62f653
-		}
62f653
-	}
62f653
-
62f653
-	snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, rec->name);
62f653
-	if (access(portal, F_OK) != 0) {
62f653
-		if (mkdir(portal, 0660) != 0) {
62f653
-			log_error("Could not make %s: %s", portal,
62f653
-				  strerror(errno));
62f653
-			rc = ISCSI_ERR_IDBM;
62f653
-			goto free_portal;
62f653
-		}
62f653
-	}
62f653
-
62f653
 	snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
62f653
 		 rec->name, rec->conn[0].address, rec->conn[0].port);
62f653
-	log_debug(5, "Looking for config file %s", portal);
62f653
-
62f653
-	rc = idbm_lock();
62f653
-	if (rc)
62f653
-		goto free_portal;
62f653
-
62f653
-	if (rec->tpgt == PORTAL_GROUP_TAG_UNKNOWN)
62f653
-		/* drop down to old style portal as config */
62f653
-		goto open_conf;
62f653
 
62f653
 	rc = stat(portal, &statb);
62f653
 	if (rc) {
62f653
@@ -2065,11 +2035,11 @@ static int idbm_rec_write(node_rec_t *rec)
62f653
 			log_error("Could not convert %s: %s", portal,
62f653
 				  strerror(errno));
62f653
 			rc = ISCSI_ERR_IDBM;
62f653
-			goto unlock;
62f653
+			goto free_portal;
62f653
 		}
62f653
 	} else {
62f653
 		rc = ISCSI_ERR_INVAL;
62f653
-		goto unlock;
62f653
+		goto free_portal;
62f653
 	}
62f653
 
62f653
 mkdir_portal:
62f653
@@ -2080,24 +2050,96 @@ mkdir_portal:
62f653
 			log_error("Could not make dir %s: %s",
62f653
 				  portal, strerror(errno));
62f653
 			rc = ISCSI_ERR_IDBM;
62f653
-			goto unlock;
62f653
+			goto free_portal;
62f653
 		}
62f653
 	}
62f653
 
62f653
 	snprintf(portal, PATH_MAX, "%s/%s/%s,%d,%d/%s", NODE_CONFIG_DIR,
62f653
 		 rec->name, rec->conn[0].address, rec->conn[0].port, rec->tpgt,
62f653
 		 rec->iface.name);
62f653
-open_conf:
62f653
+/* open_conf: */
62f653
 	f = fopen(portal, "w");
62f653
 	if (!f) {
62f653
 		log_error("Could not open %s: %s", portal, strerror(errno));
62f653
 		rc = ISCSI_ERR_IDBM;
62f653
-		goto unlock;
62f653
+		goto free_portal;
62f653
 	}
62f653
 
62f653
 	idbm_print(IDBM_PRINT_TYPE_NODE, rec, 1, f);
62f653
 	fclose(f);
62f653
-unlock:
62f653
+free_portal:
62f653
+	free(portal);
62f653
+	return rc;
62f653
+}
62f653
+
62f653
+static int idbm_rec_write_old(node_rec_t *rec)
62f653
+{
62f653
+	FILE *f;
62f653
+	char *portal;
62f653
+	int rc = 0;
62f653
+
62f653
+	portal = malloc(PATH_MAX);
62f653
+	if (!portal) {
62f653
+		log_error("Could not alloc portal");
62f653
+		return ISCSI_ERR_NOMEM;
62f653
+	}
62f653
+	snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
62f653
+		 rec->name, rec->conn[0].address, rec->conn[0].port);
62f653
+
62f653
+	f = fopen(portal, "w");
62f653
+	if (!f) {
62f653
+		log_error("Could not open %s: %sd", portal, strerror(errno));
62f653
+		rc = ISCSI_ERR_IDBM;
62f653
+		goto free_portal;
62f653
+	}
62f653
+	idbm_print(IDBM_PRINT_TYPE_NODE, rec, 1, f);
62f653
+	fclose(f);
62f653
+free_portal:
62f653
+	free(portal);
62f653
+	return rc;
62f653
+}
62f653
+
62f653
+static int idbm_rec_write(node_rec_t *rec)
62f653
+{
62f653
+	char *portal;
62f653
+	int rc = 0;
62f653
+
62f653
+	portal = malloc(PATH_MAX);
62f653
+	if (!portal) {
62f653
+		log_error("Could not alloc portal");
62f653
+		return ISCSI_ERR_NOMEM;
62f653
+	}
62f653
+
62f653
+	snprintf(portal, PATH_MAX, "%s", NODE_CONFIG_DIR);
62f653
+	if (access(portal, F_OK) != 0) {
62f653
+		if (mkdir(portal, 0660) != 0) {
62f653
+			log_error("Could not make %s: %s", portal,
62f653
+				  strerror(errno));
62f653
+			rc = ISCSI_ERR_IDBM;
62f653
+			goto free_portal;
62f653
+		}
62f653
+	}
62f653
+
62f653
+	snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, rec->name);
62f653
+	if (access(portal, F_OK) != 0) {
62f653
+		if (mkdir(portal, 0660) != 0) {
62f653
+			log_error("Could not make %s: %s", portal,
62f653
+				  strerror(errno));
62f653
+			rc = ISCSI_ERR_IDBM;
62f653
+			goto free_portal;
62f653
+		}
62f653
+	}
62f653
+
62f653
+	rc = idbm_lock();
62f653
+	if (rc)
62f653
+		goto free_portal;
62f653
+
62f653
+	if (rec->tpgt == PORTAL_GROUP_TAG_UNKNOWN)
62f653
+		/* old style portal as config */
62f653
+		rc = idbm_rec_write_old(rec);
62f653
+	else
62f653
+		rc = idbm_rec_write_new(rec);
62f653
+
62f653
 	idbm_unlock();
62f653
 free_portal:
62f653
 	free(portal);
62f653
-- 
62f653
2.14.4
62f653