ctld.c (0bfd163f522701b486e066fa2e56624c02f5081a) | ctld.c (2fabfaa5048a571ab10468a8520667dae7ed7a18) |
---|---|
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 --- 855 unchanged lines hidden (view full) --- 864 lo->lo_name, lo->lo_value); 865 fprintf(stderr, "\t}\n"); 866 } 867 fprintf(stderr, "}\n"); 868 } 869} 870#endif 871 | 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 --- 855 unchanged lines hidden (view full) --- 864 lo->lo_name, lo->lo_value); 865 fprintf(stderr, "\t}\n"); 866 } 867 fprintf(stderr, "}\n"); 868 } 869} 870#endif 871 |
872static int 873conf_verify_lun(struct lun *lun) 874{ 875 const struct lun *lun2; 876 877 if (lun->l_backend == NULL) 878 lun_set_backend(lun, "block"); 879 if (strcmp(lun->l_backend, "block") == 0) { 880 if (lun->l_path == NULL) { 881 log_warnx("missing path for lun %d, target \"%s\"", 882 lun->l_lun, lun->l_target->t_iqn); 883 return (1); 884 } 885 } else if (strcmp(lun->l_backend, "ramdisk") == 0) { 886 if (lun->l_size == 0) { 887 log_warnx("missing size for ramdisk-backed lun %d, " 888 "target \"%s\"", lun->l_lun, lun->l_target->t_iqn); 889 return (1); 890 } 891 if (lun->l_path != NULL) { 892 log_warnx("path must not be specified " 893 "for ramdisk-backed lun %d, target \"%s\"", 894 lun->l_lun, lun->l_target->t_iqn); 895 return (1); 896 } 897 } 898 if (lun->l_lun < 0 || lun->l_lun > 255) { 899 log_warnx("invalid lun number for lun %d, target \"%s\"; " 900 "must be between 0 and 255", lun->l_lun, 901 lun->l_target->t_iqn); 902 return (1); 903 } 904#if 1 /* Should we? */ 905 TAILQ_FOREACH(lun2, &lun->l_target->t_luns, l_next) { 906 if (lun == lun2) 907 continue; 908 if (lun->l_path != NULL && lun2->l_path != NULL && 909 strcmp(lun->l_path, lun2->l_path) == 0) 910 log_debugx("WARNING: duplicate path for lun %d, " 911 "target \"%s\"", lun->l_lun, lun->l_target->t_iqn); 912 } 913#endif 914 if (lun->l_blocksize == 0) { 915 lun_set_blocksize(lun, DEFAULT_BLOCKSIZE); 916 } else if (lun->l_blocksize < 0) { 917 log_warnx("invalid blocksize for lun %d, target \"%s\"; " 918 "must be larger than 0", lun->l_lun, lun->l_target->t_iqn); 919 return (1); 920 } 921 if (lun->l_size != 0 && lun->l_size % lun->l_blocksize != 0) { 922 log_warnx("invalid size for lun %d, target \"%s\"; " 923 "must be multiple of blocksize", lun->l_lun, 924 lun->l_target->t_iqn); 925 return (1); 926 } 927 928 return (0); 929} 930 |
|
872int 873conf_verify(struct conf *conf) 874{ 875 struct auth_group *ag; 876 struct portal_group *pg; 877 struct target *targ; | 931int 932conf_verify(struct conf *conf) 933{ 934 struct auth_group *ag; 935 struct portal_group *pg; 936 struct target *targ; |
878 struct lun *lun, *lun2; | 937 struct lun *lun; |
879 bool found_lun0; | 938 bool found_lun0; |
939 int error; |
|
880 881 if (conf->conf_pidfile_path == NULL) 882 conf->conf_pidfile_path = checked_strdup(DEFAULT_PIDFILE); 883 884 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) { 885 if (targ->t_auth_group == NULL) { 886 log_warnx("missing authentication for target \"%s\"; " 887 "must specify either \"auth-group\", \"chap\", " 888 "or \"chap-mutual\"", targ->t_iqn); 889 return (1); 890 } 891 if (targ->t_portal_group == NULL) { 892 targ->t_portal_group = portal_group_find(conf, 893 "default"); 894 assert(targ->t_portal_group != NULL); 895 } 896 found_lun0 = false; 897 TAILQ_FOREACH(lun, &targ->t_luns, l_next) { | 940 941 if (conf->conf_pidfile_path == NULL) 942 conf->conf_pidfile_path = checked_strdup(DEFAULT_PIDFILE); 943 944 TAILQ_FOREACH(targ, &conf->conf_targets, t_next) { 945 if (targ->t_auth_group == NULL) { 946 log_warnx("missing authentication for target \"%s\"; " 947 "must specify either \"auth-group\", \"chap\", " 948 "or \"chap-mutual\"", targ->t_iqn); 949 return (1); 950 } 951 if (targ->t_portal_group == NULL) { 952 targ->t_portal_group = portal_group_find(conf, 953 "default"); 954 assert(targ->t_portal_group != NULL); 955 } 956 found_lun0 = false; 957 TAILQ_FOREACH(lun, &targ->t_luns, l_next) { |
958 error = conf_verify_lun(lun); 959 if (error != 0) 960 return (error); |
|
898 if (lun->l_lun == 0) 899 found_lun0 = true; | 961 if (lun->l_lun == 0) 962 found_lun0 = true; |
900 if (lun->l_backend == NULL) 901 lun_set_backend(lun, "block"); 902 if (strcmp(lun->l_backend, "block") == 0 && 903 lun->l_path == NULL) { 904 log_warnx("missing path for lun %d, " 905 "target \"%s\"", lun->l_lun, targ->t_iqn); 906 return (1); 907 } 908 if (strcmp(lun->l_backend, "ramdisk") == 0) { 909 if (lun->l_size == 0) { 910 log_warnx("missing size for " 911 "ramdisk-backed lun %d, " 912 "target \"%s\"", 913 lun->l_lun, targ->t_iqn); 914 return (1); 915 } 916 if (lun->l_path != NULL) { 917 log_warnx("path must not be specified " 918 "for ramdisk-backed lun %d, " 919 "target \"%s\"", 920 lun->l_lun, targ->t_iqn); 921 return (1); 922 } 923 } 924 if (lun->l_lun < 0 || lun->l_lun > 255) { 925 log_warnx("invalid lun number for lun %d, " 926 "target \"%s\"; must be between 0 and 255", 927 lun->l_lun, targ->t_iqn); 928 return (1); 929 } 930#if 1 /* Should we? */ 931 TAILQ_FOREACH(lun2, &targ->t_luns, l_next) { 932 if (lun == lun2) 933 continue; 934 if (lun->l_path != NULL && 935 lun2->l_path != NULL && 936 strcmp(lun->l_path, lun2->l_path) == 0) 937 log_debugx("WARNING: duplicate path " 938 "for lun %d, target \"%s\"", 939 lun->l_lun, targ->t_iqn); 940 } 941#endif 942 if (lun->l_blocksize == 0) { 943 lun_set_blocksize(lun, DEFAULT_BLOCKSIZE); 944 } else if (lun->l_blocksize <= 0) { 945 log_warnx("invalid blocksize for lun %d, " 946 "target \"%s\"; must be larger than 0", 947 lun->l_lun, targ->t_iqn); 948 return (1); 949 } 950 if (lun->l_size != 0 && 951 lun->l_size % lun->l_blocksize != 0) { 952 log_warnx("invalid size for lun %d, target " 953 "\"%s\"; must be multiple of blocksize", 954 lun->l_lun, targ->t_iqn); 955 return (1); 956 } | |
957 } 958 if (!found_lun0) { 959 log_warnx("mandatory LUN 0 not configured " 960 "for target \"%s\"", targ->t_iqn); 961 return (1); 962 } 963 } 964 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) { --- 749 unchanged lines hidden --- | 963 } 964 if (!found_lun0) { 965 log_warnx("mandatory LUN 0 not configured " 966 "for target \"%s\"", targ->t_iqn); 967 return (1); 968 } 969 } 970 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) { --- 749 unchanged lines hidden --- |