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