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

6c64be
From 954a9492b5ed1de5907ad2a7d7cc0ae6215d8fac Mon Sep 17 00:00:00 2001
6c64be
From: Chris Leech <cleech@redhat.com>
6c64be
Date: Tue, 13 Aug 2013 11:34:31 -0700
6c64be
Subject: 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
6c64be
index 0a88699..cb6ffd1 100644
6c64be
--- a/usr/idbm.c
6c64be
+++ b/usr/idbm.c
6c64be
@@ -1808,7 +1808,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;
6c64be
@@ -1820,38 +1820,8 @@ static int idbm_rec_write(node_rec_t *rec)
6c64be
 		log_error("Could not alloc portal\n");
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) {
6c64be
-			log_error("Could not make %s: %s\n", 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) {
6c64be
-			log_error("Could not make %s: %s\n", 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) {
6c64be
@@ -1872,11 +1842,11 @@ static int idbm_rec_write(node_rec_t *rec)
6c64be
 			log_error("Could not convert %s: %s\n", 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:
6c64be
@@ -1887,24 +1857,96 @@ mkdir_portal:
6c64be
 			log_error("Could not make dir %s: %s\n",
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) {
6c64be
 		log_error("Could not open %s: %sd\n", 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) {
6c64be
+		log_error("Could not alloc portal\n");
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) {
6c64be
+		log_error("Could not open %s: %sd\n", 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) {
6c64be
+		log_error("Could not alloc portal\n");
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) {
6c64be
+			log_error("Could not make %s: %s\n", 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) {
6c64be
+			log_error("Could not make %s: %s\n", 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
-- 
6c64be
1.8.1.4
6c64be