]> git.pld-linux.org Git - packages/open-iscsi.git/blame - 0045-idbm_rec_write-seperate-old-and-new-style-writes.patch
- fix paths to daemons in systemd service files
[packages/open-iscsi.git] / 0045-idbm_rec_write-seperate-old-and-new-style-writes.patch
CommitLineData
6ae08450
JR
1From 954a9492b5ed1de5907ad2a7d7cc0ae6215d8fac Mon Sep 17 00:00:00 2001
2From: Chris Leech <cleech@redhat.com>
3Date: Tue, 13 Aug 2013 11:34:31 -0700
4Subject: idbm_rec_write, seperate old and new style writes
5
6Duplicates a small bit of code, but easier to understand and extened.
7---
8 usr/idbm.c | 116 +++++++++++++++++++++++++++++++++++++++++--------------------
9 1 file changed, 79 insertions(+), 37 deletions(-)
10
11diff --git a/usr/idbm.c b/usr/idbm.c
12index 0a88699..cb6ffd1 100644
13--- a/usr/idbm.c
14+++ b/usr/idbm.c
15@@ -1808,7 +1808,7 @@ mkdir_portal:
16 return f;
17 }
18
19-static int idbm_rec_write(node_rec_t *rec)
20+static int idbm_rec_write_new(node_rec_t *rec)
21 {
22 struct stat statb;
23 FILE *f;
24@@ -1820,38 +1820,8 @@ static int idbm_rec_write(node_rec_t *rec)
25 log_error("Could not alloc portal\n");
26 return ISCSI_ERR_NOMEM;
27 }
28-
29- snprintf(portal, PATH_MAX, "%s", NODE_CONFIG_DIR);
30- if (access(portal, F_OK) != 0) {
31- if (mkdir(portal, 0660) != 0) {
32- log_error("Could not make %s: %s\n", portal,
33- strerror(errno));
34- rc = ISCSI_ERR_IDBM;
35- goto free_portal;
36- }
37- }
38-
39- snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, rec->name);
40- if (access(portal, F_OK) != 0) {
41- if (mkdir(portal, 0660) != 0) {
42- log_error("Could not make %s: %s\n", portal,
43- strerror(errno));
44- rc = ISCSI_ERR_IDBM;
45- goto free_portal;
46- }
47- }
48-
49 snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
50 rec->name, rec->conn[0].address, rec->conn[0].port);
51- log_debug(5, "Looking for config file %s", portal);
52-
53- rc = idbm_lock();
54- if (rc)
55- goto free_portal;
56-
57- if (rec->tpgt == PORTAL_GROUP_TAG_UNKNOWN)
58- /* drop down to old style portal as config */
59- goto open_conf;
60
61 rc = stat(portal, &statb);
62 if (rc) {
63@@ -1872,11 +1842,11 @@ static int idbm_rec_write(node_rec_t *rec)
64 log_error("Could not convert %s: %s\n", portal,
65 strerror(errno));
66 rc = ISCSI_ERR_IDBM;
67- goto unlock;
68+ goto free_portal;
69 }
70 } else {
71 rc = ISCSI_ERR_INVAL;
72- goto unlock;
73+ goto free_portal;
74 }
75
76 mkdir_portal:
77@@ -1887,24 +1857,96 @@ mkdir_portal:
78 log_error("Could not make dir %s: %s\n",
79 portal, strerror(errno));
80 rc = ISCSI_ERR_IDBM;
81- goto unlock;
82+ goto free_portal;
83 }
84 }
85
86 snprintf(portal, PATH_MAX, "%s/%s/%s,%d,%d/%s", NODE_CONFIG_DIR,
87 rec->name, rec->conn[0].address, rec->conn[0].port, rec->tpgt,
88 rec->iface.name);
89-open_conf:
90+/* open_conf: */
91 f = fopen(portal, "w");
92 if (!f) {
93 log_error("Could not open %s: %sd\n", portal, strerror(errno));
94 rc = ISCSI_ERR_IDBM;
95- goto unlock;
96+ goto free_portal;
97 }
98
99 idbm_print(IDBM_PRINT_TYPE_NODE, rec, 1, f);
100 fclose(f);
101-unlock:
102+free_portal:
103+ free(portal);
104+ return rc;
105+}
106+
107+static int idbm_rec_write_old(node_rec_t *rec)
108+{
109+ FILE *f;
110+ char *portal;
111+ int rc = 0;
112+
113+ portal = malloc(PATH_MAX);
114+ if (!portal) {
115+ log_error("Could not alloc portal\n");
116+ return ISCSI_ERR_NOMEM;
117+ }
118+ snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
119+ rec->name, rec->conn[0].address, rec->conn[0].port);
120+
121+ f = fopen(portal, "w");
122+ if (!f) {
123+ log_error("Could not open %s: %sd\n", portal, strerror(errno));
124+ rc = ISCSI_ERR_IDBM;
125+ goto free_portal;
126+ }
127+ idbm_print(IDBM_PRINT_TYPE_NODE, rec, 1, f);
128+ fclose(f);
129+free_portal:
130+ free(portal);
131+ return rc;
132+}
133+
134+static int idbm_rec_write(node_rec_t *rec)
135+{
136+ char *portal;
137+ int rc = 0;
138+
139+ portal = malloc(PATH_MAX);
140+ if (!portal) {
141+ log_error("Could not alloc portal\n");
142+ return ISCSI_ERR_NOMEM;
143+ }
144+
145+ snprintf(portal, PATH_MAX, "%s", NODE_CONFIG_DIR);
146+ if (access(portal, F_OK) != 0) {
147+ if (mkdir(portal, 0660) != 0) {
148+ log_error("Could not make %s: %s\n", portal,
149+ strerror(errno));
150+ rc = ISCSI_ERR_IDBM;
151+ goto free_portal;
152+ }
153+ }
154+
155+ snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, rec->name);
156+ if (access(portal, F_OK) != 0) {
157+ if (mkdir(portal, 0660) != 0) {
158+ log_error("Could not make %s: %s\n", portal,
159+ strerror(errno));
160+ rc = ISCSI_ERR_IDBM;
161+ goto free_portal;
162+ }
163+ }
164+
165+ rc = idbm_lock();
166+ if (rc)
167+ goto free_portal;
168+
169+ if (rec->tpgt == PORTAL_GROUP_TAG_UNKNOWN)
170+ /* old style portal as config */
171+ rc = idbm_rec_write_old(rec);
172+ else
173+ rc = idbm_rec_write_new(rec);
174+
175 idbm_unlock();
176 free_portal:
177 free(portal);
178--
1791.8.1.4
180
This page took 0.114962 seconds and 4 git commands to generate.