2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2015 iXsystems Inc.
7 * This software was developed by Jakub Klama <jceel@FreeBSD.org>
8 * under sponsorship from iXsystems Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/queue.h>
35 #include <sys/types.h>
42 #include <netinet/in.h>
43 #include <netinet/ip.h>
47 static struct conf *conf = NULL;
49 static int uclparse_toplevel(const ucl_object_t *);
50 static int uclparse_chap(struct auth_group *, const ucl_object_t *);
51 static int uclparse_chap_mutual(struct auth_group *, const ucl_object_t *);
52 static int uclparse_lun(const char *, const ucl_object_t *);
53 static int uclparse_auth_group(const char *, const ucl_object_t *);
54 static int uclparse_portal_group(const char *, const ucl_object_t *);
55 static int uclparse_target(const char *, const ucl_object_t *);
56 static int uclparse_target_portal_group(struct target *, const ucl_object_t *);
57 static int uclparse_target_lun(struct target *, const ucl_object_t *);
60 uclparse_chap(struct auth_group *auth_group, const ucl_object_t *obj)
62 const struct auth *ca;
63 const ucl_object_t *user, *secret;
65 user = ucl_object_find_key(obj, "user");
66 if (!user || user->type != UCL_STRING) {
67 log_warnx("chap section in auth-group \"%s\" is missing "
68 "\"user\" string key", auth_group->ag_name);
72 secret = ucl_object_find_key(obj, "secret");
73 if (!secret || secret->type != UCL_STRING) {
74 log_warnx("chap section in auth-group \"%s\" is missing "
75 "\"secret\" string key", auth_group->ag_name);
78 ca = auth_new_chap(auth_group,
79 ucl_object_tostring(user),
80 ucl_object_tostring(secret));
89 uclparse_chap_mutual(struct auth_group *auth_group, const ucl_object_t *obj)
91 const struct auth *ca;
92 const ucl_object_t *user, *secret, *mutual_user;
93 const ucl_object_t *mutual_secret;
95 user = ucl_object_find_key(obj, "user");
96 if (!user || user->type != UCL_STRING) {
97 log_warnx("chap-mutual section in auth-group \"%s\" is missing "
98 "\"user\" string key", auth_group->ag_name);
102 secret = ucl_object_find_key(obj, "secret");
103 if (!secret || secret->type != UCL_STRING) {
104 log_warnx("chap-mutual section in auth-group \"%s\" is missing "
105 "\"secret\" string key", auth_group->ag_name);
109 mutual_user = ucl_object_find_key(obj, "mutual-user");
110 if (!user || user->type != UCL_STRING) {
111 log_warnx("chap-mutual section in auth-group \"%s\" is missing "
112 "\"mutual-user\" string key", auth_group->ag_name);
116 mutual_secret = ucl_object_find_key(obj, "mutual-secret");
117 if (!secret || secret->type != UCL_STRING) {
118 log_warnx("chap-mutual section in auth-group \"%s\" is missing "
119 "\"mutual-secret\" string key", auth_group->ag_name);
123 ca = auth_new_chap_mutual(auth_group,
124 ucl_object_tostring(user),
125 ucl_object_tostring(secret),
126 ucl_object_tostring(mutual_user),
127 ucl_object_tostring(mutual_secret));
136 uclparse_target_portal_group(struct target *target, const ucl_object_t *obj)
138 struct portal_group *tpg;
139 struct auth_group *tag = NULL;
141 const ucl_object_t *portal_group, *auth_group;
143 portal_group = ucl_object_find_key(obj, "name");
144 if (!portal_group || portal_group->type != UCL_STRING) {
145 log_warnx("portal-group section in target \"%s\" is missing "
146 "\"name\" string key", target->t_name);
150 auth_group = ucl_object_find_key(obj, "auth-group-name");
151 if (auth_group && auth_group->type != UCL_STRING) {
152 log_warnx("portal-group section in target \"%s\" is missing "
153 "\"auth-group-name\" string key", target->t_name);
158 tpg = portal_group_find(conf, ucl_object_tostring(portal_group));
160 log_warnx("unknown portal-group \"%s\" for target "
161 "\"%s\"", ucl_object_tostring(portal_group), target->t_name);
166 tag = auth_group_find(conf, ucl_object_tostring(auth_group));
168 log_warnx("unknown auth-group \"%s\" for target "
169 "\"%s\"", ucl_object_tostring(auth_group),
175 tp = port_new(conf, target, tpg);
177 log_warnx("can't link portal-group \"%s\" to target "
178 "\"%s\"", ucl_object_tostring(portal_group), target->t_name);
181 tp->p_auth_group = tag;
187 uclparse_target_lun(struct target *target, const ucl_object_t *obj)
192 if (obj->type == UCL_INT) {
195 tmp = ucl_object_toint(obj);
196 if (tmp >= MAX_LUNS) {
197 log_warnx("LU number %ju in target \"%s\" is too big",
198 tmp, target->t_name);
202 asprintf(&name, "%s,lun,%ju", target->t_name, tmp);
203 lun = lun_new(conf, name);
207 lun_set_scsiname(lun, name);
208 target->t_luns[tmp] = lun;
212 if (obj->type == UCL_OBJECT) {
213 const ucl_object_t *num = ucl_object_find_key(obj, "number");
214 const ucl_object_t *name = ucl_object_find_key(obj, "name");
216 if (num == NULL || num->type != UCL_INT) {
217 log_warnx("lun section in target \"%s\" is missing "
218 "\"number\" integer property", target->t_name);
221 tmp = ucl_object_toint(num);
222 if (tmp >= MAX_LUNS) {
223 log_warnx("LU number %ju in target \"%s\" is too big",
224 tmp, target->t_name);
228 if (name == NULL || name->type != UCL_STRING) {
229 log_warnx("lun section in target \"%s\" is missing "
230 "\"name\" string property", target->t_name);
234 lun = lun_find(conf, ucl_object_tostring(name));
238 target->t_luns[tmp] = lun;
245 uclparse_toplevel(const ucl_object_t *top)
247 ucl_object_iter_t it = NULL, iter = NULL;
248 const ucl_object_t *obj = NULL, *child = NULL;
251 /* Pass 1 - everything except targets */
252 while ((obj = ucl_iterate_object(top, &it, true))) {
253 const char *key = ucl_object_key(obj);
255 if (!strcmp(key, "debug")) {
256 if (obj->type == UCL_INT)
257 conf->conf_debug = ucl_object_toint(obj);
259 log_warnx("\"debug\" property value is not integer");
264 if (!strcmp(key, "timeout")) {
265 if (obj->type == UCL_INT)
266 conf->conf_timeout = ucl_object_toint(obj);
268 log_warnx("\"timeout\" property value is not integer");
273 if (!strcmp(key, "maxproc")) {
274 if (obj->type == UCL_INT)
275 conf->conf_maxproc = ucl_object_toint(obj);
277 log_warnx("\"maxproc\" property value is not integer");
282 if (!strcmp(key, "pidfile")) {
283 if (obj->type == UCL_STRING)
284 conf->conf_pidfile_path = strdup(
285 ucl_object_tostring(obj));
287 log_warnx("\"pidfile\" property value is not string");
292 if (!strcmp(key, "isns-server")) {
293 if (obj->type == UCL_ARRAY) {
295 while ((child = ucl_iterate_object(obj, &iter,
297 if (child->type != UCL_STRING)
301 ucl_object_tostring(child));
307 log_warnx("\"isns-server\" property value is "
313 if (!strcmp(key, "isns-period")) {
314 if (obj->type == UCL_INT)
315 conf->conf_timeout = ucl_object_toint(obj);
317 log_warnx("\"isns-period\" property value is not integer");
322 if (!strcmp(key, "isns-timeout")) {
323 if (obj->type == UCL_INT)
324 conf->conf_timeout = ucl_object_toint(obj);
326 log_warnx("\"isns-timeout\" property value is not integer");
331 if (!strcmp(key, "auth-group")) {
332 if (obj->type == UCL_OBJECT) {
334 while ((child = ucl_iterate_object(obj, &iter, true))) {
335 uclparse_auth_group(ucl_object_key(child), child);
338 log_warnx("\"auth-group\" section is not an object");
343 if (!strcmp(key, "portal-group")) {
344 if (obj->type == UCL_OBJECT) {
346 while ((child = ucl_iterate_object(obj, &iter, true))) {
347 uclparse_portal_group(ucl_object_key(child), child);
350 log_warnx("\"portal-group\" section is not an object");
355 if (!strcmp(key, "lun")) {
356 if (obj->type == UCL_OBJECT) {
358 while ((child = ucl_iterate_object(obj, &iter, true))) {
359 uclparse_lun(ucl_object_key(child), child);
362 log_warnx("\"lun\" section is not an object");
368 /* Pass 2 - targets */
370 while ((obj = ucl_iterate_object(top, &it, true))) {
371 const char *key = ucl_object_key(obj);
373 if (!strcmp(key, "target")) {
374 if (obj->type == UCL_OBJECT) {
376 while ((child = ucl_iterate_object(obj, &iter,
378 uclparse_target(ucl_object_key(child),
382 log_warnx("\"target\" section is not an object");
392 uclparse_auth_group(const char *name, const ucl_object_t *top)
394 struct auth_group *auth_group;
395 const struct auth_name *an;
396 const struct auth_portal *ap;
397 ucl_object_iter_t it = NULL, it2 = NULL;
398 const ucl_object_t *obj = NULL, *tmp = NULL;
402 if (!strcmp(name, "default") &&
403 conf->conf_default_ag_defined == false) {
404 auth_group = auth_group_find(conf, name);
405 conf->conf_default_ag_defined = true;
407 auth_group = auth_group_new(conf, name);
410 if (auth_group == NULL)
413 while ((obj = ucl_iterate_object(top, &it, true))) {
414 key = ucl_object_key(obj);
416 if (!strcmp(key, "auth-type")) {
417 const char *value = ucl_object_tostring(obj);
419 err = auth_group_set_type(auth_group, value);
424 if (!strcmp(key, "chap")) {
425 if (obj->type != UCL_ARRAY) {
426 log_warnx("\"chap\" property of "
427 "auth-group \"%s\" is not an array",
433 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
434 if (uclparse_chap(auth_group, tmp) != 0)
439 if (!strcmp(key, "chap-mutual")) {
440 if (obj->type != UCL_ARRAY) {
441 log_warnx("\"chap-mutual\" property of "
442 "auth-group \"%s\" is not an array",
448 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
449 if (uclparse_chap_mutual(auth_group, tmp) != 0)
454 if (!strcmp(key, "initiator-name")) {
455 if (obj->type != UCL_ARRAY) {
456 log_warnx("\"initiator-name\" property of "
457 "auth-group \"%s\" is not an array",
463 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
464 const char *value = ucl_object_tostring(tmp);
466 an = auth_name_new(auth_group, value);
472 if (!strcmp(key, "initiator-portal")) {
473 if (obj->type != UCL_ARRAY) {
474 log_warnx("\"initiator-portal\" property of "
475 "auth-group \"%s\" is not an array",
481 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
482 const char *value = ucl_object_tostring(tmp);
484 ap = auth_portal_new(auth_group, value);
495 uclparse_portal_group(const char *name, const ucl_object_t *top)
497 struct portal_group *portal_group;
498 ucl_object_iter_t it = NULL, it2 = NULL;
499 const ucl_object_t *obj = NULL, *tmp = NULL;
502 if (strcmp(name, "default") == 0 &&
503 conf->conf_default_pg_defined == false) {
504 portal_group = portal_group_find(conf, name);
505 conf->conf_default_pg_defined = true;
507 portal_group = portal_group_new(conf, name);
510 if (portal_group == NULL)
513 while ((obj = ucl_iterate_object(top, &it, true))) {
514 key = ucl_object_key(obj);
516 if (!strcmp(key, "discovery-auth-group")) {
517 portal_group->pg_discovery_auth_group =
518 auth_group_find(conf, ucl_object_tostring(obj));
519 if (portal_group->pg_discovery_auth_group == NULL) {
520 log_warnx("unknown discovery-auth-group \"%s\" "
521 "for portal-group \"%s\"",
522 ucl_object_tostring(obj),
523 portal_group->pg_name);
528 if (!strcmp(key, "discovery-filter")) {
529 if (obj->type != UCL_STRING) {
530 log_warnx("\"discovery-filter\" property of "
531 "portal-group \"%s\" is not a string",
532 portal_group->pg_name);
536 if (portal_group_set_filter(portal_group,
537 ucl_object_tostring(obj)) != 0)
541 if (!strcmp(key, "listen")) {
542 if (obj->type == UCL_STRING) {
543 if (portal_group_add_listen(portal_group,
544 ucl_object_tostring(obj), false) != 0)
546 } else if (obj->type == UCL_ARRAY) {
547 while ((tmp = ucl_iterate_object(obj, &it2,
549 if (portal_group_add_listen(
551 ucl_object_tostring(tmp),
556 log_warnx("\"listen\" property of "
557 "portal-group \"%s\" is not a string",
558 portal_group->pg_name);
563 if (!strcmp(key, "listen-iser")) {
564 if (obj->type == UCL_STRING) {
565 if (portal_group_add_listen(portal_group,
566 ucl_object_tostring(obj), true) != 0)
568 } else if (obj->type == UCL_ARRAY) {
569 while ((tmp = ucl_iterate_object(obj, &it2,
571 if (portal_group_add_listen(
573 ucl_object_tostring(tmp),
578 log_warnx("\"listen\" property of "
579 "portal-group \"%s\" is not a string",
580 portal_group->pg_name);
585 if (!strcmp(key, "redirect")) {
586 if (obj->type != UCL_STRING) {
587 log_warnx("\"listen\" property of "
588 "portal-group \"%s\" is not a string",
589 portal_group->pg_name);
593 if (portal_group_set_redirection(portal_group,
594 ucl_object_tostring(obj)) != 0)
598 if (!strcmp(key, "options")) {
599 if (obj->type != UCL_OBJECT) {
600 log_warnx("\"options\" property of portal group "
601 "\"%s\" is not an object", portal_group->pg_name);
605 while ((tmp = ucl_iterate_object(obj, &it2,
607 option_new(&portal_group->pg_options,
609 ucl_object_tostring_forced(tmp));
613 if (!strcmp(key, "dscp")) {
614 if ((obj->type != UCL_STRING) && (obj->type != UCL_INT)) {
615 log_warnx("\"dscp\" property of portal group "
616 "\"%s\" is not a string or integer", portal_group->pg_name);
619 if (obj->type == UCL_INT)
620 portal_group->pg_dscp = ucl_object_toint(obj);
622 key = ucl_object_tostring(obj);
623 if (strcmp(key, "0x") == 0)
624 portal_group->pg_dscp = strtol(key + 2, NULL, 16);
625 else if (strcmp(key, "be") || strcmp(key, "cs0"))
626 portal_group->pg_dscp = IPTOS_DSCP_CS0 >> 2;
627 else if (strcmp(key, "ef"))
628 portal_group->pg_dscp = IPTOS_DSCP_EF >> 2;
629 else if (strcmp(key, "cs0"))
630 portal_group->pg_dscp = IPTOS_DSCP_CS0 >> 2;
631 else if (strcmp(key, "cs1"))
632 portal_group->pg_dscp = IPTOS_DSCP_CS1 >> 2;
633 else if (strcmp(key, "cs2"))
634 portal_group->pg_dscp = IPTOS_DSCP_CS2 >> 2;
635 else if (strcmp(key, "cs3"))
636 portal_group->pg_dscp = IPTOS_DSCP_CS3 >> 2;
637 else if (strcmp(key, "cs4"))
638 portal_group->pg_dscp = IPTOS_DSCP_CS4 >> 2;
639 else if (strcmp(key, "cs5"))
640 portal_group->pg_dscp = IPTOS_DSCP_CS5 >> 2;
641 else if (strcmp(key, "cs6"))
642 portal_group->pg_dscp = IPTOS_DSCP_CS6 >> 2;
643 else if (strcmp(key, "cs7"))
644 portal_group->pg_dscp = IPTOS_DSCP_CS7 >> 2;
645 else if (strcmp(key, "af11"))
646 portal_group->pg_dscp = IPTOS_DSCP_AF11 >> 2;
647 else if (strcmp(key, "af12"))
648 portal_group->pg_dscp = IPTOS_DSCP_AF12 >> 2;
649 else if (strcmp(key, "af13"))
650 portal_group->pg_dscp = IPTOS_DSCP_AF13 >> 2;
651 else if (strcmp(key, "af21"))
652 portal_group->pg_dscp = IPTOS_DSCP_AF21 >> 2;
653 else if (strcmp(key, "af22"))
654 portal_group->pg_dscp = IPTOS_DSCP_AF22 >> 2;
655 else if (strcmp(key, "af23"))
656 portal_group->pg_dscp = IPTOS_DSCP_AF23 >> 2;
657 else if (strcmp(key, "af31"))
658 portal_group->pg_dscp = IPTOS_DSCP_AF31 >> 2;
659 else if (strcmp(key, "af32"))
660 portal_group->pg_dscp = IPTOS_DSCP_AF32 >> 2;
661 else if (strcmp(key, "af33"))
662 portal_group->pg_dscp = IPTOS_DSCP_AF33 >> 2;
663 else if (strcmp(key, "af41"))
664 portal_group->pg_dscp = IPTOS_DSCP_AF41 >> 2;
665 else if (strcmp(key, "af42"))
666 portal_group->pg_dscp = IPTOS_DSCP_AF42 >> 2;
667 else if (strcmp(key, "af43"))
668 portal_group->pg_dscp = IPTOS_DSCP_AF43 >> 2;
670 log_warnx("\"dscp\" property value is not a supported textual value");
681 uclparse_target(const char *name, const ucl_object_t *top)
683 struct target *target;
684 ucl_object_iter_t it = NULL, it2 = NULL;
685 const ucl_object_t *obj = NULL, *tmp = NULL;
688 target = target_new(conf, name);
692 while ((obj = ucl_iterate_object(top, &it, true))) {
693 key = ucl_object_key(obj);
695 if (!strcmp(key, "alias")) {
696 if (obj->type != UCL_STRING) {
697 log_warnx("\"alias\" property of target "
698 "\"%s\" is not a string", target->t_name);
702 target->t_alias = strdup(ucl_object_tostring(obj));
705 if (!strcmp(key, "auth-group")) {
706 if (target->t_auth_group != NULL) {
707 if (target->t_auth_group->ag_name != NULL)
708 log_warnx("auth-group for target \"%s\" "
709 "specified more than once",
712 log_warnx("cannot use both auth-group "
713 "and explicit authorisations for "
714 "target \"%s\"", target->t_name);
717 target->t_auth_group = auth_group_find(conf,
718 ucl_object_tostring(obj));
719 if (target->t_auth_group == NULL) {
720 log_warnx("unknown auth-group \"%s\" for target "
721 "\"%s\"", ucl_object_tostring(obj),
727 if (!strcmp(key, "auth-type")) {
730 if (target->t_auth_group != NULL) {
731 if (target->t_auth_group->ag_name != NULL) {
732 log_warnx("cannot use both auth-group and "
733 "auth-type for target \"%s\"",
738 target->t_auth_group = auth_group_new(conf, NULL);
739 if (target->t_auth_group == NULL)
742 target->t_auth_group->ag_target = target;
744 error = auth_group_set_type(target->t_auth_group,
745 ucl_object_tostring(obj));
750 if (!strcmp(key, "chap")) {
751 if (uclparse_chap(target->t_auth_group, obj) != 0)
755 if (!strcmp(key, "chap-mutual")) {
756 if (uclparse_chap_mutual(target->t_auth_group, obj) != 0)
760 if (!strcmp(key, "initiator-name")) {
761 const struct auth_name *an;
763 if (target->t_auth_group != NULL) {
764 if (target->t_auth_group->ag_name != NULL) {
765 log_warnx("cannot use both auth-group and "
766 "initiator-name for target \"%s\"",
771 target->t_auth_group = auth_group_new(conf, NULL);
772 if (target->t_auth_group == NULL)
775 target->t_auth_group->ag_target = target;
777 an = auth_name_new(target->t_auth_group,
778 ucl_object_tostring(obj));
783 if (!strcmp(key, "initiator-portal")) {
784 const struct auth_portal *ap;
786 if (target->t_auth_group != NULL) {
787 if (target->t_auth_group->ag_name != NULL) {
788 log_warnx("cannot use both auth-group and "
789 "initiator-portal for target \"%s\"",
794 target->t_auth_group = auth_group_new(conf, NULL);
795 if (target->t_auth_group == NULL)
798 target->t_auth_group->ag_target = target;
800 ap = auth_portal_new(target->t_auth_group,
801 ucl_object_tostring(obj));
806 if (!strcmp(key, "portal-group")) {
807 if (obj->type == UCL_OBJECT) {
808 if (uclparse_target_portal_group(target, obj) != 0)
812 if (obj->type == UCL_ARRAY) {
813 while ((tmp = ucl_iterate_object(obj, &it2,
815 if (uclparse_target_portal_group(target,
822 if (!strcmp(key, "port")) {
825 const char *value = ucl_object_tostring(obj);
826 int ret, i_pp, i_vp = 0;
828 ret = sscanf(value, "ioctl/%d/%d", &i_pp, &i_vp);
830 tp = port_new_ioctl(conf, target, i_pp, i_vp);
832 log_warnx("can't create new ioctl port "
833 "for target \"%s\"", target->t_name);
840 pp = pport_find(conf, value);
842 log_warnx("unknown port \"%s\" for target \"%s\"",
843 value, target->t_name);
846 if (!TAILQ_EMPTY(&pp->pp_ports)) {
847 log_warnx("can't link port \"%s\" to target \"%s\", "
848 "port already linked to some target",
849 value, target->t_name);
852 tp = port_new_pp(conf, target, pp);
854 log_warnx("can't link port \"%s\" to target \"%s\"",
855 value, target->t_name);
860 if (!strcmp(key, "redirect")) {
861 if (obj->type != UCL_STRING) {
862 log_warnx("\"redirect\" property of target "
863 "\"%s\" is not a string", target->t_name);
867 if (target_set_redirection(target,
868 ucl_object_tostring(obj)) != 0)
872 if (!strcmp(key, "lun")) {
873 while ((tmp = ucl_iterate_object(obj, &it2, true))) {
874 if (uclparse_target_lun(target, tmp) != 0)
884 uclparse_lun(const char *name, const ucl_object_t *top)
887 ucl_object_iter_t it = NULL, child_it = NULL;
888 const ucl_object_t *obj = NULL, *child = NULL;
891 lun = lun_new(conf, name);
895 while ((obj = ucl_iterate_object(top, &it, true))) {
896 key = ucl_object_key(obj);
898 if (!strcmp(key, "backend")) {
899 if (obj->type != UCL_STRING) {
900 log_warnx("\"backend\" property of lun "
901 "\"%s\" is not a string",
906 lun_set_backend(lun, ucl_object_tostring(obj));
909 if (!strcmp(key, "blocksize")) {
910 if (obj->type != UCL_INT) {
911 log_warnx("\"blocksize\" property of lun "
912 "\"%s\" is not an integer", lun->l_name);
916 lun_set_blocksize(lun, ucl_object_toint(obj));
919 if (!strcmp(key, "device-id")) {
920 if (obj->type != UCL_STRING) {
921 log_warnx("\"device-id\" property of lun "
922 "\"%s\" is not an integer", lun->l_name);
926 lun_set_device_id(lun, ucl_object_tostring(obj));
929 if (!strcmp(key, "options")) {
930 if (obj->type != UCL_OBJECT) {
931 log_warnx("\"options\" property of lun "
932 "\"%s\" is not an object", lun->l_name);
936 while ((child = ucl_iterate_object(obj, &child_it,
938 option_new(&lun->l_options,
939 ucl_object_key(child),
940 ucl_object_tostring_forced(child));
944 if (!strcmp(key, "path")) {
945 if (obj->type != UCL_STRING) {
946 log_warnx("\"path\" property of lun "
947 "\"%s\" is not a string", lun->l_name);
951 lun_set_path(lun, ucl_object_tostring(obj));
954 if (!strcmp(key, "serial")) {
955 if (obj->type != UCL_STRING) {
956 log_warnx("\"serial\" property of lun "
957 "\"%s\" is not a string", lun->l_name);
961 lun_set_serial(lun, ucl_object_tostring(obj));
964 if (!strcmp(key, "size")) {
965 if (obj->type != UCL_INT) {
966 log_warnx("\"size\" property of lun "
967 "\"%s\" is not an integer", lun->l_name);
971 lun_set_size(lun, ucl_object_toint(obj));
979 uclparse_conf(struct conf *newconf, const char *path)
981 struct ucl_parser *parser;
986 parser = ucl_parser_new(0);
988 if (!ucl_parser_add_file(parser, path)) {
989 log_warn("unable to parse configuration file %s: %s", path,
990 ucl_parser_get_error(parser));
991 ucl_parser_free(parser);
995 top = ucl_parser_get_object(parser);
996 error = uclparse_toplevel(top);
997 ucl_object_unref(top);
998 ucl_parser_free(parser);