From owner-svn-src-head@freebsd.org Thu Oct 26 22:53:51 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CD235E54D51; Thu, 26 Oct 2017 22:53:51 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 76A236CE89; Thu, 26 Oct 2017 22:53:51 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9QMroMc009496; Thu, 26 Oct 2017 22:53:50 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9QMrovZ009495; Thu, 26 Oct 2017 22:53:50 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201710262253.v9QMrovZ009495@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 26 Oct 2017 22:53:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325026 - head/sys/cam/ata X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sys/cam/ata X-SVN-Commit-Revision: 325026 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Oct 2017 22:53:52 -0000 Author: imp Date: Thu Oct 26 22:53:49 2017 New Revision: 325026 URL: https://svnweb.freebsd.org/changeset/base/325026 Log: Always send STANDBY IMMEDIATE when shutting down To save SMART data and for a drive to understand that it's been nicely shutdown, we need to send a STANDBY IMMEDIATE. Modify adaspindown to use a local CCB on the stack. When we're panicing, used xpt_polled_action rather than cam_periph_runccb so that we can SEND IMMEDIATE after we've shutdown the scheduler. Sponsored by: Netflix Reviewed by: scottl@, gallatin@ Differential Revision: https://reviews.freebsd.org/D12799 Modified: head/sys/cam/ata/ata_da.c Modified: head/sys/cam/ata/ata_da.c ============================================================================== --- head/sys/cam/ata/ata_da.c Thu Oct 26 22:53:02 2017 (r325025) +++ head/sys/cam/ata/ata_da.c Thu Oct 26 22:53:49 2017 (r325026) @@ -3466,7 +3466,7 @@ adaspindown(uint8_t cmd, int flags) { struct cam_periph *periph; struct ada_softc *softc; - union ccb *ccb; + struct ccb_ataio local_ccb; int error; CAM_PERIPH_FOREACH(periph, &adadriver) { @@ -3486,8 +3486,11 @@ adaspindown(uint8_t cmd, int flags) if (bootverbose) xpt_print(periph->path, "spin-down\n"); - ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); - cam_fill_ataio(&ccb->ataio, + memset(&local_ccb, 0, sizeof(local_ccb)); + xpt_setup_ccb(&local_ccb.ccb_h, periph->path, CAM_PRIORITY_NORMAL); + local_ccb.ccb_h.ccb_state = ADA_CCB_DUMP; + + cam_fill_ataio(&local_ccb, 0, adadone, CAM_DIR_NONE | flags, @@ -3495,14 +3498,35 @@ adaspindown(uint8_t cmd, int flags) NULL, 0, ada_default_timeout*1000); - ata_28bit_cmd(&ccb->ataio, cmd, 0, 0, 0); + ata_28bit_cmd(&local_ccb, cmd, 0, 0, 0); - error = cam_periph_runccb(ccb, adaerror, /*cam_flags*/0, - /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY, - softc->disk->d_devstat); + if (!SCHEDULER_STOPPED()) { + /* + * Not panicing, can just do the normal runccb + * XXX should make cam_periph_runccb work while + * XXX panicing... later + */ + error = cam_periph_runccb((union ccb *)&local_ccb, adaerror, + /*cam_flags*/0, /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY, + softc->disk->d_devstat); + } else { + /* + * Panicing, so we have to do this by hand: do + * xpt_polled_action to run the request through the SIM, + * extract the error, and if the queue was frozen, + * unfreeze it. cam_periph_runccb takes care of these + * details, but xpt_polled_action doesn't. + */ + xpt_polled_action((union ccb *)&local_ccb); + error = adaerror((union ccb *)&local_ccb, 0, + SF_NO_RECOVERY | SF_NO_RETRY); + if ((local_ccb.ccb_h.status & CAM_DEV_QFRZN) != 0) + cam_release_devq(local_ccb.ccb_h.path, + /*relsim_flags*/0, /*reduction*/0, + /*timeout*/0, /*getcount_only*/0); + } if (error != 0) xpt_print(periph->path, "Spin-down disk failed\n"); - xpt_release_ccb(ccb); cam_periph_unlock(periph); } } @@ -3512,8 +3536,14 @@ adashutdown(void *arg, int howto) { adaflush(); - if (ada_spindown_shutdown != 0 && - (howto & (RB_HALT | RB_POWEROFF | RB_POWERCYCLE)) != 0) + + /* + * STANDBY IMMEDIATE flushes any volatile data to the drive so + * do this always to ensure we flush a cosnsistent state to + * the drive. adaspindown will ensure that we don't send this + * to a drive that doesn't support it. + */ + if (ada_spindown_shutdown != 0) adaspindown(ATA_STANDBY_IMMEDIATE, 0); } @@ -3522,6 +3552,10 @@ adasuspend(void *arg) { adaflush(); + /* + * SLEEP also fushes any volatile data, like STANDBY IMEDIATE, + * so we don't need to send it as well. + */ if (ada_spindown_suspend != 0) adaspindown(ATA_SLEEP, CAM_DEV_QFREEZE); }