Date: Wed, 18 Jun 2014 17:13:18 +0000 (UTC) From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r267610 - head/sys/cam/ctl Message-ID: <201406181713.s5IHDIYw060298@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: trasz Date: Wed Jun 18 17:13:18 2014 New Revision: 267610 URL: http://svnweb.freebsd.org/changeset/base/267610 Log: Rework session termination in iSCSI target to actually wait for any outstanding commands to be properly aborted by CTL. Without it, in some cases (such as files backing the LUNs stored on failing disk drives), terminating a busy session would result in panic. Reviewed by: mav@ (earlier version) Sponsored by: The FreeBSD Foundation Modified: head/sys/cam/ctl/ctl_frontend_iscsi.c Modified: head/sys/cam/ctl/ctl_frontend_iscsi.c ============================================================================== --- head/sys/cam/ctl/ctl_frontend_iscsi.c Wed Jun 18 17:04:25 2014 (r267609) +++ head/sys/cam/ctl/ctl_frontend_iscsi.c Wed Jun 18 17:13:18 2014 (r267610) @@ -1045,7 +1045,7 @@ cfiscsi_session_terminate_tasks(struct c { struct cfiscsi_data_wait *cdw, *tmpcdw; union ctl_io *io; - int error; + int error, last; #ifdef notyet io = ctl_alloc_io(cs->cs_target->ct_softc->fe.ctl_pool_ref); @@ -1102,12 +1102,31 @@ cfiscsi_session_terminate_tasks(struct c CFISCSI_SESSION_DEBUG(cs, "removing csw for initiator task tag " "0x%x", cdw->cdw_initiator_task_tag); #endif + /* + * Set nonzero port status; this prevents backends from + * assuming that the data transfer actually succeeded + * and writing uninitialized data to disk. + */ + cdw->cdw_ctl_io->scsiio.io_hdr.port_status = 42; cdw->cdw_ctl_io->scsiio.be_move_done(cdw->cdw_ctl_io); TAILQ_REMOVE(&cs->cs_waiting_for_data_out, cdw, cdw_next); uma_zfree(cfiscsi_data_wait_zone, cdw); } CFISCSI_SESSION_UNLOCK(cs); #endif + + /* + * Wait for CTL to terminate all the tasks. + */ + for (;;) { + refcount_acquire(&cs->cs_outstanding_ctl_pdus); + last = refcount_release(&cs->cs_outstanding_ctl_pdus); + if (last != 0) + break; + CFISCSI_SESSION_WARN(cs, "waiting for CTL to terminate tasks, " + "%d remaining", cs->cs_outstanding_ctl_pdus); + pause("cfiscsi_terminate", 1); + } } static void @@ -1124,19 +1143,22 @@ cfiscsi_maintenance_thread(void *arg) CFISCSI_SESSION_UNLOCK(cs); if (cs->cs_terminating) { - cfiscsi_session_terminate_tasks(cs); - callout_drain(&cs->cs_callout); + /* + * We used to wait up to 30 seconds to deliver queued + * PDUs to the initiator. We also tried hard to deliver + * SCSI Responses for the aborted PDUs. We don't do + * that anymore. We might need to revisit that. + */ + callout_drain(&cs->cs_callout); icl_conn_shutdown(cs->cs_conn); icl_conn_close(cs->cs_conn); /* - * XXX: We used to wait up to 30 seconds to deliver queued PDUs - * to the initiator. We also tried hard to deliver SCSI Responses - * for the aborted PDUs. We don't do that anymore. We might need - * to revisit that. + * At this point ICL receive thread is no longer + * running; no new tasks can be queued. */ - + cfiscsi_session_terminate_tasks(cs); cfiscsi_session_delete(cs); kthread_exit(); return;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406181713.s5IHDIYw060298>