Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Jul 2014 17:57:59 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r268328 - in head: sys/cam/ctl usr.sbin/ctld
Message-ID:  <201407061757.s66HvxtG028322@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sun Jul  6 17:57:59 2014
New Revision: 268328
URL: http://svnweb.freebsd.org/changeset/base/268328

Log:
  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:
  head/sys/cam/ctl/ctl.c
  head/sys/cam/ctl/ctl_frontend.h
  head/sys/cam/ctl/ctl_frontend_iscsi.c
  head/usr.sbin/ctld/kernel.c

Modified: head/sys/cam/ctl/ctl.c
==============================================================================
--- head/sys/cam/ctl/ctl.c	Sun Jul  6 17:42:38 2014	(r268327)
+++ head/sys/cam/ctl/ctl.c	Sun Jul  6 17:57:59 2014	(r268328)
@@ -3252,6 +3252,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: head/sys/cam/ctl/ctl_frontend.h
==============================================================================
--- head/sys/cam/ctl/ctl_frontend.h	Sun Jul  6 17:42:38 2014	(r268327)
+++ head/sys/cam/ctl/ctl_frontend.h	Sun Jul  6 17:57:59 2014	(r268328)
@@ -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: head/sys/cam/ctl/ctl_frontend_iscsi.c
==============================================================================
--- head/sys/cam/ctl/ctl_frontend_iscsi.c	Sun Jul  6 17:42:38 2014	(r268327)
+++ head/sys/cam/ctl/ctl_frontend_iscsi.c	Sun Jul  6 17:57:59 2014	(r268328)
@@ -145,6 +145,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,
@@ -1411,6 +1412,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)
 {
@@ -1993,6 +2005,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: head/usr.sbin/ctld/kernel.c
==============================================================================
--- head/usr.sbin/ctld/kernel.c	Sun Jul  6 17:42:38 2014	(r268327)
+++ head/usr.sbin/ctld/kernel.c	Sun Jul  6 17:57:59 2014	(r268328)
@@ -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) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407061757.s66HvxtG028322>