Module Name:    src
Committed By:   bouyer
Date:           Sun Jun 19 09:35:06 UTC 2016

Modified Files:
        src/sys/dev/ata: wd.c
        src/sys/kern: subr_autoconf.c
        src/sys/sys: device.h

Log Message:
Add a new config_detach() flag, DETACH_POWEROFF, which is set when
detaching devices at shutdown time with RB_POWERDOWN.
When detaching wd(4), put the drive in standby before detach
for DETACH_POWEROFF.
Fix PR kern/51252


To generate a diff of this commit:
cvs rdiff -u -r1.420 -r1.421 src/sys/dev/ata/wd.c
cvs rdiff -u -r1.241 -r1.242 src/sys/kern/subr_autoconf.c
cvs rdiff -u -r1.148 -r1.149 src/sys/sys/device.h

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/wd.c
diff -u src/sys/dev/ata/wd.c:1.420 src/sys/dev/ata/wd.c:1.421
--- src/sys/dev/ata/wd.c:1.420	Sun Apr 26 15:15:20 2015
+++ src/sys/dev/ata/wd.c	Sun Jun 19 09:35:06 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: wd.c,v 1.420 2015/04/26 15:15:20 mlelstv Exp $ */
+/*	$NetBSD: wd.c,v 1.421 2016/06/19 09:35:06 bouyer Exp $ */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -54,7 +54,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.420 2015/04/26 15:15:20 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.421 2016/06/19 09:35:06 bouyer Exp $");
 
 #include "opt_ata.h"
 
@@ -467,6 +467,8 @@ wddetach(device_t self, int flags)
 
 	bufq_free(sc->sc_q);
 	sc->atabus->ata_killpending(sc->drvp);
+	if (flags & DETACH_POWEROFF)
+		wd_standby(sc, AT_POLL);
 
 	splx(s);
 

Index: src/sys/kern/subr_autoconf.c
diff -u src/sys/kern/subr_autoconf.c:1.241 src/sys/kern/subr_autoconf.c:1.242
--- src/sys/kern/subr_autoconf.c:1.241	Mon Mar 28 09:50:40 2016
+++ src/sys/kern/subr_autoconf.c	Sun Jun 19 09:35:06 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.241 2016/03/28 09:50:40 skrll Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.242 2016/06/19 09:35:06 bouyer Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.241 2016/03/28 09:50:40 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.242 2016/06/19 09:35:06 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1876,14 +1876,20 @@ config_detach_all(int how)
 	static struct shutdown_state s;
 	device_t curdev;
 	bool progress = false;
+	int flags;
 
 	if ((how & (RB_NOSYNC|RB_DUMP)) != 0)
 		return false;
 
+	if ((how & RB_POWERDOWN) == RB_POWERDOWN)
+		flags = DETACH_SHUTDOWN | DETACH_POWEROFF;
+	else
+		flags = DETACH_SHUTDOWN;
+
 	for (curdev = shutdown_first(&s); curdev != NULL;
 	     curdev = shutdown_next(&s)) {
 		aprint_debug(" detaching %s, ", device_xname(curdev));
-		if (config_detach(curdev, DETACH_SHUTDOWN) == 0) {
+		if (config_detach(curdev, flags) == 0) {
 			progress = true;
 			aprint_debug("success.");
 		} else

Index: src/sys/sys/device.h
diff -u src/sys/sys/device.h:1.148 src/sys/sys/device.h:1.149
--- src/sys/sys/device.h:1.148	Mon Dec  7 11:38:46 2015
+++ src/sys/sys/device.h	Sun Jun 19 09:35:06 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.148 2015/12/07 11:38:46 pgoyette Exp $ */
+/* $NetBSD: device.h,v 1.149 2016/06/19 09:35:06 bouyer Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -349,6 +349,7 @@ struct cfattach __CONCAT(name,_ca) = {		
 #define	DETACH_FORCE	0x01		/* force detachment; hardware gone */
 #define	DETACH_QUIET	0x02		/* don't print a notice */
 #define	DETACH_SHUTDOWN	0x04		/* detach because of system shutdown */
+#define	DETACH_POWEROFF	0x08		/* going to power off; power down devices */
 
 struct cfdriver {
 	LIST_ENTRY(cfdriver) cd_list;	/* link on allcfdrivers */

Reply via email to