Deleted Added
full compact
ctld.c (263721) ctld.c (263723)
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

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
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 *
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

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
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 * $FreeBSD: stable/10/usr.sbin/ctld/ctld.c 263721 2014-03-25 12:06:42Z trasz $
29 * $FreeBSD: stable/10/usr.sbin/ctld/ctld.c 263723 2014-03-25 12:10:30Z trasz $
30 */
31
32#include <sys/types.h>
33#include <sys/time.h>
34#include <sys/socket.h>
35#include <sys/wait.h>
36#include <netinet/in.h>
37#include <assert.h>

--- 121 unchanged lines hidden (view full) ---

159 if (auth->a_auth_group->ag_name != NULL)
160 log_warnx("secret for user \"%s\", auth-group \"%s\", "
161 "is too long; it should be at most 16 characters "
162 "long", auth->a_user, auth->a_auth_group->ag_name);
163 else
164 log_warnx("secret for user \"%s\", target \"%s\", "
165 "is too long; it should be at most 16 characters "
166 "long", auth->a_user,
30 */
31
32#include <sys/types.h>
33#include <sys/time.h>
34#include <sys/socket.h>
35#include <sys/wait.h>
36#include <netinet/in.h>
37#include <assert.h>

--- 121 unchanged lines hidden (view full) ---

159 if (auth->a_auth_group->ag_name != NULL)
160 log_warnx("secret for user \"%s\", auth-group \"%s\", "
161 "is too long; it should be at most 16 characters "
162 "long", auth->a_user, auth->a_auth_group->ag_name);
163 else
164 log_warnx("secret for user \"%s\", target \"%s\", "
165 "is too long; it should be at most 16 characters "
166 "long", auth->a_user,
167 auth->a_auth_group->ag_target->t_iqn);
167 auth->a_auth_group->ag_target->t_name);
168 }
169 if (len < 12) {
170 if (auth->a_auth_group->ag_name != NULL)
171 log_warnx("secret for user \"%s\", auth-group \"%s\", "
172 "is too short; it should be at least 12 characters "
173 "long", auth->a_user,
174 auth->a_auth_group->ag_name);
175 else
176 log_warnx("secret for user \"%s\", target \"%s\", "
177 "is too short; it should be at least 16 characters "
178 "long", auth->a_user,
168 }
169 if (len < 12) {
170 if (auth->a_auth_group->ag_name != NULL)
171 log_warnx("secret for user \"%s\", auth-group \"%s\", "
172 "is too short; it should be at least 12 characters "
173 "long", auth->a_user,
174 auth->a_auth_group->ag_name);
175 else
176 log_warnx("secret for user \"%s\", target \"%s\", "
177 "is too short; it should be at least 16 characters "
178 "long", auth->a_user,
179 auth->a_auth_group->ag_target->t_iqn);
179 auth->a_auth_group->ag_target->t_name);
180 }
181
182 if (auth->a_mutual_secret != NULL) {
183 len = strlen(auth->a_secret);
184 if (len > 16) {
185 if (auth->a_auth_group->ag_name != NULL)
186 log_warnx("mutual secret for user \"%s\", "
187 "auth-group \"%s\", is too long; it should "
188 "be at most 16 characters long",
189 auth->a_user, auth->a_auth_group->ag_name);
190 else
191 log_warnx("mutual secret for user \"%s\", "
192 "target \"%s\", is too long; it should "
193 "be at most 16 characters long",
194 auth->a_user,
180 }
181
182 if (auth->a_mutual_secret != NULL) {
183 len = strlen(auth->a_secret);
184 if (len > 16) {
185 if (auth->a_auth_group->ag_name != NULL)
186 log_warnx("mutual secret for user \"%s\", "
187 "auth-group \"%s\", is too long; it should "
188 "be at most 16 characters long",
189 auth->a_user, auth->a_auth_group->ag_name);
190 else
191 log_warnx("mutual secret for user \"%s\", "
192 "target \"%s\", is too long; it should "
193 "be at most 16 characters long",
194 auth->a_user,
195 auth->a_auth_group->ag_target->t_iqn);
195 auth->a_auth_group->ag_target->t_name);
196 }
197 if (len < 12) {
198 if (auth->a_auth_group->ag_name != NULL)
199 log_warnx("mutual secret for user \"%s\", "
200 "auth-group \"%s\", is too short; it "
201 "should be at least 12 characters long",
202 auth->a_user, auth->a_auth_group->ag_name);
203 else
204 log_warnx("mutual secret for user \"%s\", "
205 "target \"%s\", is too short; it should be "
206 "at least 16 characters long",
207 auth->a_user,
196 }
197 if (len < 12) {
198 if (auth->a_auth_group->ag_name != NULL)
199 log_warnx("mutual secret for user \"%s\", "
200 "auth-group \"%s\", is too short; it "
201 "should be at least 12 characters long",
202 auth->a_user, auth->a_auth_group->ag_name);
203 else
204 log_warnx("mutual secret for user \"%s\", "
205 "target \"%s\", is too short; it should be "
206 "at least 16 characters long",
207 auth->a_user,
208 auth->a_auth_group->ag_target->t_iqn);
208 auth->a_auth_group->ag_target->t_name);
209 }
210 }
211}
212
213const struct auth *
214auth_new_chap(struct auth_group *ag, const char *user,
215 const char *secret)
216{
217 struct auth *auth;
218
219 if (ag->ag_type == AG_TYPE_UNKNOWN)
220 ag->ag_type = AG_TYPE_CHAP;
221 if (ag->ag_type != AG_TYPE_CHAP) {
222 if (ag->ag_name != NULL)
223 log_warnx("cannot mix \"chap\" authentication with "
224 "other types for auth-group \"%s\"", ag->ag_name);
225 else
226 log_warnx("cannot mix \"chap\" authentication with "
227 "other types for target \"%s\"",
209 }
210 }
211}
212
213const struct auth *
214auth_new_chap(struct auth_group *ag, const char *user,
215 const char *secret)
216{
217 struct auth *auth;
218
219 if (ag->ag_type == AG_TYPE_UNKNOWN)
220 ag->ag_type = AG_TYPE_CHAP;
221 if (ag->ag_type != AG_TYPE_CHAP) {
222 if (ag->ag_name != NULL)
223 log_warnx("cannot mix \"chap\" authentication with "
224 "other types for auth-group \"%s\"", ag->ag_name);
225 else
226 log_warnx("cannot mix \"chap\" authentication with "
227 "other types for target \"%s\"",
228 ag->ag_target->t_iqn);
228 ag->ag_target->t_name);
229 return (NULL);
230 }
231
232 auth = auth_new(ag);
233 auth->a_user = checked_strdup(user);
234 auth->a_secret = checked_strdup(secret);
235
236 auth_check_secret_length(auth);

--- 12 unchanged lines hidden (view full) ---

249 if (ag->ag_type != AG_TYPE_CHAP_MUTUAL) {
250 if (ag->ag_name != NULL)
251 log_warnx("cannot mix \"chap-mutual\" authentication "
252 "with other types for auth-group \"%s\"",
253 ag->ag_name);
254 else
255 log_warnx("cannot mix \"chap-mutual\" authentication "
256 "with other types for target \"%s\"",
229 return (NULL);
230 }
231
232 auth = auth_new(ag);
233 auth->a_user = checked_strdup(user);
234 auth->a_secret = checked_strdup(secret);
235
236 auth_check_secret_length(auth);

--- 12 unchanged lines hidden (view full) ---

249 if (ag->ag_type != AG_TYPE_CHAP_MUTUAL) {
250 if (ag->ag_name != NULL)
251 log_warnx("cannot mix \"chap-mutual\" authentication "
252 "with other types for auth-group \"%s\"",
253 ag->ag_name);
254 else
255 log_warnx("cannot mix \"chap-mutual\" authentication "
256 "with other types for target \"%s\"",
257 ag->ag_target->t_iqn);
257 ag->ag_target->t_name);
258 return (NULL);
259 }
260
261 auth = auth_new(ag);
262 auth->a_user = checked_strdup(user);
263 auth->a_secret = checked_strdup(secret);
264 auth->a_mutual_user = checked_strdup(user2);
265 auth->a_mutual_secret = checked_strdup(secret2);

--- 415 unchanged lines hidden (view full) ---

681 log_warnx("invalid target name \"%s\"; should start with "
682 "either \".iqn\", \"eui.\", or \"naa.\"",
683 name);
684 }
685 return (true);
686}
687
688struct target *
258 return (NULL);
259 }
260
261 auth = auth_new(ag);
262 auth->a_user = checked_strdup(user);
263 auth->a_secret = checked_strdup(secret);
264 auth->a_mutual_user = checked_strdup(user2);
265 auth->a_mutual_secret = checked_strdup(secret2);

--- 415 unchanged lines hidden (view full) ---

681 log_warnx("invalid target name \"%s\"; should start with "
682 "either \".iqn\", \"eui.\", or \"naa.\"",
683 name);
684 }
685 return (true);
686}
687
688struct target *
689target_new(struct conf *conf, const char *iqn)
689target_new(struct conf *conf, const char *name)
690{
691 struct target *targ;
692 int i, len;
693
690{
691 struct target *targ;
692 int i, len;
693
694 targ = target_find(conf, iqn);
694 targ = target_find(conf, name);
695 if (targ != NULL) {
695 if (targ != NULL) {
696 log_warnx("duplicated target \"%s\"", iqn);
696 log_warnx("duplicated target \"%s\"", name);
697 return (NULL);
698 }
697 return (NULL);
698 }
699 if (valid_iscsi_name(iqn) == false) {
700 log_warnx("target name \"%s\" is invalid", iqn);
699 if (valid_iscsi_name(name) == false) {
700 log_warnx("target name \"%s\" is invalid", name);
701 return (NULL);
702 }
703 targ = calloc(1, sizeof(*targ));
704 if (targ == NULL)
705 log_err(1, "calloc");
701 return (NULL);
702 }
703 targ = calloc(1, sizeof(*targ));
704 if (targ == NULL)
705 log_err(1, "calloc");
706 targ->t_iqn = checked_strdup(iqn);
706 targ->t_name = checked_strdup(name);
707
708 /*
709 * RFC 3722 requires us to normalize the name to lowercase.
710 */
707
708 /*
709 * RFC 3722 requires us to normalize the name to lowercase.
710 */
711 len = strlen(iqn);
711 len = strlen(name);
712 for (i = 0; i < len; i++)
712 for (i = 0; i < len; i++)
713 targ->t_iqn[i] = tolower(targ->t_iqn[i]);
713 targ->t_name[i] = tolower(targ->t_name[i]);
714
715 TAILQ_INIT(&targ->t_luns);
716 targ->t_conf = conf;
717 TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next);
718
719 return (targ);
720}
721
722void
723target_delete(struct target *targ)
724{
725 struct lun *lun, *tmp;
726
727 TAILQ_REMOVE(&targ->t_conf->conf_targets, targ, t_next);
728
729 TAILQ_FOREACH_SAFE(lun, &targ->t_luns, l_next, tmp)
730 lun_delete(lun);
714
715 TAILQ_INIT(&targ->t_luns);
716 targ->t_conf = conf;
717 TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next);
718
719 return (targ);
720}
721
722void
723target_delete(struct target *targ)
724{
725 struct lun *lun, *tmp;
726
727 TAILQ_REMOVE(&targ->t_conf->conf_targets, targ, t_next);
728
729 TAILQ_FOREACH_SAFE(lun, &targ->t_luns, l_next, tmp)
730 lun_delete(lun);
731 free(targ->t_iqn);
731 free(targ->t_name);
732 free(targ);
733}
734
735struct target *
732 free(targ);
733}
734
735struct target *
736target_find(struct conf *conf, const char *iqn)
736target_find(struct conf *conf, const char *name)
737{
738 struct target *targ;
739
740 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
737{
738 struct target *targ;
739
740 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
741 if (strcasecmp(targ->t_iqn, iqn) == 0)
741 if (strcasecmp(targ->t_name, name) == 0)
742 return (targ);
743 }
744
745 return (NULL);
746}
747
748struct lun *
749lun_new(struct target *targ, int lun_id)
750{
751 struct lun *lun;
752
753 lun = lun_find(targ, lun_id);
754 if (lun != NULL) {
755 log_warnx("duplicated lun %d for target \"%s\"",
742 return (targ);
743 }
744
745 return (NULL);
746}
747
748struct lun *
749lun_new(struct target *targ, int lun_id)
750{
751 struct lun *lun;
752
753 lun = lun_find(targ, lun_id);
754 if (lun != NULL) {
755 log_warnx("duplicated lun %d for target \"%s\"",
756 lun_id, targ->t_iqn);
756 lun_id, targ->t_name);
757 return (NULL);
758 }
759
760 lun = calloc(1, sizeof(*lun));
761 if (lun == NULL)
762 log_err(1, "calloc");
763 lun->l_lun = lun_id;
764 TAILQ_INIT(&lun->l_options);

--- 84 unchanged lines hidden (view full) ---

849struct lun_option *
850lun_option_new(struct lun *lun, const char *name, const char *value)
851{
852 struct lun_option *lo;
853
854 lo = lun_option_find(lun, name);
855 if (lo != NULL) {
856 log_warnx("duplicated lun option %s for lun %d, target \"%s\"",
757 return (NULL);
758 }
759
760 lun = calloc(1, sizeof(*lun));
761 if (lun == NULL)
762 log_err(1, "calloc");
763 lun->l_lun = lun_id;
764 TAILQ_INIT(&lun->l_options);

--- 84 unchanged lines hidden (view full) ---

849struct lun_option *
850lun_option_new(struct lun *lun, const char *name, const char *value)
851{
852 struct lun_option *lo;
853
854 lo = lun_option_find(lun, name);
855 if (lo != NULL) {
856 log_warnx("duplicated lun option %s for lun %d, target \"%s\"",
857 name, lun->l_lun, lun->l_target->t_iqn);
857 name, lun->l_lun, lun->l_target->t_name);
858 return (NULL);
859 }
860
861 lo = calloc(1, sizeof(*lo));
862 if (lo == NULL)
863 log_err(1, "calloc");
864 lo->lo_name = checked_strdup(name);
865 lo->lo_value = checked_strdup(value);

--- 87 unchanged lines hidden (view full) ---

953 }
954 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
955 fprintf(stderr, "portal-group %s {\n", pg->pg_name);
956 TAILQ_FOREACH(portal, &pg->pg_portals, p_next)
957 fprintf(stderr, "\t listen %s\n", portal->p_listen);
958 fprintf(stderr, "}\n");
959 }
960 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
858 return (NULL);
859 }
860
861 lo = calloc(1, sizeof(*lo));
862 if (lo == NULL)
863 log_err(1, "calloc");
864 lo->lo_name = checked_strdup(name);
865 lo->lo_value = checked_strdup(value);

--- 87 unchanged lines hidden (view full) ---

953 }
954 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
955 fprintf(stderr, "portal-group %s {\n", pg->pg_name);
956 TAILQ_FOREACH(portal, &pg->pg_portals, p_next)
957 fprintf(stderr, "\t listen %s\n", portal->p_listen);
958 fprintf(stderr, "}\n");
959 }
960 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
961 fprintf(stderr, "target %s {\n", targ->t_iqn);
961 fprintf(stderr, "target %s {\n", targ->t_name);
962 if (targ->t_alias != NULL)
963 fprintf(stderr, "\t alias %s\n", targ->t_alias);
964 TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
965 fprintf(stderr, "\tlun %d {\n", lun->l_lun);
966 fprintf(stderr, "\t\tpath %s\n", lun->l_path);
967 TAILQ_FOREACH(lo, &lun->l_options, lo_next)
968 fprintf(stderr, "\t\toption %s %s\n",
969 lo->lo_name, lo->lo_value);

--- 10 unchanged lines hidden (view full) ---

980 const struct lun *lun2;
981 const struct target *targ2;
982
983 if (lun->l_backend == NULL)
984 lun_set_backend(lun, "block");
985 if (strcmp(lun->l_backend, "block") == 0) {
986 if (lun->l_path == NULL) {
987 log_warnx("missing path for lun %d, target \"%s\"",
962 if (targ->t_alias != NULL)
963 fprintf(stderr, "\t alias %s\n", targ->t_alias);
964 TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
965 fprintf(stderr, "\tlun %d {\n", lun->l_lun);
966 fprintf(stderr, "\t\tpath %s\n", lun->l_path);
967 TAILQ_FOREACH(lo, &lun->l_options, lo_next)
968 fprintf(stderr, "\t\toption %s %s\n",
969 lo->lo_name, lo->lo_value);

--- 10 unchanged lines hidden (view full) ---

980 const struct lun *lun2;
981 const struct target *targ2;
982
983 if (lun->l_backend == NULL)
984 lun_set_backend(lun, "block");
985 if (strcmp(lun->l_backend, "block") == 0) {
986 if (lun->l_path == NULL) {
987 log_warnx("missing path for lun %d, target \"%s\"",
988 lun->l_lun, lun->l_target->t_iqn);
988 lun->l_lun, lun->l_target->t_name);
989 return (1);
990 }
991 } else if (strcmp(lun->l_backend, "ramdisk") == 0) {
992 if (lun->l_size == 0) {
993 log_warnx("missing size for ramdisk-backed lun %d, "
989 return (1);
990 }
991 } else if (strcmp(lun->l_backend, "ramdisk") == 0) {
992 if (lun->l_size == 0) {
993 log_warnx("missing size for ramdisk-backed lun %d, "
994 "target \"%s\"", lun->l_lun, lun->l_target->t_iqn);
994 "target \"%s\"", lun->l_lun, lun->l_target->t_name);
995 return (1);
996 }
997 if (lun->l_path != NULL) {
998 log_warnx("path must not be specified "
999 "for ramdisk-backed lun %d, target \"%s\"",
995 return (1);
996 }
997 if (lun->l_path != NULL) {
998 log_warnx("path must not be specified "
999 "for ramdisk-backed lun %d, target \"%s\"",
1000 lun->l_lun, lun->l_target->t_iqn);
1000 lun->l_lun, lun->l_target->t_name);
1001 return (1);
1002 }
1003 }
1004 if (lun->l_lun < 0 || lun->l_lun > 255) {
1005 log_warnx("invalid lun number for lun %d, target \"%s\"; "
1006 "must be between 0 and 255", lun->l_lun,
1001 return (1);
1002 }
1003 }
1004 if (lun->l_lun < 0 || lun->l_lun > 255) {
1005 log_warnx("invalid lun number for lun %d, target \"%s\"; "
1006 "must be between 0 and 255", lun->l_lun,
1007 lun->l_target->t_iqn);
1007 lun->l_target->t_name);
1008 return (1);
1009 }
1010 if (lun->l_blocksize == 0) {
1011 lun_set_blocksize(lun, DEFAULT_BLOCKSIZE);
1012 } else if (lun->l_blocksize < 0) {
1013 log_warnx("invalid blocksize for lun %d, target \"%s\"; "
1008 return (1);
1009 }
1010 if (lun->l_blocksize == 0) {
1011 lun_set_blocksize(lun, DEFAULT_BLOCKSIZE);
1012 } else if (lun->l_blocksize < 0) {
1013 log_warnx("invalid blocksize for lun %d, target \"%s\"; "
1014 "must be larger than 0", lun->l_lun, lun->l_target->t_iqn);
1014 "must be larger than 0", lun->l_lun, lun->l_target->t_name);
1015 return (1);
1016 }
1017 if (lun->l_size != 0 && lun->l_size % lun->l_blocksize != 0) {
1018 log_warnx("invalid size for lun %d, target \"%s\"; "
1019 "must be multiple of blocksize", lun->l_lun,
1015 return (1);
1016 }
1017 if (lun->l_size != 0 && lun->l_size % lun->l_blocksize != 0) {
1018 log_warnx("invalid size for lun %d, target \"%s\"; "
1019 "must be multiple of blocksize", lun->l_lun,
1020 lun->l_target->t_iqn);
1020 lun->l_target->t_name);
1021 return (1);
1022 }
1023 TAILQ_FOREACH(targ2, &lun->l_target->t_conf->conf_targets, t_next) {
1024 TAILQ_FOREACH(lun2, &targ2->t_luns, l_next) {
1025 if (lun == lun2)
1026 continue;
1027 if (lun->l_path != NULL && lun2->l_path != NULL &&
1028 strcmp(lun->l_path, lun2->l_path) == 0) {
1029 log_debugx("WARNING: path \"%s\" duplicated "
1030 "between lun %d, target \"%s\", and "
1031 "lun %d, target \"%s\"", lun->l_path,
1021 return (1);
1022 }
1023 TAILQ_FOREACH(targ2, &lun->l_target->t_conf->conf_targets, t_next) {
1024 TAILQ_FOREACH(lun2, &targ2->t_luns, l_next) {
1025 if (lun == lun2)
1026 continue;
1027 if (lun->l_path != NULL && lun2->l_path != NULL &&
1028 strcmp(lun->l_path, lun2->l_path) == 0) {
1029 log_debugx("WARNING: path \"%s\" duplicated "
1030 "between lun %d, target \"%s\", and "
1031 "lun %d, target \"%s\"", lun->l_path,
1032 lun->l_lun, lun->l_target->t_iqn,
1033 lun2->l_lun, lun2->l_target->t_iqn);
1032 lun->l_lun, lun->l_target->t_name,
1033 lun2->l_lun, lun2->l_target->t_name);
1034 }
1035 }
1036 }
1037
1038 return (0);
1039}
1040
1041int

--- 8 unchanged lines hidden (view full) ---

1050
1051 if (conf->conf_pidfile_path == NULL)
1052 conf->conf_pidfile_path = checked_strdup(DEFAULT_PIDFILE);
1053
1054 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1055 if (targ->t_auth_group == NULL) {
1056 log_warnx("missing authentication for target \"%s\"; "
1057 "must specify either \"auth-group\", \"chap\", "
1034 }
1035 }
1036 }
1037
1038 return (0);
1039}
1040
1041int

--- 8 unchanged lines hidden (view full) ---

1050
1051 if (conf->conf_pidfile_path == NULL)
1052 conf->conf_pidfile_path = checked_strdup(DEFAULT_PIDFILE);
1053
1054 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
1055 if (targ->t_auth_group == NULL) {
1056 log_warnx("missing authentication for target \"%s\"; "
1057 "must specify either \"auth-group\", \"chap\", "
1058 "or \"chap-mutual\"", targ->t_iqn);
1058 "or \"chap-mutual\"", targ->t_name);
1059 return (1);
1060 }
1061 if (targ->t_portal_group == NULL) {
1062 targ->t_portal_group = portal_group_find(conf,
1063 "default");
1064 assert(targ->t_portal_group != NULL);
1065 }
1066 found_lun0 = false;
1067 TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
1068 error = conf_verify_lun(lun);
1069 if (error != 0)
1070 return (error);
1071 if (lun->l_lun == 0)
1072 found_lun0 = true;
1073 }
1074 if (!found_lun0) {
1075 log_warnx("mandatory LUN 0 not configured "
1059 return (1);
1060 }
1061 if (targ->t_portal_group == NULL) {
1062 targ->t_portal_group = portal_group_find(conf,
1063 "default");
1064 assert(targ->t_portal_group != NULL);
1065 }
1066 found_lun0 = false;
1067 TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
1068 error = conf_verify_lun(lun);
1069 if (error != 0)
1070 return (error);
1071 if (lun->l_lun == 0)
1072 found_lun0 = true;
1073 }
1074 if (!found_lun0) {
1075 log_warnx("mandatory LUN 0 not configured "
1076 "for target \"%s\"", targ->t_iqn);
1076 "for target \"%s\"", targ->t_name);
1077 return (1);
1078 }
1079 }
1080 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1081 assert(pg->pg_name != NULL);
1082 if (pg->pg_discovery_auth_group == NULL) {
1083 pg->pg_discovery_auth_group =
1084 auth_group_find(conf, "no-access");

--- 79 unchanged lines hidden (view full) ---

1164 }
1165 }
1166
1167 TAILQ_FOREACH_SAFE(oldtarg, &oldconf->conf_targets, t_next, tmptarg) {
1168 /*
1169 * First, remove any targets present in the old configuration
1170 * and missing in the new one.
1171 */
1077 return (1);
1078 }
1079 }
1080 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
1081 assert(pg->pg_name != NULL);
1082 if (pg->pg_discovery_auth_group == NULL) {
1083 pg->pg_discovery_auth_group =
1084 auth_group_find(conf, "no-access");

--- 79 unchanged lines hidden (view full) ---

1164 }
1165 }
1166
1167 TAILQ_FOREACH_SAFE(oldtarg, &oldconf->conf_targets, t_next, tmptarg) {
1168 /*
1169 * First, remove any targets present in the old configuration
1170 * and missing in the new one.
1171 */
1172 newtarg = target_find(newconf, oldtarg->t_iqn);
1172 newtarg = target_find(newconf, oldtarg->t_name);
1173 if (newtarg == NULL) {
1174 TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next,
1175 tmplun) {
1176 log_debugx("target %s not found in new "
1177 "configuration; removing its lun %d, "
1178 "backed by CTL lun %d",
1173 if (newtarg == NULL) {
1174 TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next,
1175 tmplun) {
1176 log_debugx("target %s not found in new "
1177 "configuration; removing its lun %d, "
1178 "backed by CTL lun %d",
1179 oldtarg->t_iqn, oldlun->l_lun,
1179 oldtarg->t_name, oldlun->l_lun,
1180 oldlun->l_ctl_lun);
1181 error = kernel_lun_remove(oldlun);
1182 if (error != 0) {
1183 log_warnx("failed to remove lun %d, "
1184 "target %s, CTL lun %d",
1180 oldlun->l_ctl_lun);
1181 error = kernel_lun_remove(oldlun);
1182 if (error != 0) {
1183 log_warnx("failed to remove lun %d, "
1184 "target %s, CTL lun %d",
1185 oldlun->l_lun, oldtarg->t_iqn,
1185 oldlun->l_lun, oldtarg->t_name,
1186 oldlun->l_ctl_lun);
1187 cumulated_error++;
1188 }
1189 lun_delete(oldlun);
1190 }
1191 target_delete(oldtarg);
1192 continue;
1193 }
1194
1195 /*
1196 * Second, remove any LUNs present in the old target
1197 * and missing in the new one.
1198 */
1199 TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next, tmplun) {
1200 newlun = lun_find(newtarg, oldlun->l_lun);
1201 if (newlun == NULL) {
1202 log_debugx("lun %d, target %s, CTL lun %d "
1203 "not found in new configuration; "
1186 oldlun->l_ctl_lun);
1187 cumulated_error++;
1188 }
1189 lun_delete(oldlun);
1190 }
1191 target_delete(oldtarg);
1192 continue;
1193 }
1194
1195 /*
1196 * Second, remove any LUNs present in the old target
1197 * and missing in the new one.
1198 */
1199 TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next, tmplun) {
1200 newlun = lun_find(newtarg, oldlun->l_lun);
1201 if (newlun == NULL) {
1202 log_debugx("lun %d, target %s, CTL lun %d "
1203 "not found in new configuration; "
1204 "removing", oldlun->l_lun, oldtarg->t_iqn,
1204 "removing", oldlun->l_lun, oldtarg->t_name,
1205 oldlun->l_ctl_lun);
1206 error = kernel_lun_remove(oldlun);
1207 if (error != 0) {
1208 log_warnx("failed to remove lun %d, "
1209 "target %s, CTL lun %d",
1205 oldlun->l_ctl_lun);
1206 error = kernel_lun_remove(oldlun);
1207 if (error != 0) {
1208 log_warnx("failed to remove lun %d, "
1209 "target %s, CTL lun %d",
1210 oldlun->l_lun, oldtarg->t_iqn,
1210 oldlun->l_lun, oldtarg->t_name,
1211 oldlun->l_ctl_lun);
1212 cumulated_error++;
1213 }
1214 lun_delete(oldlun);
1215 continue;
1216 }
1217
1218 /*
1219 * Also remove the LUNs changed by more than size.
1220 */
1221 changed = 0;
1222 assert(oldlun->l_backend != NULL);
1223 assert(newlun->l_backend != NULL);
1224 if (strcmp(newlun->l_backend, oldlun->l_backend) != 0) {
1225 log_debugx("backend for lun %d, target %s, "
1226 "CTL lun %d changed; removing",
1211 oldlun->l_ctl_lun);
1212 cumulated_error++;
1213 }
1214 lun_delete(oldlun);
1215 continue;
1216 }
1217
1218 /*
1219 * Also remove the LUNs changed by more than size.
1220 */
1221 changed = 0;
1222 assert(oldlun->l_backend != NULL);
1223 assert(newlun->l_backend != NULL);
1224 if (strcmp(newlun->l_backend, oldlun->l_backend) != 0) {
1225 log_debugx("backend for lun %d, target %s, "
1226 "CTL lun %d changed; removing",
1227 oldlun->l_lun, oldtarg->t_iqn,
1227 oldlun->l_lun, oldtarg->t_name,
1228 oldlun->l_ctl_lun);
1229 changed = 1;
1230 }
1231 if (oldlun->l_blocksize != newlun->l_blocksize) {
1232 log_debugx("blocksize for lun %d, target %s, "
1233 "CTL lun %d changed; removing",
1228 oldlun->l_ctl_lun);
1229 changed = 1;
1230 }
1231 if (oldlun->l_blocksize != newlun->l_blocksize) {
1232 log_debugx("blocksize for lun %d, target %s, "
1233 "CTL lun %d changed; removing",
1234 oldlun->l_lun, oldtarg->t_iqn,
1234 oldlun->l_lun, oldtarg->t_name,
1235 oldlun->l_ctl_lun);
1236 changed = 1;
1237 }
1238 if (newlun->l_device_id != NULL &&
1239 (oldlun->l_device_id == NULL ||
1240 strcmp(oldlun->l_device_id, newlun->l_device_id) !=
1241 0)) {
1242 log_debugx("device-id for lun %d, target %s, "
1243 "CTL lun %d changed; removing",
1235 oldlun->l_ctl_lun);
1236 changed = 1;
1237 }
1238 if (newlun->l_device_id != NULL &&
1239 (oldlun->l_device_id == NULL ||
1240 strcmp(oldlun->l_device_id, newlun->l_device_id) !=
1241 0)) {
1242 log_debugx("device-id for lun %d, target %s, "
1243 "CTL lun %d changed; removing",
1244 oldlun->l_lun, oldtarg->t_iqn,
1244 oldlun->l_lun, oldtarg->t_name,
1245 oldlun->l_ctl_lun);
1246 changed = 1;
1247 }
1248 if (newlun->l_path != NULL &&
1249 (oldlun->l_path == NULL ||
1250 strcmp(oldlun->l_path, newlun->l_path) != 0)) {
1251 log_debugx("path for lun %d, target %s, "
1252 "CTL lun %d, changed; removing",
1245 oldlun->l_ctl_lun);
1246 changed = 1;
1247 }
1248 if (newlun->l_path != NULL &&
1249 (oldlun->l_path == NULL ||
1250 strcmp(oldlun->l_path, newlun->l_path) != 0)) {
1251 log_debugx("path for lun %d, target %s, "
1252 "CTL lun %d, changed; removing",
1253 oldlun->l_lun, oldtarg->t_iqn,
1253 oldlun->l_lun, oldtarg->t_name,
1254 oldlun->l_ctl_lun);
1255 changed = 1;
1256 }
1257 if (newlun->l_serial != NULL &&
1258 (oldlun->l_serial == NULL ||
1259 strcmp(oldlun->l_serial, newlun->l_serial) != 0)) {
1260 log_debugx("serial for lun %d, target %s, "
1261 "CTL lun %d changed; removing",
1254 oldlun->l_ctl_lun);
1255 changed = 1;
1256 }
1257 if (newlun->l_serial != NULL &&
1258 (oldlun->l_serial == NULL ||
1259 strcmp(oldlun->l_serial, newlun->l_serial) != 0)) {
1260 log_debugx("serial for lun %d, target %s, "
1261 "CTL lun %d changed; removing",
1262 oldlun->l_lun, oldtarg->t_iqn,
1262 oldlun->l_lun, oldtarg->t_name,
1263 oldlun->l_ctl_lun);
1264 changed = 1;
1265 }
1266 if (changed) {
1267 error = kernel_lun_remove(oldlun);
1268 if (error != 0) {
1269 log_warnx("failed to remove lun %d, "
1270 "target %s, CTL lun %d",
1263 oldlun->l_ctl_lun);
1264 changed = 1;
1265 }
1266 if (changed) {
1267 error = kernel_lun_remove(oldlun);
1268 if (error != 0) {
1269 log_warnx("failed to remove lun %d, "
1270 "target %s, CTL lun %d",
1271 oldlun->l_lun, oldtarg->t_iqn,
1271 oldlun->l_lun, oldtarg->t_name,
1272 oldlun->l_ctl_lun);
1273 cumulated_error++;
1274 }
1275 lun_delete(oldlun);
1276 continue;
1277 }
1278
1279 lun_set_ctl_lun(newlun, oldlun->l_ctl_lun);
1280 }
1281 }
1282
1283 /*
1284 * Now add new targets or modify existing ones.
1285 */
1286 TAILQ_FOREACH(newtarg, &newconf->conf_targets, t_next) {
1272 oldlun->l_ctl_lun);
1273 cumulated_error++;
1274 }
1275 lun_delete(oldlun);
1276 continue;
1277 }
1278
1279 lun_set_ctl_lun(newlun, oldlun->l_ctl_lun);
1280 }
1281 }
1282
1283 /*
1284 * Now add new targets or modify existing ones.
1285 */
1286 TAILQ_FOREACH(newtarg, &newconf->conf_targets, t_next) {
1287 oldtarg = target_find(oldconf, newtarg->t_iqn);
1287 oldtarg = target_find(oldconf, newtarg->t_name);
1288
1289 TAILQ_FOREACH(newlun, &newtarg->t_luns, l_next) {
1290 if (oldtarg != NULL) {
1291 oldlun = lun_find(oldtarg, newlun->l_lun);
1292 if (oldlun != NULL) {
1293 if (newlun->l_size != oldlun->l_size) {
1294 log_debugx("resizing lun %d, "
1295 "target %s, CTL lun %d",
1296 newlun->l_lun,
1288
1289 TAILQ_FOREACH(newlun, &newtarg->t_luns, l_next) {
1290 if (oldtarg != NULL) {
1291 oldlun = lun_find(oldtarg, newlun->l_lun);
1292 if (oldlun != NULL) {
1293 if (newlun->l_size != oldlun->l_size) {
1294 log_debugx("resizing lun %d, "
1295 "target %s, CTL lun %d",
1296 newlun->l_lun,
1297 newtarg->t_iqn,
1297 newtarg->t_name,
1298 newlun->l_ctl_lun);
1299 error =
1300 kernel_lun_resize(newlun);
1301 if (error != 0) {
1302 log_warnx("failed to "
1303 "resize lun %d, "
1304 "target %s, "
1305 "CTL lun %d",
1306 newlun->l_lun,
1298 newlun->l_ctl_lun);
1299 error =
1300 kernel_lun_resize(newlun);
1301 if (error != 0) {
1302 log_warnx("failed to "
1303 "resize lun %d, "
1304 "target %s, "
1305 "CTL lun %d",
1306 newlun->l_lun,
1307 newtarg->t_iqn,
1307 newtarg->t_name,
1308 newlun->l_lun);
1309 cumulated_error++;
1310 }
1311 }
1312 continue;
1313 }
1314 }
1315 log_debugx("adding lun %d, target %s",
1308 newlun->l_lun);
1309 cumulated_error++;
1310 }
1311 }
1312 continue;
1313 }
1314 }
1315 log_debugx("adding lun %d, target %s",
1316 newlun->l_lun, newtarg->t_iqn);
1316 newlun->l_lun, newtarg->t_name);
1317 error = kernel_lun_add(newlun);
1318 if (error != 0) {
1319 log_warnx("failed to add lun %d, target %s",
1317 error = kernel_lun_add(newlun);
1318 if (error != 0) {
1319 log_warnx("failed to add lun %d, target %s",
1320 newlun->l_lun, newtarg->t_iqn);
1320 newlun->l_lun, newtarg->t_name);
1321 cumulated_error++;
1322 }
1323 }
1324 }
1325
1326 /*
1327 * Go through the new portals, opening the sockets as neccessary.
1328 */

--- 502 unchanged lines hidden ---
1321 cumulated_error++;
1322 }
1323 }
1324 }
1325
1326 /*
1327 * Go through the new portals, opening the sockets as neccessary.
1328 */

--- 502 unchanged lines hidden ---