ctld.c (279006) | ctld.c (279055) |
---|---|
1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: stable/10/usr.sbin/ctld/ctld.c 279006 2015-02-19 14:52:01Z mav $"); | 32__FBSDID("$FreeBSD: stable/10/usr.sbin/ctld/ctld.c 279055 2015-02-20 17:09:49Z mav $"); |
33 34#include <sys/types.h> 35#include <sys/time.h> 36#include <sys/socket.h> 37#include <sys/wait.h> 38#include <netinet/in.h> 39#include <arpa/inet.h> 40#include <assert.h> --- 47 unchanged lines hidden (view full) --- 88 conf = calloc(1, sizeof(*conf)); 89 if (conf == NULL) 90 log_err(1, "calloc"); 91 TAILQ_INIT(&conf->conf_luns); 92 TAILQ_INIT(&conf->conf_targets); 93 TAILQ_INIT(&conf->conf_auth_groups); 94 TAILQ_INIT(&conf->conf_ports); 95 TAILQ_INIT(&conf->conf_portal_groups); | 33 34#include <sys/types.h> 35#include <sys/time.h> 36#include <sys/socket.h> 37#include <sys/wait.h> 38#include <netinet/in.h> 39#include <arpa/inet.h> 40#include <assert.h> --- 47 unchanged lines hidden (view full) --- 88 conf = calloc(1, sizeof(*conf)); 89 if (conf == NULL) 90 log_err(1, "calloc"); 91 TAILQ_INIT(&conf->conf_luns); 92 TAILQ_INIT(&conf->conf_targets); 93 TAILQ_INIT(&conf->conf_auth_groups); 94 TAILQ_INIT(&conf->conf_ports); 95 TAILQ_INIT(&conf->conf_portal_groups); |
96 TAILQ_INIT(&conf->conf_pports); |
|
96 TAILQ_INIT(&conf->conf_isns); 97 98 conf->conf_isns_period = 900; 99 conf->conf_isns_timeout = 5; 100 conf->conf_debug = 0; 101 conf->conf_timeout = 60; 102 conf->conf_maxproc = 30; 103 104 return (conf); 105} 106 107void 108conf_delete(struct conf *conf) 109{ 110 struct lun *lun, *ltmp; 111 struct target *targ, *tmp; 112 struct auth_group *ag, *cagtmp; 113 struct portal_group *pg, *cpgtmp; | 97 TAILQ_INIT(&conf->conf_isns); 98 99 conf->conf_isns_period = 900; 100 conf->conf_isns_timeout = 5; 101 conf->conf_debug = 0; 102 conf->conf_timeout = 60; 103 conf->conf_maxproc = 30; 104 105 return (conf); 106} 107 108void 109conf_delete(struct conf *conf) 110{ 111 struct lun *lun, *ltmp; 112 struct target *targ, *tmp; 113 struct auth_group *ag, *cagtmp; 114 struct portal_group *pg, *cpgtmp; |
115 struct pport *pp, *pptmp; |
|
114 struct isns *is, *istmp; 115 116 assert(conf->conf_pidfh == NULL); 117 118 TAILQ_FOREACH_SAFE(lun, &conf->conf_luns, l_next, ltmp) 119 lun_delete(lun); 120 TAILQ_FOREACH_SAFE(targ, &conf->conf_targets, t_next, tmp) 121 target_delete(targ); 122 TAILQ_FOREACH_SAFE(ag, &conf->conf_auth_groups, ag_next, cagtmp) 123 auth_group_delete(ag); 124 TAILQ_FOREACH_SAFE(pg, &conf->conf_portal_groups, pg_next, cpgtmp) 125 portal_group_delete(pg); | 116 struct isns *is, *istmp; 117 118 assert(conf->conf_pidfh == NULL); 119 120 TAILQ_FOREACH_SAFE(lun, &conf->conf_luns, l_next, ltmp) 121 lun_delete(lun); 122 TAILQ_FOREACH_SAFE(targ, &conf->conf_targets, t_next, tmp) 123 target_delete(targ); 124 TAILQ_FOREACH_SAFE(ag, &conf->conf_auth_groups, ag_next, cagtmp) 125 auth_group_delete(ag); 126 TAILQ_FOREACH_SAFE(pg, &conf->conf_portal_groups, pg_next, cpgtmp) 127 portal_group_delete(pg); |
128 TAILQ_FOREACH_SAFE(pp, &conf->conf_pports, pp_next, pptmp) 129 pport_delete(pp); |
|
126 TAILQ_FOREACH_SAFE(is, &conf->conf_isns, i_next, istmp) 127 isns_delete(is); 128 assert(TAILQ_EMPTY(&conf->conf_ports)); 129 free(conf->conf_pidfile_path); 130 free(conf); 131} 132 133static struct auth * --- 994 unchanged lines hidden (view full) --- 1128 } else { 1129 log_warnx("invalid target name \"%s\"; should start with " 1130 "either \".iqn\", \"eui.\", or \"naa.\"", 1131 name); 1132 } 1133 return (true); 1134} 1135 | 130 TAILQ_FOREACH_SAFE(is, &conf->conf_isns, i_next, istmp) 131 isns_delete(is); 132 assert(TAILQ_EMPTY(&conf->conf_ports)); 133 free(conf->conf_pidfile_path); 134 free(conf); 135} 136 137static struct auth * --- 994 unchanged lines hidden (view full) --- 1132 } else { 1133 log_warnx("invalid target name \"%s\"; should start with " 1134 "either \".iqn\", \"eui.\", or \"naa.\"", 1135 name); 1136 } 1137 return (true); 1138} 1139 |
1140struct pport * 1141pport_new(struct conf *conf, const char *name, uint32_t ctl_port) 1142{ 1143 struct pport *pp; 1144 1145 pp = calloc(1, sizeof(*pp)); 1146 if (pp == NULL) 1147 log_err(1, "calloc"); 1148 pp->pp_conf = conf; 1149 pp->pp_name = checked_strdup(name); 1150 pp->pp_ctl_port = ctl_port; 1151 TAILQ_INIT(&pp->pp_ports); 1152 TAILQ_INSERT_TAIL(&conf->conf_pports, pp, pp_next); 1153 return (pp); 1154} 1155 1156struct pport * 1157pport_find(const struct conf *conf, const char *name) 1158{ 1159 struct pport *pp; 1160 1161 TAILQ_FOREACH(pp, &conf->conf_pports, pp_next) { 1162 if (strcasecmp(pp->pp_name, name) == 0) 1163 return (pp); 1164 } 1165 return (NULL); 1166} 1167 1168struct pport * 1169pport_copy(struct pport *pp, struct conf *conf) 1170{ 1171 struct pport *ppnew; 1172 1173 ppnew = pport_new(conf, pp->pp_name, pp->pp_ctl_port); 1174 return (ppnew); 1175} 1176 1177void 1178pport_delete(struct pport *pp) 1179{ 1180 struct port *port, *tport; 1181 1182 TAILQ_FOREACH_SAFE(port, &pp->pp_ports, p_ts, tport) 1183 port_delete(port); 1184 TAILQ_REMOVE(&pp->pp_conf->conf_pports, pp, pp_next); 1185 free(pp->pp_name); 1186 free(pp); 1187} 1188 |
|
1136struct port * 1137port_new(struct conf *conf, struct target *target, struct portal_group *pg) 1138{ 1139 struct port *port; | 1189struct port * 1190port_new(struct conf *conf, struct target *target, struct portal_group *pg) 1191{ 1192 struct port *port; |
1193 char *name; |
|
1140 | 1194 |
1195 asprintf(&name, "%s-%s", pg->pg_name, target->t_name); 1196 if (port_find(conf, name) != NULL) { 1197 log_warnx("duplicate port \"%s\"", name); 1198 free(name); 1199 return (NULL); 1200 } |
|
1141 port = calloc(1, sizeof(*port)); 1142 if (port == NULL) 1143 log_err(1, "calloc"); | 1201 port = calloc(1, sizeof(*port)); 1202 if (port == NULL) 1203 log_err(1, "calloc"); |
1144 asprintf(&port->p_name, "%s-%s", pg->pg_name, target->t_name); 1145 if (port_find(conf, port->p_name) != NULL) { 1146 log_warnx("duplicate port \"%s\"", port->p_name); 1147 free(port); 1148 return (NULL); 1149 } | |
1150 port->p_conf = conf; | 1204 port->p_conf = conf; |
1205 port->p_name = name; |
|
1151 TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next); 1152 TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts); 1153 port->p_target = target; 1154 TAILQ_INSERT_TAIL(&pg->pg_ports, port, p_pgs); 1155 port->p_portal_group = pg; 1156 return (port); 1157} 1158 1159struct port * | 1206 TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next); 1207 TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts); 1208 port->p_target = target; 1209 TAILQ_INSERT_TAIL(&pg->pg_ports, port, p_pgs); 1210 port->p_portal_group = pg; 1211 return (port); 1212} 1213 1214struct port * |
1215port_new_pp(struct conf *conf, struct target *target, struct pport *pp) 1216{ 1217 struct port *port; 1218 char *name; 1219 1220 asprintf(&name, "%s-%s", pp->pp_name, target->t_name); 1221 if (port_find(conf, name) != NULL) { 1222 log_warnx("duplicate port \"%s\"", name); 1223 free(name); 1224 return (NULL); 1225 } 1226 port = calloc(1, sizeof(*port)); 1227 if (port == NULL) 1228 log_err(1, "calloc"); 1229 port->p_conf = conf; 1230 port->p_name = name; 1231 TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next); 1232 TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts); 1233 port->p_target = target; 1234 TAILQ_INSERT_TAIL(&pp->pp_ports, port, p_pps); 1235 port->p_pport = pp; 1236 return (port); 1237} 1238 1239struct port * |
|
1160port_find(const struct conf *conf, const char *name) 1161{ 1162 struct port *port; 1163 1164 TAILQ_FOREACH(port, &conf->conf_ports, p_next) { 1165 if (strcasecmp(port->p_name, name) == 0) 1166 return (port); 1167 } --- 15 unchanged lines hidden (view full) --- 1183} 1184 1185void 1186port_delete(struct port *port) 1187{ 1188 1189 if (port->p_portal_group) 1190 TAILQ_REMOVE(&port->p_portal_group->pg_ports, port, p_pgs); | 1240port_find(const struct conf *conf, const char *name) 1241{ 1242 struct port *port; 1243 1244 TAILQ_FOREACH(port, &conf->conf_ports, p_next) { 1245 if (strcasecmp(port->p_name, name) == 0) 1246 return (port); 1247 } --- 15 unchanged lines hidden (view full) --- 1263} 1264 1265void 1266port_delete(struct port *port) 1267{ 1268 1269 if (port->p_portal_group) 1270 TAILQ_REMOVE(&port->p_portal_group->pg_ports, port, p_pgs); |
1271 if (port->p_pport) 1272 TAILQ_REMOVE(&port->p_pport->pp_ports, port, p_pps); |
|
1191 if (port->p_target) 1192 TAILQ_REMOVE(&port->p_target->t_ports, port, p_ts); 1193 TAILQ_REMOVE(&port->p_conf->conf_ports, port, p_next); 1194 free(port->p_name); 1195 free(port); 1196} 1197 1198struct target * --- 557 unchanged lines hidden (view full) --- 1756 /* 1757 * First, remove any ports present in the old configuration 1758 * and missing in the new one. 1759 */ 1760 TAILQ_FOREACH_SAFE(oldport, &oldconf->conf_ports, p_next, tmpport) { 1761 newport = port_find(newconf, oldport->p_name); 1762 if (newport != NULL) 1763 continue; | 1273 if (port->p_target) 1274 TAILQ_REMOVE(&port->p_target->t_ports, port, p_ts); 1275 TAILQ_REMOVE(&port->p_conf->conf_ports, port, p_next); 1276 free(port->p_name); 1277 free(port); 1278} 1279 1280struct target * --- 557 unchanged lines hidden (view full) --- 1838 /* 1839 * First, remove any ports present in the old configuration 1840 * and missing in the new one. 1841 */ 1842 TAILQ_FOREACH_SAFE(oldport, &oldconf->conf_ports, p_next, tmpport) { 1843 newport = port_find(newconf, oldport->p_name); 1844 if (newport != NULL) 1845 continue; |
1846 log_debugx("removing port \"%s\"", oldport->p_name); |
|
1764 error = kernel_port_remove(oldport); 1765 if (error != 0) { 1766 log_warnx("failed to remove port %s", 1767 oldport->p_name); 1768 /* 1769 * XXX: Uncomment after fixing the root cause. 1770 * 1771 * cumulated_error++; --- 108 unchanged lines hidden (view full) --- 1880 1881 /* 1882 * Now add new ports or modify existing ones. 1883 */ 1884 TAILQ_FOREACH(newport, &newconf->conf_ports, p_next) { 1885 oldport = port_find(oldconf, newport->p_name); 1886 1887 if (oldport == NULL) { | 1847 error = kernel_port_remove(oldport); 1848 if (error != 0) { 1849 log_warnx("failed to remove port %s", 1850 oldport->p_name); 1851 /* 1852 * XXX: Uncomment after fixing the root cause. 1853 * 1854 * cumulated_error++; --- 108 unchanged lines hidden (view full) --- 1963 1964 /* 1965 * Now add new ports or modify existing ones. 1966 */ 1967 TAILQ_FOREACH(newport, &newconf->conf_ports, p_next) { 1968 oldport = port_find(oldconf, newport->p_name); 1969 1970 if (oldport == NULL) { |
1971 log_debugx("adding port \"%s\"", newport->p_name); |
|
1888 error = kernel_port_add(newport); 1889 } else { | 1972 error = kernel_port_add(newport); 1973 } else { |
1974 log_debugx("updating port \"%s\"", newport->p_name); |
|
1890 newport->p_ctl_port = oldport->p_ctl_port; 1891 error = kernel_port_update(newport); 1892 } 1893 if (error != 0) { 1894 log_warnx("failed to %s port %s", 1895 (oldport == NULL) ? "add" : "update", 1896 newport->p_name); 1897 /* --- 495 unchanged lines hidden (view full) --- 2393 argc -= optind; 2394 if (argc != 0) 2395 usage(); 2396 2397 log_init(debug); 2398 kernel_init(); 2399 2400 oldconf = conf_new_from_kernel(); | 1975 newport->p_ctl_port = oldport->p_ctl_port; 1976 error = kernel_port_update(newport); 1977 } 1978 if (error != 0) { 1979 log_warnx("failed to %s port %s", 1980 (oldport == NULL) ? "add" : "update", 1981 newport->p_name); 1982 /* --- 495 unchanged lines hidden (view full) --- 2478 argc -= optind; 2479 if (argc != 0) 2480 usage(); 2481 2482 log_init(debug); 2483 kernel_init(); 2484 2485 oldconf = conf_new_from_kernel(); |
2401 newconf = conf_new_from_file(config_path); | 2486 newconf = conf_new_from_file(config_path, oldconf); |
2402 if (newconf == NULL) 2403 log_errx(1, "configuration error; exiting"); 2404 if (debug > 0) { 2405 oldconf->conf_debug = debug; 2406 newconf->conf_debug = debug; 2407 } 2408 2409 error = conf_apply(oldconf, newconf); --- 18 unchanged lines hidden (view full) --- 2428 if (!TAILQ_EMPTY(&newconf->conf_isns)) 2429 set_timeout((newconf->conf_isns_period + 2) / 3, false); 2430 2431 for (;;) { 2432 main_loop(newconf, dont_daemonize); 2433 if (sighup_received) { 2434 sighup_received = false; 2435 log_debugx("received SIGHUP, reloading configuration"); | 2487 if (newconf == NULL) 2488 log_errx(1, "configuration error; exiting"); 2489 if (debug > 0) { 2490 oldconf->conf_debug = debug; 2491 newconf->conf_debug = debug; 2492 } 2493 2494 error = conf_apply(oldconf, newconf); --- 18 unchanged lines hidden (view full) --- 2513 if (!TAILQ_EMPTY(&newconf->conf_isns)) 2514 set_timeout((newconf->conf_isns_period + 2) / 3, false); 2515 2516 for (;;) { 2517 main_loop(newconf, dont_daemonize); 2518 if (sighup_received) { 2519 sighup_received = false; 2520 log_debugx("received SIGHUP, reloading configuration"); |
2436 tmpconf = conf_new_from_file(config_path); | 2521 tmpconf = conf_new_from_file(config_path, newconf); |
2437 if (tmpconf == NULL) { 2438 log_warnx("configuration error, " 2439 "continuing with old configuration"); 2440 } else { 2441 if (debug > 0) 2442 tmpconf->conf_debug = debug; 2443 oldconf = newconf; 2444 newconf = tmpconf; --- 44 unchanged lines hidden --- | 2522 if (tmpconf == NULL) { 2523 log_warnx("configuration error, " 2524 "continuing with old configuration"); 2525 } else { 2526 if (debug > 0) 2527 tmpconf->conf_debug = debug; 2528 oldconf = newconf; 2529 newconf = tmpconf; --- 44 unchanged lines hidden --- |