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

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