Module Name: src Committed By: dyoung Date: Fri Apr 10 17:36:42 UTC 2009
Modified Files: src/sys/dev/scsipi: sd.c sdvar.h Log Message: Use a PMF shutdown hook instead of shutdownhook_establish(). This ought to stop the crash during shutdown that yamt@ reports in kern/41182. To generate a diff of this commit: cvs rdiff -u -r1.278 -r1.279 src/sys/dev/scsipi/sd.c cvs rdiff -u -r1.31 -r1.32 src/sys/dev/scsipi/sdvar.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/scsipi/sd.c diff -u src/sys/dev/scsipi/sd.c:1.278 src/sys/dev/scsipi/sd.c:1.279 --- src/sys/dev/scsipi/sd.c:1.278 Tue Apr 7 18:35:17 2009 +++ src/sys/dev/scsipi/sd.c Fri Apr 10 17:36:42 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sd.c,v 1.278 2009/04/07 18:35:17 dyoung Exp $ */ +/* $NetBSD: sd.c,v 1.279 2009/04/10 17:36:42 dyoung Exp $ */ /*- * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc. @@ -47,7 +47,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.278 2009/04/07 18:35:17 dyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.279 2009/04/10 17:36:42 dyoung Exp $"); #include "opt_scsi.h" #include "rnd.h" @@ -101,7 +101,7 @@ static void sdrestart(void *); static void sddone(struct scsipi_xfer *, int); static bool sd_suspend(device_t PMF_FN_PROTO); -static void sd_shutdown(void *); +static bool sd_shutdown(device_t, int); static int sd_interpret_sense(struct scsipi_xfer *); static int sd_mode_sense(struct sd_softc *, u_int8_t, void *, size_t, int, @@ -305,16 +305,11 @@ * Establish a shutdown hook so that we can ensure that * our data has actually made it onto the platter at * shutdown time. Note that this relies on the fact - * that the shutdown hook code puts us at the head of - * the list (thus guaranteeing that our hook runs before + * that the shutdown hooks at the "leaves" of the device tree + * are run, first (thus guaranteeing that our hook runs before * our ancestors'). */ - if ((sd->sc_sdhook = - shutdownhook_establish(sd_shutdown, sd)) == NULL) - aprint_error_dev(sd->sc_dev, - "WARNING: unable to establish shutdown hook\n"); - - if (!pmf_device_register(self, sd_suspend, NULL)) + if (!pmf_device_register1(self, sd_suspend, NULL, sd_shutdown)) aprint_error_dev(self, "couldn't establish power handler\n"); #if NRND > 0 @@ -392,7 +387,6 @@ callout_destroy(&sd->sc_callout); pmf_device_deregister(self); - shutdownhook_disestablish(sd->sc_sdhook); #if NRND > 0 /* Unhook the entropy source. */ @@ -1324,10 +1318,10 @@ return 0; } -static void -sd_shutdown(void *arg) +static bool +sd_shutdown(device_t self, int how) { - struct sd_softc *sd = arg; + struct sd_softc *sd = device_private(self); /* * If the disk cache needs to be flushed, and the disk supports @@ -1342,15 +1336,13 @@ } else sd->flags &= ~(SDF_FLUSHING|SDF_DIRTY); } + return true; } static bool sd_suspend(device_t dv PMF_FN_ARGS) { - struct sd_softc *sd = device_private(dv); - - sd_shutdown(sd); /* XXX no need to poll */ - return true; + return sd_shutdown(dv, boothowto); /* XXX no need to poll */ } /* Index: src/sys/dev/scsipi/sdvar.h diff -u src/sys/dev/scsipi/sdvar.h:1.31 src/sys/dev/scsipi/sdvar.h:1.32 --- src/sys/dev/scsipi/sdvar.h:1.31 Wed Jul 16 18:54:09 2008 +++ src/sys/dev/scsipi/sdvar.h Fri Apr 10 17:36:42 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sdvar.h,v 1.31 2008/07/16 18:54:09 drochner Exp $ */ +/* $NetBSD: sdvar.h,v 1.32 2009/04/10 17:36:42 dyoung Exp $ */ /*- * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. @@ -91,8 +91,6 @@ u_int8_t type; char name[16]; /* product name, for default disklabel */ - void *sc_sdhook; /* our shutdown hook */ - #if NRND > 0 rndsource_element_t rnd_source; #endif