Deleted Added
full compact
38c38
< __FBSDID("$FreeBSD: stable/10/usr.sbin/ctld/kernel.c 279006 2015-02-19 14:52:01Z mav $");
---
> __FBSDID("$FreeBSD: stable/10/usr.sbin/ctld/kernel.c 279055 2015-02-20 17:09:49Z mav $");
123a124
> char *port_name;
333c334,337
< if (strcmp(name, "cfiscsi_target") == 0) {
---
> if (strcmp(name, "port_name") == 0) {
> cur_port->port_name = str;
> str = NULL;
> } else if (strcmp(name, "cfiscsi_target") == 0) {
380a385
> struct pport *pp;
501,502c506,519
< log_debugx("CTL port %ju wasn't managed by ctld; "
< "ignoring", (uintmax_t)port->port_id);
---
> log_debugx("CTL port %u \"%s\" wasn't managed by ctld; ",
> port->port_id, port->port_name);
> pp = pport_find(conf, port->port_name);
> if (pp == NULL) {
> #if 0
> log_debugx("found new kernel port %u \"%s\"",
> port->port_id, port->port_name);
> #endif
> pp = pport_new(conf, port->port_name, port->port_id);
> if (pp == NULL) {
> log_warnx("pport_new failed");
> continue;
> }
> }
846,878c863,898
< bzero(&req, sizeof(req));
< strlcpy(req.driver, "iscsi", sizeof(req.driver));
< req.reqtype = CTL_REQ_CREATE;
< req.args = malloc(req.num_args * sizeof(*req.args));
< n = 0;
< req.args[n].namelen = sizeof("port_id");
< req.args[n].name = __DECONST(char *, "port_id");
< req.args[n].vallen = sizeof(port->p_ctl_port);
< req.args[n].value = &port->p_ctl_port;
< req.args[n++].flags = CTL_BEARG_WR;
< str_arg(&req.args[n++], "cfiscsi_target", targ->t_name);
< snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag);
< str_arg(&req.args[n++], "cfiscsi_portal_group_tag", tagstr);
< if (targ->t_alias)
< str_arg(&req.args[n++], "cfiscsi_target_alias", targ->t_alias);
< str_arg(&req.args[n++], "ctld_portal_group_name", pg->pg_name);
< req.num_args = n;
< error = ioctl(ctl_fd, CTL_PORT_REQ, &req);
< free(req.args);
< if (error != 0) {
< log_warn("error issuing CTL_PORT_REQ ioctl");
< return (1);
< }
< if (req.status == CTL_LUN_ERROR) {
< log_warnx("error returned from port creation request: %s",
< req.error_str);
< return (1);
< }
< if (req.status != CTL_LUN_OK) {
< log_warnx("unknown port creation request status %d",
< req.status);
< return (1);
< }
---
> if (port->p_portal_group) {
> bzero(&req, sizeof(req));
> strlcpy(req.driver, "iscsi", sizeof(req.driver));
> req.reqtype = CTL_REQ_CREATE;
> req.args = malloc(req.num_args * sizeof(*req.args));
> n = 0;
> req.args[n].namelen = sizeof("port_id");
> req.args[n].name = __DECONST(char *, "port_id");
> req.args[n].vallen = sizeof(port->p_ctl_port);
> req.args[n].value = &port->p_ctl_port;
> req.args[n++].flags = CTL_BEARG_WR;
> str_arg(&req.args[n++], "cfiscsi_target", targ->t_name);
> snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag);
> str_arg(&req.args[n++], "cfiscsi_portal_group_tag", tagstr);
> if (targ->t_alias)
> str_arg(&req.args[n++], "cfiscsi_target_alias", targ->t_alias);
> str_arg(&req.args[n++], "ctld_portal_group_name", pg->pg_name);
> req.num_args = n;
> error = ioctl(ctl_fd, CTL_PORT_REQ, &req);
> free(req.args);
> if (error != 0) {
> log_warn("error issuing CTL_PORT_REQ ioctl");
> return (1);
> }
> if (req.status == CTL_LUN_ERROR) {
> log_warnx("error returned from port creation request: %s",
> req.error_str);
> return (1);
> }
> if (req.status != CTL_LUN_OK) {
> log_warnx("unknown port creation request status %d",
> req.status);
> return (1);
> }
> } else if (port->p_pport)
> port->p_ctl_port = port->p_pport->pp_ctl_port;
936a957,958
> struct ctl_port_entry entry;
> struct ctl_lun_map lm;
943,953c965,968
< bzero(&req, sizeof(req));
< strlcpy(req.driver, "iscsi", sizeof(req.driver));
< req.reqtype = CTL_REQ_REMOVE;
< req.num_args = 2;
< req.args = malloc(req.num_args * sizeof(*req.args));
< str_arg(&req.args[0], "cfiscsi_target", targ->t_name);
< snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag);
< str_arg(&req.args[1], "cfiscsi_portal_group_tag", tagstr);
<
< error = ioctl(ctl_fd, CTL_PORT_REQ, &req);
< free(req.args);
---
> /* Disable port */
> bzero(&entry, sizeof(entry));
> entry.targ_port = port->p_ctl_port;
> error = ioctl(ctl_fd, CTL_DISABLE_PORT, &entry);
955,956c970,971
< log_warn("error issuing CTL_PORT_REQ ioctl");
< return (1);
---
> log_warn("CTL_DISABLE_PORT ioctl failed");
> return (-1);
959,962c974,1007
< if (req.status == CTL_LUN_ERROR) {
< log_warnx("error returned from port removal request: %s",
< req.error_str);
< return (1);
---
> /* Remove iSCSI port. */
> if (port->p_portal_group) {
> bzero(&req, sizeof(req));
> strlcpy(req.driver, "iscsi", sizeof(req.driver));
> req.reqtype = CTL_REQ_REMOVE;
> req.num_args = 2;
> req.args = malloc(req.num_args * sizeof(*req.args));
> str_arg(&req.args[0], "cfiscsi_target", targ->t_name);
> snprintf(tagstr, sizeof(tagstr), "%d", pg->pg_tag);
> str_arg(&req.args[1], "cfiscsi_portal_group_tag", tagstr);
> error = ioctl(ctl_fd, CTL_PORT_REQ, &req);
> free(req.args);
> if (error != 0) {
> log_warn("error issuing CTL_PORT_REQ ioctl");
> return (1);
> }
> if (req.status == CTL_LUN_ERROR) {
> log_warnx("error returned from port removal request: %s",
> req.error_str);
> return (1);
> }
> if (req.status != CTL_LUN_OK) {
> log_warnx("unknown port removal request status %d",
> req.status);
> return (1);
> }
> } else {
> /* Disable LUN mapping. */
> lm.port = port->p_ctl_port;
> lm.plun = UINT32_MAX;
> lm.lun = UINT32_MAX;
> error = ioctl(ctl_fd, CTL_LUN_MAP, &lm);
> if (error != 0)
> log_warn("CTL_LUN_MAP ioctl failed");
964,970d1008
<
< if (req.status != CTL_LUN_OK) {
< log_warnx("unknown port removal request status %d",
< req.status);
< return (1);
< }
<