From owner-svn-src-all@FreeBSD.ORG Sat Sep 14 09:06:32 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E35FDB21; Sat, 14 Sep 2013 09:06:32 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D01552AD2; Sat, 14 Sep 2013 09:06:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r8E96Wrk093159; Sat, 14 Sep 2013 09:06:32 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r8E96W7s093157; Sat, 14 Sep 2013 09:06:32 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201309140906.r8E96W7s093157@svn.freebsd.org> From: Alexander Motin Date: Sat, 14 Sep 2013 09:06:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r255547 - in stable/9/sys/cam: ata scsi X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Sep 2013 09:06:33 -0000 Author: mav Date: Sat Sep 14 09:06:32 2013 New Revision: 255547 URL: http://svnweb.freebsd.org/changeset/base/255547 Log: MFC r253724: Synchronize device cache on close only if there were some write operations. While these operations are not really needed otherwise, at least for SCSI they may cause extra errors if some other initiator holds write exclusive reservation on the LUN (SYNCHRONIZE CACHE handled as "write" operation). Modified: stable/9/sys/cam/ata/ata_da.c stable/9/sys/cam/scsi/scsi_da.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/cam/ata/ata_da.c ============================================================================== --- stable/9/sys/cam/ata/ata_da.c Sat Sep 14 09:05:03 2013 (r255546) +++ stable/9/sys/cam/ata/ata_da.c Sat Sep 14 09:06:32 2013 (r255547) @@ -88,7 +88,8 @@ typedef enum { ADA_FLAG_SCTX_INIT = 0x0200, ADA_FLAG_CAN_CFA = 0x0400, ADA_FLAG_CAN_POWERMGT = 0x0800, - ADA_FLAG_CAN_DMA48 = 0x1000 + ADA_FLAG_CAN_DMA48 = 0x1000, + ADA_FLAG_DIRTY = 0x2000 } ada_flags; typedef enum { @@ -613,6 +614,7 @@ adaclose(struct disk *dp) struct cam_periph *periph; struct ada_softc *softc; union ccb *ccb; + int error; periph = (struct cam_periph *)dp->d_drv1; cam_periph_lock(periph); @@ -628,7 +630,8 @@ adaclose(struct disk *dp) ("adaclose\n")); /* We only sync the cache if the drive is capable of it. */ - if ((softc->flags & ADA_FLAG_CAN_FLUSHCACHE) != 0 && + if ((softc->flags & ADA_FLAG_DIRTY) != 0 && + (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) != 0 && (softc->flags & ADA_FLAG_PACK_INVALID) == 0) { ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); @@ -645,11 +648,13 @@ adaclose(struct disk *dp) ata_48bit_cmd(&ccb->ataio, ATA_FLUSHCACHE48, 0, 0, 0); else ata_28bit_cmd(&ccb->ataio, ATA_FLUSHCACHE, 0, 0, 0); - cam_periph_runccb(ccb, adaerror, /*cam_flags*/0, + error = cam_periph_runccb(ccb, adaerror, /*cam_flags*/0, /*sense_flags*/0, softc->disk->d_devstat); - if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) + if (error != 0) xpt_print(periph->path, "Synchronize cache failed\n"); + else + softc->flags &= ~ADA_FLAG_DIRTY; xpt_release_ccb(ccb); } @@ -1498,8 +1503,10 @@ adastart(struct cam_periph *periph, unio tag_code = 1; } switch (bp->bio_cmd) { - case BIO_READ: case BIO_WRITE: + softc->flags |= ADA_FLAG_DIRTY; + /* FALLTHROUGH */ + case BIO_READ: { uint64_t lba = bp->bio_pblkno; uint16_t count = bp->bio_bcount / softc->params.secsize; Modified: stable/9/sys/cam/scsi/scsi_da.c ============================================================================== --- stable/9/sys/cam/scsi/scsi_da.c Sat Sep 14 09:05:03 2013 (r255546) +++ stable/9/sys/cam/scsi/scsi_da.c Sat Sep 14 09:06:32 2013 (r255547) @@ -90,7 +90,8 @@ typedef enum { DA_FLAG_OPEN = 0x100, DA_FLAG_SCTX_INIT = 0x200, DA_FLAG_CAN_RC16 = 0x400, - DA_FLAG_PROBED = 0x800 + DA_FLAG_PROBED = 0x800, + DA_FLAG_DIRTY = 0x1000 } da_flags; typedef enum { @@ -1249,6 +1250,7 @@ daclose(struct disk *dp) { struct cam_periph *periph; struct da_softc *softc; + int error; periph = (struct cam_periph *)dp->d_drv1; cam_periph_lock(periph); @@ -1263,8 +1265,9 @@ daclose(struct disk *dp) CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH, ("daclose\n")); - if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 - && (softc->flags & DA_FLAG_PACK_INVALID) == 0) { + if ((softc->flags & DA_FLAG_DIRTY) != 0 && + (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 && + (softc->flags & DA_FLAG_PACK_INVALID) == 0) { union ccb *ccb; ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); @@ -1278,9 +1281,11 @@ daclose(struct disk *dp) SSD_FULL_SIZE, 5 * 60 * 1000); - cam_periph_runccb(ccb, daerror, /*cam_flags*/0, + error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0, /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR, softc->disk->d_devstat); + if (error == 0) + softc->flags &= ~DA_FLAG_DIRTY; xpt_release_ccb(ccb); } @@ -2252,8 +2257,10 @@ skipstate: } switch (bp->bio_cmd) { - case BIO_READ: case BIO_WRITE: + softc->flags |= DA_FLAG_DIRTY; + /* FALLTHROUGH */ + case BIO_READ: scsi_read_write(&start_ccb->csio, /*retries*/da_retry_count, /*cbfcnp*/dadone,