Deleted Added
sdiff udiff text old ( 279006 ) new ( 279055 )
full compact
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 279055 2015-02-20 17:09:49Z 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;
124 char *port_name;
125 int cfiscsi_state;
126 char *cfiscsi_target;
127 uint16_t cfiscsi_portal_group_tag;
128 char *ctld_portal_group_name;
129 STAILQ_HEAD(,cctl_lun_nv) attr_list;
130 STAILQ_ENTRY(cctl_port) links;
131};
132

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

326 free(str);
327 str = NULL;
328 }
329
330 sbuf_delete(devlist->cur_sb[devlist->level]);
331 devlist->cur_sb[devlist->level] = NULL;
332 devlist->level--;
333
334 if (strcmp(name, "port_name") == 0) {
335 cur_port->port_name = str;
336 str = NULL;
337 } else if (strcmp(name, "cfiscsi_target") == 0) {
338 cur_port->cfiscsi_target = str;
339 str = NULL;
340 } else if (strcmp(name, "cfiscsi_state") == 0) {
341 cur_port->cfiscsi_state = strtoul(str, NULL, 0);
342 } else if (strcmp(name, "cfiscsi_portal_group_tag") == 0) {
343 cur_port->cfiscsi_portal_group_tag = strtoul(str, NULL, 0);
344 } else if (strcmp(name, "ctld_portal_group_name") == 0) {
345 cur_port->ctld_portal_group_name = str;

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

377}
378
379struct conf *
380conf_new_from_kernel(void)
381{
382 struct conf *conf = NULL;
383 struct target *targ;
384 struct portal_group *pg;
385 struct pport *pp;
386 struct port *cp;
387 struct lun *cl;
388 struct lun_option *lo;
389 struct ctl_lun_list list;
390 struct cctl_devlist_data devlist;
391 struct cctl_lun *lun;
392 struct cctl_port *port;
393 XML_Parser parser;

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

498 return (NULL);
499 }
500
501 conf = conf_new();
502
503 STAILQ_FOREACH(port, &devlist.port_list, links) {
504
505 if (port->cfiscsi_target == NULL) {
506 log_debugx("CTL port %u \"%s\" wasn't managed by ctld; ",
507 port->port_id, port->port_name);
508 pp = pport_find(conf, port->port_name);
509 if (pp == NULL) {
510#if 0
511 log_debugx("found new kernel port %u \"%s\"",
512 port->port_id, port->port_name);
513#endif
514 pp = pport_new(conf, port->port_name, port->port_id);
515 if (pp == NULL) {
516 log_warnx("pport_new failed");
517 continue;
518 }
519 }
520 continue;
521 }
522 if (port->cfiscsi_state != 1) {
523 log_debugx("CTL port %ju is not active (%d); ignoring",
524 (uintmax_t)port->port_id, port->cfiscsi_state);
525 continue;
526 }
527

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

855 struct ctl_req req;
856 struct ctl_lun_map lm;
857 struct target *targ = port->p_target;
858 struct portal_group *pg = port->p_portal_group;
859 char tagstr[16];
860 int error, i, n;
861
862 /* Create iSCSI port. */
863 if (port->p_portal_group) {
864 bzero(&req, sizeof(req));
865 strlcpy(req.driver, "iscsi", sizeof(req.driver));
866 req.reqtype = CTL_REQ_CREATE;
867 req.args = malloc(req.num_args * sizeof(*req.args));
868 n = 0;
869 req.args[n].namelen = sizeof("port_id");
870 req.args[n].name = __DECONST(char *, "port_id");
871 req.args[n].vallen = sizeof(port->p_ctl_port);
872 req.args[n].value = &port->p_ctl_port;
873 req.args[n++].flags = CTL_BEARG_WR;
874 str_arg(&req.args[n++], "cfiscsi_target", targ->t_name);
875 snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag);
876 str_arg(&req.args[n++], "cfiscsi_portal_group_tag", tagstr);
877 if (targ->t_alias)
878 str_arg(&req.args[n++], "cfiscsi_target_alias", targ->t_alias);
879 str_arg(&req.args[n++], "ctld_portal_group_name", pg->pg_name);
880 req.num_args = n;
881 error = ioctl(ctl_fd, CTL_PORT_REQ, &req);
882 free(req.args);
883 if (error != 0) {
884 log_warn("error issuing CTL_PORT_REQ ioctl");
885 return (1);
886 }
887 if (req.status == CTL_LUN_ERROR) {
888 log_warnx("error returned from port creation request: %s",
889 req.error_str);
890 return (1);
891 }
892 if (req.status != CTL_LUN_OK) {
893 log_warnx("unknown port creation request status %d",
894 req.status);
895 return (1);
896 }
897 } else if (port->p_pport)
898 port->p_ctl_port = port->p_pport->pp_ctl_port;
899
900 /* Explicitly enable mapping to block any access except allowed. */
901 lm.port = port->p_ctl_port;
902 lm.plun = UINT32_MAX;
903 lm.lun = 0;
904 error = ioctl(ctl_fd, CTL_LUN_MAP, &lm);
905 if (error != 0)
906 log_warn("CTL_LUN_MAP ioctl failed");

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

949 log_warn("CTL_LUN_MAP ioctl failed");
950 }
951 return (0);
952}
953
954int
955kernel_port_remove(struct port *port)
956{
957 struct ctl_port_entry entry;
958 struct ctl_lun_map lm;
959 struct ctl_req req;
960 char tagstr[16];
961 struct target *targ = port->p_target;
962 struct portal_group *pg = port->p_portal_group;
963 int error;
964
965 /* Disable port */
966 bzero(&entry, sizeof(entry));
967 entry.targ_port = port->p_ctl_port;
968 error = ioctl(ctl_fd, CTL_DISABLE_PORT, &entry);
969 if (error != 0) {
970 log_warn("CTL_DISABLE_PORT ioctl failed");
971 return (-1);
972 }
973
974 /* Remove iSCSI port. */
975 if (port->p_portal_group) {
976 bzero(&req, sizeof(req));
977 strlcpy(req.driver, "iscsi", sizeof(req.driver));
978 req.reqtype = CTL_REQ_REMOVE;
979 req.num_args = 2;
980 req.args = malloc(req.num_args * sizeof(*req.args));
981 str_arg(&req.args[0], "cfiscsi_target", targ->t_name);
982 snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag);
983 str_arg(&req.args[1], "cfiscsi_portal_group_tag", tagstr);
984 error = ioctl(ctl_fd, CTL_PORT_REQ, &req);
985 free(req.args);
986 if (error != 0) {
987 log_warn("error issuing CTL_PORT_REQ ioctl");
988 return (1);
989 }
990 if (req.status == CTL_LUN_ERROR) {
991 log_warnx("error returned from port removal request: %s",
992 req.error_str);
993 return (1);
994 }
995 if (req.status != CTL_LUN_OK) {
996 log_warnx("unknown port removal request status %d",
997 req.status);
998 return (1);
999 }
1000 } else {
1001 /* Disable LUN mapping. */
1002 lm.port = port->p_ctl_port;
1003 lm.plun = UINT32_MAX;
1004 lm.lun = UINT32_MAX;
1005 error = ioctl(ctl_fd, CTL_LUN_MAP, &lm);
1006 if (error != 0)
1007 log_warn("CTL_LUN_MAP ioctl failed");
1008 }
1009 return (0);
1010}
1011
1012#ifdef ICL_KERNEL_PROXY
1013void
1014kernel_listen(struct addrinfo *ai, bool iser, int portal_id)
1015{
1016 struct ctl_iscsi req;

--- 132 unchanged lines hidden ---