Deleted Added
full compact
kernel.c (288310) kernel.c (290615)
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: head/usr.sbin/ctld/kernel.c 288310 2015-09-27 13:47:28Z mav $");
38__FBSDID("$FreeBSD: head/usr.sbin/ctld/kernel.c 290615 2015-11-09 18:33:36Z 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>

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

391conf_new_from_kernel(void)
392{
393 struct conf *conf = NULL;
394 struct target *targ;
395 struct portal_group *pg;
396 struct pport *pp;
397 struct port *cp;
398 struct lun *cl;
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>

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

391conf_new_from_kernel(void)
392{
393 struct conf *conf = NULL;
394 struct target *targ;
395 struct portal_group *pg;
396 struct pport *pp;
397 struct port *cp;
398 struct lun *cl;
399 struct lun_option *lo;
399 struct option *o;
400 struct ctl_lun_list list;
401 struct cctl_devlist_data devlist;
402 struct cctl_lun *lun;
403 struct cctl_port *port;
404 XML_Parser parser;
405 char *str, *name;
406 int len, retval;
407

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

621 lun_set_ctl_lun(cl, lun->lun_id);
622
623 STAILQ_FOREACH(nv, &lun->attr_list, links) {
624 if (strcmp(nv->name, "file") == 0 ||
625 strcmp(nv->name, "dev") == 0) {
626 lun_set_path(cl, nv->value);
627 continue;
628 }
400 struct ctl_lun_list list;
401 struct cctl_devlist_data devlist;
402 struct cctl_lun *lun;
403 struct cctl_port *port;
404 XML_Parser parser;
405 char *str, *name;
406 int len, retval;
407

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

621 lun_set_ctl_lun(cl, lun->lun_id);
622
623 STAILQ_FOREACH(nv, &lun->attr_list, links) {
624 if (strcmp(nv->name, "file") == 0 ||
625 strcmp(nv->name, "dev") == 0) {
626 lun_set_path(cl, nv->value);
627 continue;
628 }
629 lo = lun_option_new(cl, nv->name, nv->value);
630 if (lo == NULL)
629 o = option_new(&cl->l_options, nv->name, nv->value);
630 if (o == NULL)
631 log_warnx("unable to add CTL lun option %s "
632 "for CTL lun %ju \"%s\"",
633 nv->name, (uintmax_t) lun->lun_id,
634 cl->l_name);
635 }
636 }
637
638 return (conf);

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

647 arg->vallen = strlen(value) + 1;
648 arg->value = __DECONST(char *, value);
649 arg->flags = CTL_BEARG_ASCII | CTL_BEARG_RD;
650}
651
652int
653kernel_lun_add(struct lun *lun)
654{
631 log_warnx("unable to add CTL lun option %s "
632 "for CTL lun %ju \"%s\"",
633 nv->name, (uintmax_t) lun->lun_id,
634 cl->l_name);
635 }
636 }
637
638 return (conf);

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

647 arg->vallen = strlen(value) + 1;
648 arg->value = __DECONST(char *, value);
649 arg->flags = CTL_BEARG_ASCII | CTL_BEARG_RD;
650}
651
652int
653kernel_lun_add(struct lun *lun)
654{
655 struct lun_option *lo;
655 struct option *o;
656 struct ctl_lun_req req;
657 int error, i, num_options;
658
659 bzero(&req, sizeof(req));
660
661 strlcpy(req.backend, lun->l_backend, sizeof(req.backend));
662 req.reqtype = CTL_LUNREQ_CREATE;
663

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

682
683 if (lun->l_device_id != NULL) {
684 strncpy(req.reqdata.create.device_id, lun->l_device_id,
685 sizeof(req.reqdata.create.device_id));
686 req.reqdata.create.flags |= CTL_LUN_FLAG_DEVID;
687 }
688
689 if (lun->l_path != NULL) {
656 struct ctl_lun_req req;
657 int error, i, num_options;
658
659 bzero(&req, sizeof(req));
660
661 strlcpy(req.backend, lun->l_backend, sizeof(req.backend));
662 req.reqtype = CTL_LUNREQ_CREATE;
663

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

682
683 if (lun->l_device_id != NULL) {
684 strncpy(req.reqdata.create.device_id, lun->l_device_id,
685 sizeof(req.reqdata.create.device_id));
686 req.reqdata.create.flags |= CTL_LUN_FLAG_DEVID;
687 }
688
689 if (lun->l_path != NULL) {
690 lo = lun_option_find(lun, "file");
691 if (lo != NULL) {
692 lun_option_set(lo, lun->l_path);
690 o = option_find(&lun->l_options, "file");
691 if (o != NULL) {
692 option_set(o, lun->l_path);
693 } else {
693 } else {
694 lo = lun_option_new(lun, "file", lun->l_path);
695 assert(lo != NULL);
694 o = option_new(&lun->l_options, "file", lun->l_path);
695 assert(o != NULL);
696 }
697 }
698
696 }
697 }
698
699 lo = lun_option_find(lun, "ctld_name");
700 if (lo != NULL) {
701 lun_option_set(lo, lun->l_name);
699 o = option_find(&lun->l_options, "ctld_name");
700 if (o != NULL) {
701 option_set(o, lun->l_name);
702 } else {
702 } else {
703 lo = lun_option_new(lun, "ctld_name", lun->l_name);
704 assert(lo != NULL);
703 o = option_new(&lun->l_options, "ctld_name", lun->l_name);
704 assert(o != NULL);
705 }
706
705 }
706
707 lo = lun_option_find(lun, "scsiname");
708 if (lo == NULL && lun->l_scsiname != NULL) {
709 lo = lun_option_new(lun, "scsiname", lun->l_scsiname);
710 assert(lo != NULL);
707 o = option_find(&lun->l_options, "scsiname");
708 if (o == NULL && lun->l_scsiname != NULL) {
709 o = option_new(&lun->l_options, "scsiname", lun->l_scsiname);
710 assert(o != NULL);
711 }
712
713 num_options = 0;
711 }
712
713 num_options = 0;
714 TAILQ_FOREACH(lo, &lun->l_options, lo_next)
714 TAILQ_FOREACH(o, &lun->l_options, o_next)
715 num_options++;
716
717 req.num_be_args = num_options;
718 if (num_options > 0) {
719 req.be_args = malloc(num_options * sizeof(*req.be_args));
720 if (req.be_args == NULL) {
721 log_warn("error allocating %zd bytes",
722 num_options * sizeof(*req.be_args));
723 return (1);
724 }
725
726 i = 0;
715 num_options++;
716
717 req.num_be_args = num_options;
718 if (num_options > 0) {
719 req.be_args = malloc(num_options * sizeof(*req.be_args));
720 if (req.be_args == NULL) {
721 log_warn("error allocating %zd bytes",
722 num_options * sizeof(*req.be_args));
723 return (1);
724 }
725
726 i = 0;
727 TAILQ_FOREACH(lo, &lun->l_options, lo_next) {
728 str_arg(&req.be_args[i], lo->lo_name, lo->lo_value);
727 TAILQ_FOREACH(o, &lun->l_options, o_next) {
728 str_arg(&req.be_args[i], o->o_name, o->o_value);
729 i++;
730 }
731 assert(i == num_options);
732 }
733
734 error = ioctl(ctl_fd, CTL_LUN_REQ, &req);
735 free(req.be_args);
736 if (error != 0) {

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

755
756 lun_set_ctl_lun(lun, req.reqdata.create.req_lun_id);
757 return (0);
758}
759
760int
761kernel_lun_modify(struct lun *lun)
762{
729 i++;
730 }
731 assert(i == num_options);
732 }
733
734 error = ioctl(ctl_fd, CTL_LUN_REQ, &req);
735 free(req.be_args);
736 if (error != 0) {

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

755
756 lun_set_ctl_lun(lun, req.reqdata.create.req_lun_id);
757 return (0);
758}
759
760int
761kernel_lun_modify(struct lun *lun)
762{
763 struct lun_option *lo;
763 struct option *o;
764 struct ctl_lun_req req;
765 int error, i, num_options;
766
767 bzero(&req, sizeof(req));
768
769 strlcpy(req.backend, lun->l_backend, sizeof(req.backend));
770 req.reqtype = CTL_LUNREQ_MODIFY;
771
772 req.reqdata.modify.lun_id = lun->l_ctl_lun;
773 req.reqdata.modify.lun_size_bytes = lun->l_size;
774
775 num_options = 0;
764 struct ctl_lun_req req;
765 int error, i, num_options;
766
767 bzero(&req, sizeof(req));
768
769 strlcpy(req.backend, lun->l_backend, sizeof(req.backend));
770 req.reqtype = CTL_LUNREQ_MODIFY;
771
772 req.reqdata.modify.lun_id = lun->l_ctl_lun;
773 req.reqdata.modify.lun_size_bytes = lun->l_size;
774
775 num_options = 0;
776 TAILQ_FOREACH(lo, &lun->l_options, lo_next)
776 TAILQ_FOREACH(o, &lun->l_options, o_next)
777 num_options++;
778
779 req.num_be_args = num_options;
780 if (num_options > 0) {
781 req.be_args = malloc(num_options * sizeof(*req.be_args));
782 if (req.be_args == NULL) {
783 log_warn("error allocating %zd bytes",
784 num_options * sizeof(*req.be_args));
785 return (1);
786 }
787
788 i = 0;
777 num_options++;
778
779 req.num_be_args = num_options;
780 if (num_options > 0) {
781 req.be_args = malloc(num_options * sizeof(*req.be_args));
782 if (req.be_args == NULL) {
783 log_warn("error allocating %zd bytes",
784 num_options * sizeof(*req.be_args));
785 return (1);
786 }
787
788 i = 0;
789 TAILQ_FOREACH(lo, &lun->l_options, lo_next) {
790 str_arg(&req.be_args[i], lo->lo_name, lo->lo_value);
789 TAILQ_FOREACH(o, &lun->l_options, o_next) {
790 str_arg(&req.be_args[i], o->o_name, o->o_value);
791 i++;
792 }
793 assert(i == num_options);
794 }
795
796 error = ioctl(ctl_fd, CTL_LUN_REQ, &req);
797 free(req.be_args);
798 if (error != 0) {

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

940 log_debugx("MaxRecvDataSegment kernel limit is %zd",
941 *max_data_segment_length);
942 }
943}
944
945int
946kernel_port_add(struct port *port)
947{
791 i++;
792 }
793 assert(i == num_options);
794 }
795
796 error = ioctl(ctl_fd, CTL_LUN_REQ, &req);
797 free(req.be_args);
798 if (error != 0) {

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

940 log_debugx("MaxRecvDataSegment kernel limit is %zd",
941 *max_data_segment_length);
942 }
943}
944
945int
946kernel_port_add(struct port *port)
947{
948 struct option *o;
948 struct ctl_port_entry entry;
949 struct ctl_req req;
950 struct ctl_lun_map lm;
951 struct target *targ = port->p_target;
952 struct portal_group *pg = port->p_portal_group;
953 char tagstr[16];
954 int error, i, n;
955
956 /* Create iSCSI port. */
957 if (port->p_portal_group) {
958 bzero(&req, sizeof(req));
959 strlcpy(req.driver, "iscsi", sizeof(req.driver));
960 req.reqtype = CTL_REQ_CREATE;
961 req.num_args = 5;
949 struct ctl_port_entry entry;
950 struct ctl_req req;
951 struct ctl_lun_map lm;
952 struct target *targ = port->p_target;
953 struct portal_group *pg = port->p_portal_group;
954 char tagstr[16];
955 int error, i, n;
956
957 /* Create iSCSI port. */
958 if (port->p_portal_group) {
959 bzero(&req, sizeof(req));
960 strlcpy(req.driver, "iscsi", sizeof(req.driver));
961 req.reqtype = CTL_REQ_CREATE;
962 req.num_args = 5;
963 TAILQ_FOREACH(o, &pg->pg_options, o_next)
964 req.num_args++;
962 req.args = malloc(req.num_args * sizeof(*req.args));
963 if (req.args == NULL)
964 log_err(1, "malloc");
965 n = 0;
966 req.args[n].namelen = sizeof("port_id");
967 req.args[n].name = __DECONST(char *, "port_id");
968 req.args[n].vallen = sizeof(port->p_ctl_port);
969 req.args[n].value = &port->p_ctl_port;
970 req.args[n++].flags = CTL_BEARG_WR;
971 str_arg(&req.args[n++], "cfiscsi_target", targ->t_name);
972 snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag);
973 str_arg(&req.args[n++], "cfiscsi_portal_group_tag", tagstr);
974 if (targ->t_alias)
975 str_arg(&req.args[n++], "cfiscsi_target_alias", targ->t_alias);
976 str_arg(&req.args[n++], "ctld_portal_group_name", pg->pg_name);
965 req.args = malloc(req.num_args * sizeof(*req.args));
966 if (req.args == NULL)
967 log_err(1, "malloc");
968 n = 0;
969 req.args[n].namelen = sizeof("port_id");
970 req.args[n].name = __DECONST(char *, "port_id");
971 req.args[n].vallen = sizeof(port->p_ctl_port);
972 req.args[n].value = &port->p_ctl_port;
973 req.args[n++].flags = CTL_BEARG_WR;
974 str_arg(&req.args[n++], "cfiscsi_target", targ->t_name);
975 snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag);
976 str_arg(&req.args[n++], "cfiscsi_portal_group_tag", tagstr);
977 if (targ->t_alias)
978 str_arg(&req.args[n++], "cfiscsi_target_alias", targ->t_alias);
979 str_arg(&req.args[n++], "ctld_portal_group_name", pg->pg_name);
980 TAILQ_FOREACH(o, &pg->pg_options, o_next)
981 str_arg(&req.args[n++], o->o_name, o->o_value);
977 req.num_args = n;
978 error = ioctl(ctl_fd, CTL_PORT_REQ, &req);
979 free(req.args);
980 if (error != 0) {
981 log_warn("error issuing CTL_PORT_REQ ioctl");
982 return (1);
983 }
984 if (req.status == CTL_LUN_ERROR) {

--- 283 unchanged lines hidden ---
982 req.num_args = n;
983 error = ioctl(ctl_fd, CTL_PORT_REQ, &req);
984 free(req.args);
985 if (error != 0) {
986 log_warn("error issuing CTL_PORT_REQ ioctl");
987 return (1);
988 }
989 if (req.status == CTL_LUN_ERROR) {

--- 283 unchanged lines hidden ---