From owner-svn-src-head@freebsd.org Mon Apr 10 17:16:01 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 F2985D37648; Mon, 10 Apr 2017 17:16:00 +0000 (UTC) (envelope-from markj@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 AB9F1615; Mon, 10 Apr 2017 17:16:00 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3AHFx5g046836; Mon, 10 Apr 2017 17:15:59 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3AHFxlq046835; Mon, 10 Apr 2017 17:15:59 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201704101715.v3AHFxlq046835@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Mon, 10 Apr 2017 17:15:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r316681 - head/sys/geom/mirror X-SVN-Group: head 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: Mon, 10 Apr 2017 17:16:01 -0000 Author: markj Date: Mon Apr 10 17:15:59 2017 New Revision: 316681 URL: https://svnweb.freebsd.org/changeset/base/316681 Log: Handle NULL entries in gmirror disk ds_bios arrays. Entries may be removed and freed if an I/O error occurs during mirror synchronization, so we cannot assume that all entries of ds_bios are valid. Also ensure that a synchronization BIO's array index is preserved after a successful write. Reported and tested by: pho MFC after: 2 weeks Sponsored by: Dell EMC Isilon Modified: head/sys/geom/mirror/g_mirror.c Modified: head/sys/geom/mirror/g_mirror.c ============================================================================== --- head/sys/geom/mirror/g_mirror.c Mon Apr 10 16:09:19 2017 (r316680) +++ head/sys/geom/mirror/g_mirror.c Mon Apr 10 17:15:59 2017 (r316681) @@ -1304,11 +1304,13 @@ g_mirror_sync_release(struct g_mirror_so static void g_mirror_sync_request_free(struct g_mirror_disk *disk, struct bio *bp) { - int i; + int idx; if (disk != NULL && disk->d_sync.ds_bios != NULL) { - i = (int)(uintptr_t)bp->bio_caller1; - disk->d_sync.ds_bios[i] = NULL; + idx = (int)(uintptr_t)bp->bio_caller1; + KASSERT(disk->d_sync.ds_bios[idx] == bp, + ("unexpected sync BIO at %p:%d", disk, idx)); + disk->d_sync.ds_bios[idx] = NULL; } free(bp->bio_data, M_MIRROR); g_destroy_bio(bp); @@ -1375,7 +1377,7 @@ g_mirror_sync_request(struct bio *bp) { off_t offset; void *data; - int i; + int i, idx; KFAIL_POINT_ERROR(DEBUG_FP, g_mirror_sync_request_write, bp->bio_error); @@ -1413,6 +1415,7 @@ g_mirror_sync_request(struct bio *bp) /* Send next synchronization request. */ data = bp->bio_data; + idx = (int)(uintptr_t)bp->bio_caller1; g_reset_bio(bp); bp->bio_cmd = BIO_READ; bp->bio_offset = sync->ds_offset; @@ -1422,6 +1425,7 @@ g_mirror_sync_request(struct bio *bp) bp->bio_data = data; bp->bio_from = sync->ds_consumer; bp->bio_to = sc->sc_provider; + bp->bio_caller1 = (void *)(uintptr_t)idx; G_MIRROR_LOGREQ(3, bp, "Sending synchronization request."); sync->ds_consumer->index++; /* @@ -1439,7 +1443,7 @@ g_mirror_sync_request(struct bio *bp) offset = sc->sc_mediasize; for (i = 0; i < g_mirror_syncreqs; i++) { bp = sync->ds_bios[i]; - if (bp->bio_offset < offset) + if (bp != NULL && bp->bio_offset < offset) offset = bp->bio_offset; } if (sync->ds_offset_done + (MAXPHYS * 100) < offset) {