ctld.c (274871) | ctld.c (274939) |
---|---|
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 274871 2014-11-22 17:52:33Z trasz $"); | 32__FBSDID("$FreeBSD: stable/10/usr.sbin/ctld/ctld.c 274939 2014-11-24 00:47:04Z 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> --- 4 unchanged lines hidden (view full) --- 45#include <stdbool.h> 46#include <stdio.h> 47#include <stdint.h> 48#include <stdlib.h> 49#include <string.h> 50#include <unistd.h> 51 52#include "ctld.h" | 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> --- 4 unchanged lines hidden (view full) --- 45#include <stdbool.h> 46#include <stdio.h> 47#include <stdint.h> 48#include <stdlib.h> 49#include <string.h> 50#include <unistd.h> 51 52#include "ctld.h" |
53#include "isns.h" |
|
53 54bool proxy_mode = false; 55 56static volatile bool sighup_received = false; 57static volatile bool sigterm_received = false; 58static volatile bool sigalrm_received = false; 59 60static int nchildren = 0; --- 23 unchanged lines hidden (view full) --- 84 struct conf *conf; 85 86 conf = calloc(1, sizeof(*conf)); 87 if (conf == NULL) 88 log_err(1, "calloc"); 89 TAILQ_INIT(&conf->conf_targets); 90 TAILQ_INIT(&conf->conf_auth_groups); 91 TAILQ_INIT(&conf->conf_portal_groups); | 54 55bool proxy_mode = false; 56 57static volatile bool sighup_received = false; 58static volatile bool sigterm_received = false; 59static volatile bool sigalrm_received = false; 60 61static int nchildren = 0; --- 23 unchanged lines hidden (view full) --- 85 struct conf *conf; 86 87 conf = calloc(1, sizeof(*conf)); 88 if (conf == NULL) 89 log_err(1, "calloc"); 90 TAILQ_INIT(&conf->conf_targets); 91 TAILQ_INIT(&conf->conf_auth_groups); 92 TAILQ_INIT(&conf->conf_portal_groups); |
93 TAILQ_INIT(&conf->conf_isns); |
|
92 | 94 |
95 conf->conf_isns_period = 900; 96 conf->conf_isns_timeout = 5; |
|
93 conf->conf_debug = 0; 94 conf->conf_timeout = 60; 95 conf->conf_maxproc = 30; 96 97 return (conf); 98} 99 100void 101conf_delete(struct conf *conf) 102{ 103 struct target *targ, *tmp; 104 struct auth_group *ag, *cagtmp; 105 struct portal_group *pg, *cpgtmp; | 97 conf->conf_debug = 0; 98 conf->conf_timeout = 60; 99 conf->conf_maxproc = 30; 100 101 return (conf); 102} 103 104void 105conf_delete(struct conf *conf) 106{ 107 struct target *targ, *tmp; 108 struct auth_group *ag, *cagtmp; 109 struct portal_group *pg, *cpgtmp; |
110 struct isns *is, *istmp; |
|
106 107 assert(conf->conf_pidfh == NULL); 108 109 TAILQ_FOREACH_SAFE(targ, &conf->conf_targets, t_next, tmp) 110 target_delete(targ); 111 TAILQ_FOREACH_SAFE(ag, &conf->conf_auth_groups, ag_next, cagtmp) 112 auth_group_delete(ag); 113 TAILQ_FOREACH_SAFE(pg, &conf->conf_portal_groups, pg_next, cpgtmp) 114 portal_group_delete(pg); | 111 112 assert(conf->conf_pidfh == NULL); 113 114 TAILQ_FOREACH_SAFE(targ, &conf->conf_targets, t_next, tmp) 115 target_delete(targ); 116 TAILQ_FOREACH_SAFE(ag, &conf->conf_auth_groups, ag_next, cagtmp) 117 auth_group_delete(ag); 118 TAILQ_FOREACH_SAFE(pg, &conf->conf_portal_groups, pg_next, cpgtmp) 119 portal_group_delete(pg); |
120 TAILQ_FOREACH_SAFE(is, &conf->conf_isns, i_next, istmp) 121 isns_delete(is); |
|
115 free(conf->conf_pidfile_path); 116 free(conf); 117} 118 119static struct auth * 120auth_new(struct auth_group *ag) 121{ 122 struct auth *auth; --- 491 unchanged lines hidden (view full) --- 614 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) { 615 if (strcmp(pg->pg_name, name) == 0) 616 return (pg); 617 } 618 619 return (NULL); 620} 621 | 122 free(conf->conf_pidfile_path); 123 free(conf); 124} 125 126static struct auth * 127auth_new(struct auth_group *ag) 128{ 129 struct auth *auth; --- 491 unchanged lines hidden (view full) --- 621 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) { 622 if (strcmp(pg->pg_name, name) == 0) 623 return (pg); 624 } 625 626 return (NULL); 627} 628 |
622int 623portal_group_add_listen(struct portal_group *pg, const char *value, bool iser) | 629static int 630parse_addr_port(char *arg, const char *def_port, struct addrinfo **ai) |
624{ 625 struct addrinfo hints; | 631{ 632 struct addrinfo hints; |
626 struct portal *portal; 627 char *addr, *ch, *arg; | 633 char *addr, *ch; |
628 const char *port; 629 int error, colons = 0; 630 | 634 const char *port; 635 int error, colons = 0; 636 |
631 portal = portal_new(pg); 632 portal->p_listen = checked_strdup(value); 633 portal->p_iser = iser; 634 635 arg = portal->p_listen; 636 if (arg[0] == '\0') { 637 log_warnx("empty listen address"); 638 portal_delete(portal); 639 return (1); 640 } | |
641 if (arg[0] == '[') { 642 /* 643 * IPv6 address in square brackets, perhaps with port. 644 */ 645 arg++; 646 addr = strsep(&arg, "]"); | 637 if (arg[0] == '[') { 638 /* 639 * IPv6 address in square brackets, perhaps with port. 640 */ 641 arg++; 642 addr = strsep(&arg, "]"); |
647 if (arg == NULL) { 648 log_warnx("invalid listen address %s", 649 portal->p_listen); 650 portal_delete(portal); | 643 if (arg == NULL) |
651 return (1); | 644 return (1); |
652 } | |
653 if (arg[0] == '\0') { | 645 if (arg[0] == '\0') { |
654 port = "3260"; | 646 port = def_port; |
655 } else if (arg[0] == ':') { 656 port = arg + 1; | 647 } else if (arg[0] == ':') { 648 port = arg + 1; |
657 } else { 658 log_warnx("invalid listen address %s", 659 portal->p_listen); 660 portal_delete(portal); | 649 } else |
661 return (1); | 650 return (1); |
662 } | |
663 } else { 664 /* 665 * Either IPv6 address without brackets - and without 666 * a port - or IPv4 address. Just count the colons. 667 */ 668 for (ch = arg; *ch != '\0'; ch++) { 669 if (*ch == ':') 670 colons++; 671 } 672 if (colons > 1) { 673 addr = arg; | 651 } else { 652 /* 653 * Either IPv6 address without brackets - and without 654 * a port - or IPv4 address. Just count the colons. 655 */ 656 for (ch = arg; *ch != '\0'; ch++) { 657 if (*ch == ':') 658 colons++; 659 } 660 if (colons > 1) { 661 addr = arg; |
674 port = "3260"; | 662 port = def_port; |
675 } else { 676 addr = strsep(&arg, ":"); 677 if (arg == NULL) | 663 } else { 664 addr = strsep(&arg, ":"); 665 if (arg == NULL) |
678 port = "3260"; | 666 port = def_port; |
679 else 680 port = arg; 681 } 682 } 683 684 memset(&hints, 0, sizeof(hints)); 685 hints.ai_family = PF_UNSPEC; 686 hints.ai_socktype = SOCK_STREAM; 687 hints.ai_flags = AI_PASSIVE; | 667 else 668 port = arg; 669 } 670 } 671 672 memset(&hints, 0, sizeof(hints)); 673 hints.ai_family = PF_UNSPEC; 674 hints.ai_socktype = SOCK_STREAM; 675 hints.ai_flags = AI_PASSIVE; |
676 error = getaddrinfo(addr, port, &hints, ai); 677 if (error != 0) 678 return (1); 679 return (0); 680} |
|
688 | 681 |
689 error = getaddrinfo(addr, port, &hints, &portal->p_ai); 690 if (error != 0) { 691 log_warnx("getaddrinfo for %s failed: %s", 692 portal->p_listen, gai_strerror(error)); | 682int 683portal_group_add_listen(struct portal_group *pg, const char *value, bool iser) 684{ 685 struct portal *portal; 686 687 portal = portal_new(pg); 688 portal->p_listen = checked_strdup(value); 689 portal->p_iser = iser; 690 691 if (parse_addr_port(portal->p_listen, "3260", &portal->p_ai)) { 692 log_warnx("invalid listen address %s", portal->p_listen); |
693 portal_delete(portal); 694 return (1); 695 } 696 697 /* 698 * XXX: getaddrinfo(3) may return multiple addresses; we should turn 699 * those into multiple portals. 700 */ 701 702 return (0); 703} 704 | 693 portal_delete(portal); 694 return (1); 695 } 696 697 /* 698 * XXX: getaddrinfo(3) may return multiple addresses; we should turn 699 * those into multiple portals. 700 */ 701 702 return (0); 703} 704 |
705int 706isns_new(struct conf *conf, const char *addr) 707{ 708 struct isns *isns; 709 710 isns = calloc(1, sizeof(*isns)); 711 if (isns == NULL) 712 log_err(1, "calloc"); 713 isns->i_conf = conf; 714 TAILQ_INSERT_TAIL(&conf->conf_isns, isns, i_next); 715 isns->i_addr = checked_strdup(addr); 716 717 if (parse_addr_port(isns->i_addr, "3205", &isns->i_ai)) { 718 log_warnx("invalid iSNS address %s", isns->i_addr); 719 isns_delete(isns); 720 return (1); 721 } 722 723 /* 724 * XXX: getaddrinfo(3) may return multiple addresses; we should turn 725 * those into multiple servers. 726 */ 727 728 return (0); 729} 730 731void 732isns_delete(struct isns *isns) 733{ 734 735 TAILQ_REMOVE(&isns->i_conf->conf_isns, isns, i_next); 736 free(isns->i_addr); 737 if (isns->i_ai != NULL) 738 freeaddrinfo(isns->i_ai); 739 free(isns); 740} 741 742static int 743isns_do_connect(struct isns *isns) 744{ 745 int s; 746 747 s = socket(isns->i_ai->ai_family, isns->i_ai->ai_socktype, 748 isns->i_ai->ai_protocol); 749 if (s < 0) { 750 log_warn("socket(2) failed for %s", isns->i_addr); 751 return (-1); 752 } 753 if (connect(s, isns->i_ai->ai_addr, isns->i_ai->ai_addrlen)) { 754 log_warn("connect(2) failed for %s", isns->i_addr); 755 close(s); 756 return (-1); 757 } 758 return(s); 759} 760 761static int 762isns_do_register(struct isns *isns, int s, const char *hostname) 763{ 764 struct conf *conf = isns->i_conf; 765 struct target *target; 766 struct portal *portal; 767 struct portal_group *pg; 768 struct isns_req *req; 769 int res = 0; 770 uint32_t error; 771 772 req = isns_req_create(ISNS_FUNC_DEVATTRREG, ISNS_FLAG_CLIENT); 773 isns_req_add_str(req, 32, TAILQ_FIRST(&conf->conf_targets)->t_name); 774 isns_req_add_delim(req); 775 isns_req_add_str(req, 1, hostname); 776 isns_req_add_32(req, 2, 2); /* 2 -- iSCSI */ 777 isns_req_add_32(req, 6, conf->conf_isns_period); 778 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) { 779 if (pg->pg_unassigned) 780 continue; 781 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) { 782 isns_req_add_addr(req, 16, portal->p_ai); 783 isns_req_add_port(req, 17, portal->p_ai); 784 } 785 } 786 TAILQ_FOREACH(target, &conf->conf_targets, t_next) { 787 isns_req_add_str(req, 32, target->t_name); 788 isns_req_add_32(req, 33, 1); /* 1 -- Target*/ 789 if (target->t_alias != NULL) 790 isns_req_add_str(req, 34, target->t_alias); 791 pg = target->t_portal_group; 792 isns_req_add_32(req, 51, pg->pg_tag); 793 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) { 794 isns_req_add_addr(req, 49, portal->p_ai); 795 isns_req_add_port(req, 50, portal->p_ai); 796 } 797 } 798 res = isns_req_send(s, req); 799 if (res < 0) { 800 log_warn("send(2) failed for %s", isns->i_addr); 801 goto quit; 802 } 803 res = isns_req_receive(s, req); 804 if (res < 0) { 805 log_warn("receive(2) failed for %s", isns->i_addr); 806 goto quit; 807 } 808 error = isns_req_get_status(req); 809 if (error != 0) { 810 log_warnx("iSNS register error %d for %s", error, isns->i_addr); 811 res = -1; 812 } 813quit: 814 isns_req_free(req); 815 return (res); 816} 817 818static int 819isns_do_check(struct isns *isns, int s, const char *hostname) 820{ 821 struct conf *conf = isns->i_conf; 822 struct isns_req *req; 823 int res = 0; 824 uint32_t error; 825 826 req = isns_req_create(ISNS_FUNC_DEVATTRQRY, ISNS_FLAG_CLIENT); 827 isns_req_add_str(req, 32, TAILQ_FIRST(&conf->conf_targets)->t_name); 828 isns_req_add_str(req, 1, hostname); 829 isns_req_add_delim(req); 830 isns_req_add(req, 2, 0, NULL); 831 res = isns_req_send(s, req); 832 if (res < 0) { 833 log_warn("send(2) failed for %s", isns->i_addr); 834 goto quit; 835 } 836 res = isns_req_receive(s, req); 837 if (res < 0) { 838 log_warn("receive(2) failed for %s", isns->i_addr); 839 goto quit; 840 } 841 error = isns_req_get_status(req); 842 if (error != 0) { 843 log_warnx("iSNS check error %d for %s", error, isns->i_addr); 844 res = -1; 845 } 846quit: 847 isns_req_free(req); 848 return (res); 849} 850 851static int 852isns_do_deregister(struct isns *isns, int s, const char *hostname) 853{ 854 struct conf *conf = isns->i_conf; 855 struct isns_req *req; 856 int res = 0; 857 uint32_t error; 858 859 req = isns_req_create(ISNS_FUNC_DEVDEREG, ISNS_FLAG_CLIENT); 860 isns_req_add_str(req, 32, TAILQ_FIRST(&conf->conf_targets)->t_name); 861 isns_req_add_delim(req); 862 isns_req_add_str(req, 1, hostname); 863 res = isns_req_send(s, req); 864 if (res < 0) { 865 log_warn("send(2) failed for %s", isns->i_addr); 866 goto quit; 867 } 868 res = isns_req_receive(s, req); 869 if (res < 0) { 870 log_warn("receive(2) failed for %s", isns->i_addr); 871 goto quit; 872 } 873 error = isns_req_get_status(req); 874 if (error != 0) { 875 log_warnx("iSNS deregister error %d for %s", error, isns->i_addr); 876 res = -1; 877 } 878quit: 879 isns_req_free(req); 880 return (res); 881} 882 883void 884isns_register(struct isns *isns, struct isns *oldisns) 885{ 886 struct conf *conf = isns->i_conf; 887 int s, res; 888 char hostname[256]; 889 890 if (TAILQ_EMPTY(&conf->conf_targets) || 891 TAILQ_EMPTY(&conf->conf_portal_groups)) 892 return; 893 set_timeout(conf->conf_isns_timeout, false); 894 s = isns_do_connect(isns); 895 if (s < 0) { 896 set_timeout(0, false); 897 return; 898 } 899 gethostname(hostname, sizeof(hostname)); 900 901 if (oldisns == NULL || TAILQ_EMPTY(&oldisns->i_conf->conf_targets)) 902 oldisns = isns; 903 res = isns_do_deregister(oldisns, s, hostname); 904 res = isns_do_register(isns, s, hostname); 905 close(s); 906 set_timeout(0, false); 907} 908 909void 910isns_check(struct isns *isns) 911{ 912 struct conf *conf = isns->i_conf; 913 int s, res; 914 char hostname[256]; 915 916 if (TAILQ_EMPTY(&conf->conf_targets) || 917 TAILQ_EMPTY(&conf->conf_portal_groups)) 918 return; 919 set_timeout(conf->conf_isns_timeout, false); 920 s = isns_do_connect(isns); 921 if (s < 0) { 922 set_timeout(0, false); 923 return; 924 } 925 gethostname(hostname, sizeof(hostname)); 926 927 res = isns_do_check(isns, s, hostname); 928 if (res < 0) { 929 res = isns_do_deregister(isns, s, hostname); 930 res = isns_do_register(isns, s, hostname); 931 } 932 close(s); 933 set_timeout(0, false); 934} 935 936void 937isns_deregister(struct isns *isns) 938{ 939 struct conf *conf = isns->i_conf; 940 int s, res; 941 char hostname[256]; 942 943 if (TAILQ_EMPTY(&conf->conf_targets) || 944 TAILQ_EMPTY(&conf->conf_portal_groups)) 945 return; 946 set_timeout(conf->conf_isns_timeout, false); 947 s = isns_do_connect(isns); 948 if (s < 0) 949 return; 950 gethostname(hostname, sizeof(hostname)); 951 952 res = isns_do_deregister(isns, s, hostname); 953 close(s); 954 set_timeout(0, false); 955} 956 |
|
705static bool 706valid_hex(const char ch) 707{ 708 switch (ch) { 709 case '0': 710 case '1': 711 case '2': 712 case '3': --- 533 unchanged lines hidden (view full) --- 1246 1247static int 1248conf_apply(struct conf *oldconf, struct conf *newconf) 1249{ 1250 struct target *oldtarg, *newtarg, *tmptarg; 1251 struct lun *oldlun, *newlun, *tmplun; 1252 struct portal_group *oldpg, *newpg; 1253 struct portal *oldp, *newp; | 957static bool 958valid_hex(const char ch) 959{ 960 switch (ch) { 961 case '0': 962 case '1': 963 case '2': 964 case '3': --- 533 unchanged lines hidden (view full) --- 1498 1499static int 1500conf_apply(struct conf *oldconf, struct conf *newconf) 1501{ 1502 struct target *oldtarg, *newtarg, *tmptarg; 1503 struct lun *oldlun, *newlun, *tmplun; 1504 struct portal_group *oldpg, *newpg; 1505 struct portal *oldp, *newp; |
1506 struct isns *oldns, *newns; |
|
1254 pid_t otherpid; 1255 int changed, cumulated_error = 0, error; 1256 int one = 1; 1257 1258 if (oldconf->conf_debug != newconf->conf_debug) { 1259 log_debugx("changing debug level to %d", newconf->conf_debug); 1260 log_init(newconf->conf_debug); 1261 } --- 21 unchanged lines hidden (view full) --- 1283 if (errno == EEXIST) 1284 log_errx(1, "daemon already running, pid: %jd.", 1285 (intmax_t)otherpid); 1286 log_err(1, "cannot open or create pidfile \"%s\"", 1287 newconf->conf_pidfile_path); 1288 } 1289 } 1290 | 1507 pid_t otherpid; 1508 int changed, cumulated_error = 0, error; 1509 int one = 1; 1510 1511 if (oldconf->conf_debug != newconf->conf_debug) { 1512 log_debugx("changing debug level to %d", newconf->conf_debug); 1513 log_init(newconf->conf_debug); 1514 } --- 21 unchanged lines hidden (view full) --- 1536 if (errno == EEXIST) 1537 log_errx(1, "daemon already running, pid: %jd.", 1538 (intmax_t)otherpid); 1539 log_err(1, "cannot open or create pidfile \"%s\"", 1540 newconf->conf_pidfile_path); 1541 } 1542 } 1543 |
1544 /* Deregister on removed iSNS servers. */ 1545 TAILQ_FOREACH(oldns, &oldconf->conf_isns, i_next) { 1546 TAILQ_FOREACH(newns, &newconf->conf_isns, i_next) { 1547 if (strcmp(oldns->i_addr, newns->i_addr) == 0) 1548 break; 1549 } 1550 if (newns == NULL) 1551 isns_deregister(oldns); 1552 } 1553 |
|
1291 /* 1292 * XXX: If target or lun removal fails, we should somehow "move" 1293 * the old lun or target into newconf, so that subsequent 1294 * conf_apply() would try to remove them again. That would 1295 * be somewhat hairy, though, and lun deletion failures don't 1296 * really happen, so leave it as it is for now. 1297 */ 1298 TAILQ_FOREACH_SAFE(oldtarg, &oldconf->conf_targets, t_next, tmptarg) { --- 13 unchanged lines hidden (view full) --- 1312 error = kernel_lun_remove(oldlun); 1313 if (error != 0) { 1314 log_warnx("failed to remove lun %d, " 1315 "target %s, CTL lun %d", 1316 oldlun->l_lun, oldtarg->t_name, 1317 oldlun->l_ctl_lun); 1318 cumulated_error++; 1319 } | 1554 /* 1555 * XXX: If target or lun removal fails, we should somehow "move" 1556 * the old lun or target into newconf, so that subsequent 1557 * conf_apply() would try to remove them again. That would 1558 * be somewhat hairy, though, and lun deletion failures don't 1559 * really happen, so leave it as it is for now. 1560 */ 1561 TAILQ_FOREACH_SAFE(oldtarg, &oldconf->conf_targets, t_next, tmptarg) { --- 13 unchanged lines hidden (view full) --- 1575 error = kernel_lun_remove(oldlun); 1576 if (error != 0) { 1577 log_warnx("failed to remove lun %d, " 1578 "target %s, CTL lun %d", 1579 oldlun->l_lun, oldtarg->t_name, 1580 oldlun->l_ctl_lun); 1581 cumulated_error++; 1582 } |
1320 lun_delete(oldlun); | |
1321 } 1322 kernel_port_remove(oldtarg); | 1583 } 1584 kernel_port_remove(oldtarg); |
1323 target_delete(oldtarg); | |
1324 continue; 1325 } 1326 1327 /* 1328 * Second, remove any LUNs present in the old target 1329 * and missing in the new one. 1330 */ 1331 TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next, tmplun) { --- 6 unchanged lines hidden (view full) --- 1338 error = kernel_lun_remove(oldlun); 1339 if (error != 0) { 1340 log_warnx("failed to remove lun %d, " 1341 "target %s, CTL lun %d", 1342 oldlun->l_lun, oldtarg->t_name, 1343 oldlun->l_ctl_lun); 1344 cumulated_error++; 1345 } | 1585 continue; 1586 } 1587 1588 /* 1589 * Second, remove any LUNs present in the old target 1590 * and missing in the new one. 1591 */ 1592 TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next, tmplun) { --- 6 unchanged lines hidden (view full) --- 1599 error = kernel_lun_remove(oldlun); 1600 if (error != 0) { 1601 log_warnx("failed to remove lun %d, " 1602 "target %s, CTL lun %d", 1603 oldlun->l_lun, oldtarg->t_name, 1604 oldlun->l_ctl_lun); 1605 cumulated_error++; 1606 } |
1346 lun_delete(oldlun); | |
1347 continue; 1348 } 1349 1350 /* 1351 * Also remove the LUNs changed by more than size. 1352 */ 1353 changed = 0; 1354 assert(oldlun->l_backend != NULL); --- 209 unchanged lines hidden (view full) --- 1564 continue; 1565 log_debugx("closing socket for %s, portal-group \"%s\"", 1566 oldp->p_listen, oldpg->pg_name); 1567 close(oldp->p_socket); 1568 oldp->p_socket = 0; 1569 } 1570 } 1571 | 1607 continue; 1608 } 1609 1610 /* 1611 * Also remove the LUNs changed by more than size. 1612 */ 1613 changed = 0; 1614 assert(oldlun->l_backend != NULL); --- 209 unchanged lines hidden (view full) --- 1824 continue; 1825 log_debugx("closing socket for %s, portal-group \"%s\"", 1826 oldp->p_listen, oldpg->pg_name); 1827 close(oldp->p_socket); 1828 oldp->p_socket = 0; 1829 } 1830 } 1831 |
1832 /* (Re-)Register on remaining/new iSNS servers. */ 1833 TAILQ_FOREACH(newns, &newconf->conf_isns, i_next) { 1834 TAILQ_FOREACH(oldns, &oldconf->conf_isns, i_next) { 1835 if (strcmp(oldns->i_addr, newns->i_addr) == 0) 1836 break; 1837 } 1838 isns_register(newns, oldns); 1839 } 1840 1841 /* Schedule iSNS update */ 1842 if (!TAILQ_EMPTY(&newconf->conf_isns)) 1843 set_timeout((newconf->conf_isns_period + 2) / 3, false); 1844 |
|
1572 return (cumulated_error); 1573} 1574 1575bool 1576timed_out(void) 1577{ 1578 1579 return (sigalrm_received); 1580} 1581 1582static void | 1845 return (cumulated_error); 1846} 1847 1848bool 1849timed_out(void) 1850{ 1851 1852 return (sigalrm_received); 1853} 1854 1855static void |
1583sigalrm_handler(int dummy __unused) | 1856sigalrm_handler_fatal(int dummy __unused) |
1584{ 1585 /* 1586 * It would be easiest to just log an error and exit. We can't 1587 * do this, though, because log_errx() is not signal safe, since 1588 * it calls syslog(3). Instead, set a flag checked by pdu_send() 1589 * and pdu_receive(), to call log_errx() there. Should they fail 1590 * to notice, we'll exit here one second later. 1591 */ 1592 if (sigalrm_received) { 1593 /* 1594 * Oh well. Just give up and quit. 1595 */ 1596 _exit(2); 1597 } 1598 1599 sigalrm_received = true; 1600} 1601 1602static void | 1857{ 1858 /* 1859 * It would be easiest to just log an error and exit. We can't 1860 * do this, though, because log_errx() is not signal safe, since 1861 * it calls syslog(3). Instead, set a flag checked by pdu_send() 1862 * and pdu_receive(), to call log_errx() there. Should they fail 1863 * to notice, we'll exit here one second later. 1864 */ 1865 if (sigalrm_received) { 1866 /* 1867 * Oh well. Just give up and quit. 1868 */ 1869 _exit(2); 1870 } 1871 1872 sigalrm_received = true; 1873} 1874 1875static void |
1603set_timeout(const struct conf *conf) | 1876sigalrm_handler(int dummy __unused) |
1604{ | 1877{ |
1878 1879 sigalrm_received = true; 1880} 1881 1882void 1883set_timeout(int timeout, int fatal) 1884{ |
|
1605 struct sigaction sa; 1606 struct itimerval itv; 1607 int error; 1608 | 1885 struct sigaction sa; 1886 struct itimerval itv; 1887 int error; 1888 |
1609 if (conf->conf_timeout <= 0) { | 1889 if (timeout <= 0) { |
1610 log_debugx("session timeout disabled"); | 1890 log_debugx("session timeout disabled"); |
1891 bzero(&itv, sizeof(itv)); 1892 error = setitimer(ITIMER_REAL, &itv, NULL); 1893 if (error != 0) 1894 log_err(1, "setitimer"); 1895 sigalrm_received = false; |
|
1611 return; 1612 } 1613 | 1896 return; 1897 } 1898 |
1899 sigalrm_received = false; |
|
1614 bzero(&sa, sizeof(sa)); | 1900 bzero(&sa, sizeof(sa)); |
1615 sa.sa_handler = sigalrm_handler; | 1901 if (fatal) 1902 sa.sa_handler = sigalrm_handler_fatal; 1903 else 1904 sa.sa_handler = sigalrm_handler; |
1616 sigfillset(&sa.sa_mask); 1617 error = sigaction(SIGALRM, &sa, NULL); 1618 if (error != 0) 1619 log_err(1, "sigaction"); 1620 1621 /* 1622 * First SIGALRM will arive after conf_timeout seconds. 1623 * If we do nothing, another one will arrive a second later. 1624 */ | 1905 sigfillset(&sa.sa_mask); 1906 error = sigaction(SIGALRM, &sa, NULL); 1907 if (error != 0) 1908 log_err(1, "sigaction"); 1909 1910 /* 1911 * First SIGALRM will arive after conf_timeout seconds. 1912 * If we do nothing, another one will arrive a second later. 1913 */ |
1914 log_debugx("setting session timeout to %d seconds", timeout); |
|
1625 bzero(&itv, sizeof(itv)); 1626 itv.it_interval.tv_sec = 1; | 1915 bzero(&itv, sizeof(itv)); 1916 itv.it_interval.tv_sec = 1; |
1627 itv.it_value.tv_sec = conf->conf_timeout; 1628 1629 log_debugx("setting session timeout to %d seconds", 1630 conf->conf_timeout); | 1917 itv.it_value.tv_sec = timeout; |
1631 error = setitimer(ITIMER_REAL, &itv, NULL); 1632 if (error != 0) 1633 log_err(1, "setitimer"); 1634} 1635 1636static int 1637wait_for_children(bool block) 1638{ --- 69 unchanged lines hidden (view full) --- 1708 log_errx(1, "getnameinfo: %s", gai_strerror(error)); 1709 1710 log_debugx("accepted connection from %s; portal group \"%s\"", 1711 host, portal->p_portal_group->pg_name); 1712 log_set_peer_addr(host); 1713 setproctitle("%s", host); 1714 1715 conn = connection_new(portal, fd, host, client_sa); | 1918 error = setitimer(ITIMER_REAL, &itv, NULL); 1919 if (error != 0) 1920 log_err(1, "setitimer"); 1921} 1922 1923static int 1924wait_for_children(bool block) 1925{ --- 69 unchanged lines hidden (view full) --- 1995 log_errx(1, "getnameinfo: %s", gai_strerror(error)); 1996 1997 log_debugx("accepted connection from %s; portal group \"%s\"", 1998 host, portal->p_portal_group->pg_name); 1999 log_set_peer_addr(host); 2000 setproctitle("%s", host); 2001 2002 conn = connection_new(portal, fd, host, client_sa); |
1716 set_timeout(conf); | 2003 set_timeout(conf->conf_timeout, true); |
1717 kernel_capsicate(); 1718 login(conn); 1719 if (conn->conn_session_type == CONN_SESSION_TYPE_NORMAL) { 1720 kernel_handoff(conn); 1721 log_debugx("connection handed off to the kernel"); 1722 } else { 1723 assert(conn->conn_session_type == CONN_SESSION_TYPE_DISCOVERY); 1724 discovery(conn); --- 30 unchanged lines hidden (view full) --- 1755 int portal_id; 1756#endif 1757 fd_set fdset; 1758 int error, nfds, client_fd; 1759 1760 pidfile_write(conf->conf_pidfh); 1761 1762 for (;;) { | 2004 kernel_capsicate(); 2005 login(conn); 2006 if (conn->conn_session_type == CONN_SESSION_TYPE_NORMAL) { 2007 kernel_handoff(conn); 2008 log_debugx("connection handed off to the kernel"); 2009 } else { 2010 assert(conn->conn_session_type == CONN_SESSION_TYPE_DISCOVERY); 2011 discovery(conn); --- 30 unchanged lines hidden (view full) --- 2042 int portal_id; 2043#endif 2044 fd_set fdset; 2045 int error, nfds, client_fd; 2046 2047 pidfile_write(conf->conf_pidfh); 2048 2049 for (;;) { |
1763 if (sighup_received || sigterm_received) | 2050 if (sighup_received || sigterm_received || timed_out()) |
1764 return; 1765 1766#ifdef ICL_KERNEL_PROXY 1767 if (proxy_mode) { 1768 client_salen = sizeof(client_sa); 1769 kernel_accept(&connection_id, &portal_id, 1770 (struct sockaddr *)&client_sa, &client_salen); 1771 assert(client_salen >= client_sa.ss_len); --- 107 unchanged lines hidden (view full) --- 1879 if (error != 0) 1880 log_err(1, "sigaction"); 1881} 1882 1883int 1884main(int argc, char **argv) 1885{ 1886 struct conf *oldconf, *newconf, *tmpconf; | 2051 return; 2052 2053#ifdef ICL_KERNEL_PROXY 2054 if (proxy_mode) { 2055 client_salen = sizeof(client_sa); 2056 kernel_accept(&connection_id, &portal_id, 2057 (struct sockaddr *)&client_sa, &client_salen); 2058 assert(client_salen >= client_sa.ss_len); --- 107 unchanged lines hidden (view full) --- 2166 if (error != 0) 2167 log_err(1, "sigaction"); 2168} 2169 2170int 2171main(int argc, char **argv) 2172{ 2173 struct conf *oldconf, *newconf, *tmpconf; |
2174 struct isns *newns; |
|
1887 const char *config_path = DEFAULT_CONFIG_PATH; 1888 int debug = 0, ch, error; 1889 bool dont_daemonize = false; 1890 1891 while ((ch = getopt(argc, argv, "df:R")) != -1) { 1892 switch (ch) { 1893 case 'd': 1894 dont_daemonize = true; --- 43 unchanged lines hidden (view full) --- 1938 log_debugx("daemonizing"); 1939 if (daemon(0, 0) == -1) { 1940 log_warn("cannot daemonize"); 1941 pidfile_remove(newconf->conf_pidfh); 1942 exit(1); 1943 } 1944 } 1945 | 2175 const char *config_path = DEFAULT_CONFIG_PATH; 2176 int debug = 0, ch, error; 2177 bool dont_daemonize = false; 2178 2179 while ((ch = getopt(argc, argv, "df:R")) != -1) { 2180 switch (ch) { 2181 case 'd': 2182 dont_daemonize = true; --- 43 unchanged lines hidden (view full) --- 2226 log_debugx("daemonizing"); 2227 if (daemon(0, 0) == -1) { 2228 log_warn("cannot daemonize"); 2229 pidfile_remove(newconf->conf_pidfh); 2230 exit(1); 2231 } 2232 } 2233 |
2234 /* Schedule iSNS update */ 2235 if (!TAILQ_EMPTY(&newconf->conf_isns)) 2236 set_timeout((newconf->conf_isns_period + 2) / 3, false); 2237 |
|
1946 for (;;) { 1947 main_loop(newconf, dont_daemonize); 1948 if (sighup_received) { 1949 sighup_received = false; 1950 log_debugx("received SIGHUP, reloading configuration"); 1951 tmpconf = conf_new_from_file(config_path); 1952 if (tmpconf == NULL) { 1953 log_warnx("configuration error, " --- 19 unchanged lines hidden (view full) --- 1973 1974 oldconf = newconf; 1975 newconf = conf_new(); 1976 if (debug > 0) 1977 newconf->conf_debug = debug; 1978 error = conf_apply(oldconf, newconf); 1979 if (error != 0) 1980 log_warnx("failed to apply configuration"); | 2238 for (;;) { 2239 main_loop(newconf, dont_daemonize); 2240 if (sighup_received) { 2241 sighup_received = false; 2242 log_debugx("received SIGHUP, reloading configuration"); 2243 tmpconf = conf_new_from_file(config_path); 2244 if (tmpconf == NULL) { 2245 log_warnx("configuration error, " --- 19 unchanged lines hidden (view full) --- 2265 2266 oldconf = newconf; 2267 newconf = conf_new(); 2268 if (debug > 0) 2269 newconf->conf_debug = debug; 2270 error = conf_apply(oldconf, newconf); 2271 if (error != 0) 2272 log_warnx("failed to apply configuration"); |
2273 conf_delete(oldconf); 2274 oldconf = NULL; |
|
1981 1982 log_warnx("exiting on signal"); 1983 exit(0); 1984 } else { 1985 nchildren -= wait_for_children(false); 1986 assert(nchildren >= 0); | 2275 2276 log_warnx("exiting on signal"); 2277 exit(0); 2278 } else { 2279 nchildren -= wait_for_children(false); 2280 assert(nchildren >= 0); |
2281 if (timed_out()) { 2282 set_timeout(0, false); 2283 TAILQ_FOREACH(newns, &newconf->conf_isns, i_next) 2284 isns_check(newns); 2285 /* Schedule iSNS update */ 2286 if (!TAILQ_EMPTY(&newconf->conf_isns)) { 2287 set_timeout((newconf->conf_isns_period 2288 + 2) / 3, 2289 false); 2290 } 2291 } |
|
1987 } 1988 } 1989 /* NOTREACHED */ 1990} | 2292 } 2293 } 2294 /* NOTREACHED */ 2295} |