kernel.c (279003) | kernel.c (279006) |
---|---|
1/*- 2 * Copyright (c) 2003, 2004 Silicon Graphics International Corp. 3 * Copyright (c) 1997-2007 Kenneth D. Merry 4 * Copyright (c) 2012 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * Portions of this software were developed by Edward Tomasz Napierala 8 * under sponsorship from the FreeBSD Foundation. --- 21 unchanged lines hidden (view full) --- 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGES. 34 * 35 */ 36 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003, 2004 Silicon Graphics International Corp. 3 * Copyright (c) 1997-2007 Kenneth D. Merry 4 * Copyright (c) 2012 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * Portions of this software were developed by Edward Tomasz Napierala 8 * under sponsorship from the FreeBSD Foundation. --- 21 unchanged lines hidden (view full) --- 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGES. 34 * 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: stable/10/usr.sbin/ctld/kernel.c 279003 2015-02-19 14:33:46Z mav $"); | 38__FBSDID("$FreeBSD: stable/10/usr.sbin/ctld/kernel.c 279006 2015-02-19 14:52:01Z mav $"); |
39 40#include <sys/ioctl.h> 41#include <sys/types.h> 42#include <sys/stat.h> 43#include <sys/param.h> 44#include <sys/linker.h> 45#include <sys/queue.h> 46#include <sys/callout.h> --- 69 unchanged lines hidden (view full) --- 116 char *device_id; 117 char *ctld_name; 118 STAILQ_HEAD(,cctl_lun_nv) attr_list; 119 STAILQ_ENTRY(cctl_lun) links; 120}; 121 122struct cctl_port { 123 uint32_t port_id; | 39 40#include <sys/ioctl.h> 41#include <sys/types.h> 42#include <sys/stat.h> 43#include <sys/param.h> 44#include <sys/linker.h> 45#include <sys/queue.h> 46#include <sys/callout.h> --- 69 unchanged lines hidden (view full) --- 116 char *device_id; 117 char *ctld_name; 118 STAILQ_HEAD(,cctl_lun_nv) attr_list; 119 STAILQ_ENTRY(cctl_lun) links; 120}; 121 122struct cctl_port { 123 uint32_t port_id; |
124 int cfiscsi_status; | 124 int cfiscsi_state; |
125 char *cfiscsi_target; 126 uint16_t cfiscsi_portal_group_tag; | 125 char *cfiscsi_target; 126 uint16_t cfiscsi_portal_group_tag; |
127 char *ctld_portal_group_name; |
|
127 STAILQ_HEAD(,cctl_lun_nv) attr_list; 128 STAILQ_ENTRY(cctl_port) links; 129}; 130 131struct cctl_devlist_data { 132 int num_luns; 133 STAILQ_HEAD(,cctl_lun) lun_list; 134 struct cctl_lun *cur_lun; --- 192 unchanged lines hidden (view full) --- 327 328 sbuf_delete(devlist->cur_sb[devlist->level]); 329 devlist->cur_sb[devlist->level] = NULL; 330 devlist->level--; 331 332 if (strcmp(name, "cfiscsi_target") == 0) { 333 cur_port->cfiscsi_target = str; 334 str = NULL; | 128 STAILQ_HEAD(,cctl_lun_nv) attr_list; 129 STAILQ_ENTRY(cctl_port) links; 130}; 131 132struct cctl_devlist_data { 133 int num_luns; 134 STAILQ_HEAD(,cctl_lun) lun_list; 135 struct cctl_lun *cur_lun; --- 192 unchanged lines hidden (view full) --- 328 329 sbuf_delete(devlist->cur_sb[devlist->level]); 330 devlist->cur_sb[devlist->level] = NULL; 331 devlist->level--; 332 333 if (strcmp(name, "cfiscsi_target") == 0) { 334 cur_port->cfiscsi_target = str; 335 str = NULL; |
335 } else if (strcmp(name, "cfiscsi_status") == 0) { 336 cur_port->cfiscsi_status = strtoul(str, NULL, 0); | 336 } else if (strcmp(name, "cfiscsi_state") == 0) { 337 cur_port->cfiscsi_state = strtoul(str, NULL, 0); |
337 } else if (strcmp(name, "cfiscsi_portal_group_tag") == 0) { 338 cur_port->cfiscsi_portal_group_tag = strtoul(str, NULL, 0); | 338 } else if (strcmp(name, "cfiscsi_portal_group_tag") == 0) { 339 cur_port->cfiscsi_portal_group_tag = strtoul(str, NULL, 0); |
340 } else if (strcmp(name, "ctld_portal_group_name") == 0) { 341 cur_port->ctld_portal_group_name = str; 342 str = NULL; |
|
339 } else if (strcmp(name, "targ_port") == 0) { 340 devlist->cur_port = NULL; 341 } else if (strcmp(name, "ctlportlist") == 0) { 342 /* Nothing. */ 343 } else { 344 struct cctl_lun_nv *nv; 345 346 nv = calloc(1, sizeof(*nv)); --- 21 unchanged lines hidden (view full) --- 368 sbuf_bcat(devlist->cur_sb[devlist->level], str, len); 369} 370 371struct conf * 372conf_new_from_kernel(void) 373{ 374 struct conf *conf = NULL; 375 struct target *targ; | 343 } else if (strcmp(name, "targ_port") == 0) { 344 devlist->cur_port = NULL; 345 } else if (strcmp(name, "ctlportlist") == 0) { 346 /* Nothing. */ 347 } else { 348 struct cctl_lun_nv *nv; 349 350 nv = calloc(1, sizeof(*nv)); --- 21 unchanged lines hidden (view full) --- 372 sbuf_bcat(devlist->cur_sb[devlist->level], str, len); 373} 374 375struct conf * 376conf_new_from_kernel(void) 377{ 378 struct conf *conf = NULL; 379 struct target *targ; |
380 struct portal_group *pg; 381 struct port *cp; |
|
376 struct lun *cl; 377 struct lun_option *lo; 378 struct ctl_lun_list list; 379 struct cctl_devlist_data devlist; 380 struct cctl_lun *lun; 381 struct cctl_port *port; 382 XML_Parser parser; 383 char *str; --- 107 unchanged lines hidden (view full) --- 491 492 STAILQ_FOREACH(port, &devlist.port_list, links) { 493 494 if (port->cfiscsi_target == NULL) { 495 log_debugx("CTL port %ju wasn't managed by ctld; " 496 "ignoring", (uintmax_t)port->port_id); 497 continue; 498 } | 382 struct lun *cl; 383 struct lun_option *lo; 384 struct ctl_lun_list list; 385 struct cctl_devlist_data devlist; 386 struct cctl_lun *lun; 387 struct cctl_port *port; 388 XML_Parser parser; 389 char *str; --- 107 unchanged lines hidden (view full) --- 497 498 STAILQ_FOREACH(port, &devlist.port_list, links) { 499 500 if (port->cfiscsi_target == NULL) { 501 log_debugx("CTL port %ju wasn't managed by ctld; " 502 "ignoring", (uintmax_t)port->port_id); 503 continue; 504 } |
499 if (port->cfiscsi_status != 1) { | 505 if (port->cfiscsi_state != 1) { |
500 log_debugx("CTL port %ju is not active (%d); ignoring", | 506 log_debugx("CTL port %ju is not active (%d); ignoring", |
501 (uintmax_t)port->port_id, port->cfiscsi_status); | 507 (uintmax_t)port->port_id, port->cfiscsi_state); |
502 continue; 503 } 504 505 targ = target_find(conf, port->cfiscsi_target); 506 if (targ == NULL) { 507#if 0 508 log_debugx("found new kernel target %s for CTL port %ld", 509 port->cfiscsi_target, port->port_id); 510#endif 511 targ = target_new(conf, port->cfiscsi_target); 512 if (targ == NULL) { 513 log_warnx("target_new failed"); 514 continue; 515 } 516 } | 508 continue; 509 } 510 511 targ = target_find(conf, port->cfiscsi_target); 512 if (targ == NULL) { 513#if 0 514 log_debugx("found new kernel target %s for CTL port %ld", 515 port->cfiscsi_target, port->port_id); 516#endif 517 targ = target_new(conf, port->cfiscsi_target); 518 if (targ == NULL) { 519 log_warnx("target_new failed"); 520 continue; 521 } 522 } |
523 524 if (port->ctld_portal_group_name == NULL) 525 continue; 526 pg = portal_group_find(conf, port->ctld_portal_group_name); 527 if (pg == NULL) { 528#if 0 529 log_debugx("found new kernel portal group %s for CTL port %ld", 530 port->ctld_portal_group_name, port->port_id); 531#endif 532 pg = portal_group_new(conf, port->ctld_portal_group_name); 533 if (pg == NULL) { 534 log_warnx("portal_group_new failed"); 535 continue; 536 } 537 } 538 pg->pg_tag = port->cfiscsi_portal_group_tag; 539 cp = port_new(conf, targ, pg); 540 if (cp == NULL) { 541 log_warnx("port_new failed"); 542 continue; 543 } 544 cp->p_ctl_port = port->port_id; |
|
517 } 518 519 STAILQ_FOREACH(lun, &devlist.lun_list, links) { 520 struct cctl_lun_nv *nv; 521 522 if (lun->ctld_name == NULL) { 523 log_debugx("CTL lun %ju wasn't managed by ctld; " 524 "ignoring", (uintmax_t)lun->lun_id); --- 274 unchanged lines hidden (view full) --- 799 800 if (req.status != CTL_ISCSI_OK) { 801 log_errx(1, "error returned from CTL iSCSI handoff request: " 802 "%s; dropping connection", req.error_str); 803 } 804} 805 806int | 545 } 546 547 STAILQ_FOREACH(lun, &devlist.lun_list, links) { 548 struct cctl_lun_nv *nv; 549 550 if (lun->ctld_name == NULL) { 551 log_debugx("CTL lun %ju wasn't managed by ctld; " 552 "ignoring", (uintmax_t)lun->lun_id); --- 274 unchanged lines hidden (view full) --- 827 828 if (req.status != CTL_ISCSI_OK) { 829 log_errx(1, "error returned from CTL iSCSI handoff request: " 830 "%s; dropping connection", req.error_str); 831 } 832} 833 834int |
807kernel_port_add(struct target *targ) | 835kernel_port_add(struct port *port) |
808{ 809 struct ctl_port_entry entry; 810 struct ctl_req req; 811 struct ctl_lun_map lm; | 836{ 837 struct ctl_port_entry entry; 838 struct ctl_req req; 839 struct ctl_lun_map lm; |
840 struct target *targ = port->p_target; 841 struct portal_group *pg = port->p_portal_group; |
|
812 char tagstr[16]; | 842 char tagstr[16]; |
813 int error, i; | 843 int error, i, n; |
814 815 /* Create iSCSI port. */ 816 bzero(&req, sizeof(req)); 817 strlcpy(req.driver, "iscsi", sizeof(req.driver)); 818 req.reqtype = CTL_REQ_CREATE; | 844 845 /* Create iSCSI port. */ 846 bzero(&req, sizeof(req)); 847 strlcpy(req.driver, "iscsi", sizeof(req.driver)); 848 req.reqtype = CTL_REQ_CREATE; |
819 req.num_args = 4; | |
820 req.args = malloc(req.num_args * sizeof(*req.args)); | 849 req.args = malloc(req.num_args * sizeof(*req.args)); |
821 req.args[0].namelen = sizeof("port_id"); 822 req.args[0].name = __DECONST(char *, "port_id"); 823 req.args[0].vallen = sizeof(targ->t_ctl_port); 824 req.args[0].value = &targ->t_ctl_port; 825 req.args[0].flags = CTL_BEARG_WR; 826 str_arg(&req.args[1], "cfiscsi_target", targ->t_name); 827 snprintf(tagstr, sizeof(tagstr), "%d", targ->t_portal_group->pg_tag); 828 str_arg(&req.args[2], "cfiscsi_portal_group_tag", tagstr); | 850 n = 0; 851 req.args[n].namelen = sizeof("port_id"); 852 req.args[n].name = __DECONST(char *, "port_id"); 853 req.args[n].vallen = sizeof(port->p_ctl_port); 854 req.args[n].value = &port->p_ctl_port; 855 req.args[n++].flags = CTL_BEARG_WR; 856 str_arg(&req.args[n++], "cfiscsi_target", targ->t_name); 857 snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag); 858 str_arg(&req.args[n++], "cfiscsi_portal_group_tag", tagstr); |
829 if (targ->t_alias) | 859 if (targ->t_alias) |
830 str_arg(&req.args[3], "cfiscsi_target_alias", targ->t_alias); 831 else 832 req.num_args--; | 860 str_arg(&req.args[n++], "cfiscsi_target_alias", targ->t_alias); 861 str_arg(&req.args[n++], "ctld_portal_group_name", pg->pg_name); 862 req.num_args = n; |
833 error = ioctl(ctl_fd, CTL_PORT_REQ, &req); 834 free(req.args); 835 if (error != 0) { 836 log_warn("error issuing CTL_PORT_REQ ioctl"); 837 return (1); 838 } 839 if (req.status == CTL_LUN_ERROR) { 840 log_warnx("error returned from port creation request: %s", 841 req.error_str); 842 return (1); 843 } 844 if (req.status != CTL_LUN_OK) { 845 log_warnx("unknown port creation request status %d", 846 req.status); 847 return (1); 848 } 849 850 /* Explicitly enable mapping to block any access except allowed. */ | 863 error = ioctl(ctl_fd, CTL_PORT_REQ, &req); 864 free(req.args); 865 if (error != 0) { 866 log_warn("error issuing CTL_PORT_REQ ioctl"); 867 return (1); 868 } 869 if (req.status == CTL_LUN_ERROR) { 870 log_warnx("error returned from port creation request: %s", 871 req.error_str); 872 return (1); 873 } 874 if (req.status != CTL_LUN_OK) { 875 log_warnx("unknown port creation request status %d", 876 req.status); 877 return (1); 878 } 879 880 /* Explicitly enable mapping to block any access except allowed. */ |
851 lm.port = targ->t_ctl_port; | 881 lm.port = port->p_ctl_port; |
852 lm.plun = UINT32_MAX; 853 lm.lun = 0; 854 error = ioctl(ctl_fd, CTL_LUN_MAP, &lm); 855 if (error != 0) 856 log_warn("CTL_LUN_MAP ioctl failed"); 857 858 /* Map configured LUNs */ 859 for (i = 0; i < MAX_LUNS; i++) { 860 if (targ->t_luns[i] == NULL) 861 continue; | 882 lm.plun = UINT32_MAX; 883 lm.lun = 0; 884 error = ioctl(ctl_fd, CTL_LUN_MAP, &lm); 885 if (error != 0) 886 log_warn("CTL_LUN_MAP ioctl failed"); 887 888 /* Map configured LUNs */ 889 for (i = 0; i < MAX_LUNS; i++) { 890 if (targ->t_luns[i] == NULL) 891 continue; |
862 lm.port = targ->t_ctl_port; | 892 lm.port = port->p_ctl_port; |
863 lm.plun = i; 864 lm.lun = targ->t_luns[i]->l_ctl_lun; 865 error = ioctl(ctl_fd, CTL_LUN_MAP, &lm); 866 if (error != 0) 867 log_warn("CTL_LUN_MAP ioctl failed"); 868 } 869 870 /* Enable port */ 871 bzero(&entry, sizeof(entry)); | 893 lm.plun = i; 894 lm.lun = targ->t_luns[i]->l_ctl_lun; 895 error = ioctl(ctl_fd, CTL_LUN_MAP, &lm); 896 if (error != 0) 897 log_warn("CTL_LUN_MAP ioctl failed"); 898 } 899 900 /* Enable port */ 901 bzero(&entry, sizeof(entry)); |
872 entry.targ_port = targ->t_ctl_port; | 902 entry.targ_port = port->p_ctl_port; |
873 error = ioctl(ctl_fd, CTL_ENABLE_PORT, &entry); 874 if (error != 0) { 875 log_warn("CTL_ENABLE_PORT ioctl failed"); 876 return (-1); 877 } 878 879 return (0); 880} 881 882int | 903 error = ioctl(ctl_fd, CTL_ENABLE_PORT, &entry); 904 if (error != 0) { 905 log_warn("CTL_ENABLE_PORT ioctl failed"); 906 return (-1); 907 } 908 909 return (0); 910} 911 912int |
883kernel_port_update(struct target *targ) | 913kernel_port_update(struct port *port) |
884{ 885 struct ctl_lun_map lm; | 914{ 915 struct ctl_lun_map lm; |
916 struct target *targ = port->p_target; |
|
886 int error, i; 887 888 /* Map configured LUNs and unmap others */ 889 for (i = 0; i < MAX_LUNS; i++) { | 917 int error, i; 918 919 /* Map configured LUNs and unmap others */ 920 for (i = 0; i < MAX_LUNS; i++) { |
890 lm.port = targ->t_ctl_port; | 921 lm.port = port->p_ctl_port; |
891 lm.plun = i; 892 if (targ->t_luns[i] == NULL) 893 lm.lun = UINT32_MAX; 894 else 895 lm.lun = targ->t_luns[i]->l_ctl_lun; 896 error = ioctl(ctl_fd, CTL_LUN_MAP, &lm); 897 if (error != 0) 898 log_warn("CTL_LUN_MAP ioctl failed"); 899 } 900 return (0); 901} 902 903int | 922 lm.plun = i; 923 if (targ->t_luns[i] == NULL) 924 lm.lun = UINT32_MAX; 925 else 926 lm.lun = targ->t_luns[i]->l_ctl_lun; 927 error = ioctl(ctl_fd, CTL_LUN_MAP, &lm); 928 if (error != 0) 929 log_warn("CTL_LUN_MAP ioctl failed"); 930 } 931 return (0); 932} 933 934int |
904kernel_port_remove(struct target *targ) | 935kernel_port_remove(struct port *port) |
905{ 906 struct ctl_req req; 907 char tagstr[16]; | 936{ 937 struct ctl_req req; 938 char tagstr[16]; |
939 struct target *targ = port->p_target; 940 struct portal_group *pg = port->p_portal_group; |
|
908 int error; 909 910 bzero(&req, sizeof(req)); 911 strlcpy(req.driver, "iscsi", sizeof(req.driver)); 912 req.reqtype = CTL_REQ_REMOVE; 913 req.num_args = 2; 914 req.args = malloc(req.num_args * sizeof(*req.args)); 915 str_arg(&req.args[0], "cfiscsi_target", targ->t_name); | 941 int error; 942 943 bzero(&req, sizeof(req)); 944 strlcpy(req.driver, "iscsi", sizeof(req.driver)); 945 req.reqtype = CTL_REQ_REMOVE; 946 req.num_args = 2; 947 req.args = malloc(req.num_args * sizeof(*req.args)); 948 str_arg(&req.args[0], "cfiscsi_target", targ->t_name); |
916 snprintf(tagstr, sizeof(tagstr), "%d", targ->t_portal_group->pg_tag); | 949 snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag); |
917 str_arg(&req.args[1], "cfiscsi_portal_group_tag", tagstr); 918 919 error = ioctl(ctl_fd, CTL_PORT_REQ, &req); 920 free(req.args); 921 if (error != 0) { 922 log_warn("error issuing CTL_PORT_REQ ioctl"); 923 return (1); 924 } --- 153 unchanged lines hidden --- | 950 str_arg(&req.args[1], "cfiscsi_portal_group_tag", tagstr); 951 952 error = ioctl(ctl_fd, CTL_PORT_REQ, &req); 953 free(req.args); 954 if (error != 0) { 955 log_warn("error issuing CTL_PORT_REQ ioctl"); 956 return (1); 957 } --- 153 unchanged lines hidden --- |