From owner-svn-src-head@freebsd.org Sat Dec 22 22:59:12 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 595B1133EAE3; Sat, 22 Dec 2018 22:59:12 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F4114758AF; Sat, 22 Dec 2018 22:59:11 +0000 (UTC) (envelope-from bde@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E8CF03D31; Sat, 22 Dec 2018 22:59:11 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBMMxBR5053910; Sat, 22 Dec 2018 22:59:11 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBMMxB1c053909; Sat, 22 Dec 2018 22:59:11 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201812222259.wBMMxB1c053909@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans Date: Sat, 22 Dec 2018 22:59:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342375 - head/sys/dev/md X-SVN-Group: head X-SVN-Commit-Author: bde X-SVN-Commit-Paths: head/sys/dev/md X-SVN-Commit-Revision: 342375 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: F4114758AF X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.946,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.999,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 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: Sat, 22 Dec 2018 22:59:12 -0000 Author: bde Date: Sat Dec 22 22:59:11 2018 New Revision: 342375 URL: https://svnweb.freebsd.org/changeset/base/342375 Log: Fix devstat on md devices, second attempt. r341765 depends on g_io_deliver() finishing initialization of the bio, but g_io_deliver() actually destroys the bio. INVARIANTS makes the bug obvious by overwriting the bio with garbage. Restore the old order for calling devstat (except don't restore not calling it for the error case), and translate to the devstat KPI so that this order works. Reviewed by: kib Modified: head/sys/dev/md/md.c Modified: head/sys/dev/md/md.c ============================================================================== --- head/sys/dev/md/md.c Sat Dec 22 21:49:25 2018 (r342374) +++ head/sys/dev/md/md.c Sat Dec 22 22:59:11 2018 (r342375) @@ -1241,12 +1241,22 @@ md_kthread(void *arg) error = sc->start(sc, bp); } + if (bp->bio_cmd == BIO_READ || bp->bio_cmd == BIO_WRITE) { + /* + * Devstat uses (bio_bcount, bio_resid) for + * determining the length of the completed part of + * the i/o. g_io_deliver() will translate from + * bio_completed to that, but it also destroys the + * bio so we must do our own translation. + */ + bp->bio_bcount = bp->bio_length; + bp->bio_resid = (error == -1 ? bp->bio_bcount : 0); + devstat_end_transaction_bio(sc->devstat, bp); + } if (error != -1) { bp->bio_completed = bp->bio_length; g_io_deliver(bp, error); } - if (bp->bio_cmd == BIO_READ || bp->bio_cmd == BIO_WRITE) - devstat_end_transaction_bio(sc->devstat, bp); } }