Module Name: src Committed By: jdolecek Date: Tue Dec 11 23:06:30 UTC 2018
Modified Files: src/sys/dev/ata: ata.c Log Message: in atabus_detach(), shutdown the channel thread only after all the children successfully detach; this is especially important for atapibus, which needs the thread to execute commands fixes hang on poweroff with root on ATAPI cd(4), reported by Christoph Badura To generate a diff of this commit: cvs rdiff -u -r1.146 -r1.147 src/sys/dev/ata/ata.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ata/ata.c diff -u src/sys/dev/ata/ata.c:1.146 src/sys/dev/ata/ata.c:1.147 --- src/sys/dev/ata/ata.c:1.146 Mon Nov 12 18:51:01 2018 +++ src/sys/dev/ata/ata.c Tue Dec 11 23:06:30 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ata.c,v 1.146 2018/11/12 18:51:01 jdolecek Exp $ */ +/* $NetBSD: ata.c,v 1.147 2018/12/11 23:06:30 jdolecek Exp $ */ /* * Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved. @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.146 2018/11/12 18:51:01 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.147 2018/12/11 23:06:30 jdolecek Exp $"); #include "opt_ata.h" @@ -630,15 +630,6 @@ atabus_detach(device_t self, int flags) device_t dev = NULL; int i, error = 0; - /* Shutdown the channel. */ - ata_channel_lock(chp); - chp->ch_flags |= ATACH_SHUTDOWN; - while (chp->ch_thread != NULL) { - cv_signal(&chp->ch_thr_idle); - cv_wait(&chp->ch_thr_idle, &chp->ch_lock); - } - ata_channel_unlock(chp); - /* * Detach atapibus and its children. */ @@ -673,6 +664,16 @@ atabus_detach(device_t self, int flags) KASSERT(chp->ch_drive[i].drive_type == 0); } } + + /* Shutdown the channel. */ + ata_channel_lock(chp); + chp->ch_flags |= ATACH_SHUTDOWN; + while (chp->ch_thread != NULL) { + cv_signal(&chp->ch_thr_idle); + cv_wait(&chp->ch_thr_idle, &chp->ch_lock); + } + ata_channel_unlock(chp); + atabus_free_drives(chp); out: