svn commit: r268688 - in stable/10: sys/cam/ctl usr.sbin/ctld

Alexander Motin mav at FreeBSD.org
Tue Jul 15 17:10:49 UTC 2014


Author: mav
Date: Tue Jul 15 17:10:48 2014
New Revision: 268688
URL: http://svnweb.freebsd.org/changeset/base/268688

Log:
  MFC r268328:
  Close race in r268291 between port destruction, delayed by sessions
  teardown, and new port creation during `service ctld restart`.
  
  Close it by returning iSCSI port internal state, that allows to identify
  dying ports, which should not be counted as existing, from really alive.

Modified:
  stable/10/sys/cam/ctl/ctl.c
  stable/10/sys/cam/ctl/ctl_frontend.h
  stable/10/sys/cam/ctl/ctl_frontend_iscsi.c
  stable/10/usr.sbin/ctld/kernel.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cam/ctl/ctl.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl.c	Tue Jul 15 17:09:52 2014	(r268687)
+++ stable/10/sys/cam/ctl/ctl.c	Tue Jul 15 17:10:48 2014	(r268688)
@@ -3254,6 +3254,11 @@ ctl_ioctl(struct cdev *dev, u_long cmd, 
 			if (retval != 0)
 				break;
 
+			if (port->port_info != NULL) {
+				retval = port->port_info(port->onoff_arg, sb);
+				if (retval != 0)
+					break;
+			}
 			STAILQ_FOREACH(opt, &port->options, links) {
 				retval = sbuf_printf(sb, "\t<%s>%s</%s>\n",
 				    opt->name, opt->value, opt->name);

Modified: stable/10/sys/cam/ctl/ctl_frontend.h
==============================================================================
--- stable/10/sys/cam/ctl/ctl_frontend.h	Tue Jul 15 17:09:52 2014	(r268687)
+++ stable/10/sys/cam/ctl/ctl_frontend.h	Tue Jul 15 17:10:48 2014	(r268688)
@@ -49,6 +49,7 @@ typedef enum {
 typedef int (*fe_init_t)(void);
 typedef void (*fe_shutdown_t)(void);
 typedef void (*port_func_t)(void *onoff_arg);
+typedef int (*port_info_func_t)(void *onoff_arg, struct sbuf *sb);
 typedef	int (*lun_func_t)(void *arg, struct ctl_id targ_id, int lun_id);
 typedef	uint32_t (*lun_map_func_t)(void *arg, uint32_t lun_id);
 typedef int (*fe_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
@@ -214,6 +215,7 @@ struct ctl_port {
 	int		virtual_port;		/* passed to CTL */
 	port_func_t	port_online;		/* passed to CTL */
 	port_func_t	port_offline;		/* passed to CTL */
+	port_info_func_t port_info;		/* passed to CTL */
 	void		*onoff_arg;		/* passed to CTL */
 	lun_func_t	lun_enable;		/* passed to CTL */
 	lun_func_t	lun_disable;		/* passed to CTL */

Modified: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl_frontend_iscsi.c	Tue Jul 15 17:09:52 2014	(r268687)
+++ stable/10/sys/cam/ctl/ctl_frontend_iscsi.c	Tue Jul 15 17:10:48 2014	(r268688)
@@ -149,6 +149,7 @@ SYSCTL_INT(_kern_cam_ctl_iscsi, OID_AUTO
 int		cfiscsi_init(void);
 static void	cfiscsi_online(void *arg);
 static void	cfiscsi_offline(void *arg);
+static int	cfiscsi_info(void *arg, struct sbuf *sb);
 static int	cfiscsi_lun_enable(void *arg,
 		    struct ctl_id target_id, int lun_id);
 static int	cfiscsi_lun_disable(void *arg,
@@ -1415,6 +1416,17 @@ cfiscsi_offline(void *arg)
 #endif
 }
 
+static int
+cfiscsi_info(void *arg, struct sbuf *sb)
+{
+	struct cfiscsi_target *ct = (struct cfiscsi_target *)arg;
+	int retval;
+
+	retval = sbuf_printf(sb, "\t<cfiscsi_state>%d</cfiscsi_state>\n",
+	    ct->ct_state);
+	return (retval);
+}
+
 static void
 cfiscsi_ioctl_handoff(struct ctl_iscsi *ci)
 {
@@ -1997,6 +2009,7 @@ cfiscsi_ioctl_port_create(struct ctl_req
 	port->virtual_port = strtoul(tag, NULL, 0);
 	port->port_online = cfiscsi_online;
 	port->port_offline = cfiscsi_offline;
+	port->port_info = cfiscsi_info;
 	port->onoff_arg = ct;
 	port->lun_enable = cfiscsi_lun_enable;
 	port->lun_disable = cfiscsi_lun_disable;

Modified: stable/10/usr.sbin/ctld/kernel.c
==============================================================================
--- stable/10/usr.sbin/ctld/kernel.c	Tue Jul 15 17:09:52 2014	(r268687)
+++ stable/10/usr.sbin/ctld/kernel.c	Tue Jul 15 17:10:48 2014	(r268688)
@@ -120,6 +120,7 @@ struct cctl_lun {
 
 struct cctl_port {
 	uint32_t port_id;
+	int cfiscsi_status;
 	char *cfiscsi_target;
 	uint16_t cfiscsi_portal_group_tag;
 	STAILQ_HEAD(,cctl_lun_nv) attr_list;
@@ -332,6 +333,8 @@ cctl_end_pelement(void *user_data, const
 	if (strcmp(name, "cfiscsi_target") == 0) {
 		cur_port->cfiscsi_target = str;
 		str = NULL;
+	} else if (strcmp(name, "cfiscsi_status") == 0) {
+		cur_port->cfiscsi_status = strtoul(str, NULL, 0);
 	} else if (strcmp(name, "cfiscsi_portal_group_tag") == 0) {
 		cur_port->cfiscsi_portal_group_tag = strtoul(str, NULL, 0);
 	} else if (strcmp(name, "targ_port") == 0) {
@@ -494,6 +497,11 @@ retry_port:
 			    "ignoring", (uintmax_t)port->port_id);
 			continue;
 		}
+		if (port->cfiscsi_status != 1) {
+			log_debugx("CTL port %ju is not active (%d); ignoring",
+			    (uintmax_t)port->port_id, port->cfiscsi_status);
+			continue;
+		}
 
 		targ = target_find(conf, port->cfiscsi_target);
 		if (targ == NULL) {


More information about the svn-src-all mailing list