From owner-svn-src-stable-11@freebsd.org Tue Aug 22 15:20:49 2017 Return-Path: Delivered-To: svn-src-stable-11@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 DE941DC8F7D; Tue, 22 Aug 2017 15:20:49 +0000 (UTC) (envelope-from mckusick@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 B385365F58; Tue, 22 Aug 2017 15:20:49 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7MFKmhH056608; Tue, 22 Aug 2017 15:20:48 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7MFKmJ7056606; Tue, 22 Aug 2017 15:20:48 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201708221520.v7MFKmJ7056606@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick Date: Tue, 22 Aug 2017 15:20:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r322792 - stable/11/sys/geom/journal X-SVN-Group: stable-11 X-SVN-Commit-Author: mckusick X-SVN-Commit-Paths: stable/11/sys/geom/journal X-SVN-Commit-Revision: 322792 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Aug 2017 15:20:50 -0000 Author: mckusick Date: Tue Aug 22 15:20:48 2017 New Revision: 322792 URL: https://svnweb.freebsd.org/changeset/base/322792 Log: MFC of 322179, 322463, and 322464: 322179: Correct ordering of bio's in gjournal queue 322463: Eliminate a variable that is set-only in g_journal.c 322464: Correct check for reads in gjournal Submitted by: Dr. Andreas Longwitz Discussed with: kib Modified: stable/11/sys/geom/journal/g_journal.c stable/11/sys/geom/journal/g_journal.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/geom/journal/g_journal.c ============================================================================== --- stable/11/sys/geom/journal/g_journal.c Tue Aug 22 15:16:09 2017 (r322791) +++ stable/11/sys/geom/journal/g_journal.c Tue Aug 22 15:20:48 2017 (r322792) @@ -1236,7 +1236,7 @@ g_journal_flush(struct g_journal_softc *sc) struct g_provider *pp; struct bio **bioq; struct bio *bp, *fbp, *pbp; - off_t joffset, size; + off_t joffset; u_char *data, hash[16]; MD5_CTX ctx; u_int i; @@ -1244,7 +1244,6 @@ g_journal_flush(struct g_journal_softc *sc) if (sc->sc_current_count == 0) return; - size = 0; pp = sc->sc_jprovider; GJ_VALIDATE_OFFSET(sc->sc_journal_offset, sc); joffset = sc->sc_journal_offset; @@ -1261,7 +1260,7 @@ g_journal_flush(struct g_journal_softc *sc) strlcpy(hdr.jrh_magic, GJ_RECORD_HEADER_MAGIC, sizeof(hdr.jrh_magic)); bioq = &sc->sc_active.jj_queue; - pbp = sc->sc_flush_queue; + GJQ_LAST(sc->sc_flush_queue, pbp); fbp = g_alloc_bio(); fbp->bio_parent = NULL; @@ -1294,7 +1293,6 @@ g_journal_flush(struct g_journal_softc *sc) ent->je_offset = bp->bio_offset; ent->je_joffset = joffset; ent->je_length = bp->bio_length; - size += ent->je_length; data = bp->bio_data; if (sc->sc_flags & GJF_DEVICE_CHECKSUM) @@ -1516,49 +1514,10 @@ g_journal_read_find(struct bio *head, int sorted, stru } /* - * Try to find requested data in cache. - */ -static struct bio * -g_journal_read_queue_find(struct bio_queue *head, struct bio *pbp, off_t ostart, - off_t oend) -{ - off_t cstart, cend; - struct bio *bp; - - TAILQ_FOREACH(bp, head, bio_queue) { - cstart = MAX(ostart, bp->bio_offset); - cend = MIN(oend, bp->bio_offset + bp->bio_length); - if (cend <= ostart) - continue; - else if (cstart >= oend) - continue; - KASSERT(bp->bio_data != NULL, - ("%s: bio_data == NULL", __func__)); - GJ_DEBUG(3, "READ(%p): (%jd, %jd) (bp=%p)", head, cstart, cend, - bp); - bcopy(bp->bio_data + cstart - bp->bio_offset, - pbp->bio_data + cstart - pbp->bio_offset, cend - cstart); - pbp->bio_completed += cend - cstart; - if (pbp->bio_completed == pbp->bio_length) { - /* - * Cool, the whole request was in cache, deliver happy - * message. - */ - g_io_deliver(pbp, 0); - return (pbp); - } - break; - } - return (bp); -} - -/* - * This function is used for colecting data on read. + * This function is used for collecting data on read. * The complexity is because parts of the data can be stored in four different * places: - * - in delayed requests * - in memory - the data not yet send to the active journal provider - * - in requests which are going to be sent to the active journal * - in the active journal * - in the inactive journal * - in the data provider @@ -1576,20 +1535,14 @@ g_journal_read(struct g_journal_softc *sc, struct bio cstart = cend = -1; bp = NULL; head = NULL; - for (i = 0; i <= 5; i++) { + for (i = 1; i <= 5; i++) { switch (i) { - case 0: /* Delayed requests. */ - head = NULL; - sorted = 0; - break; case 1: /* Not-yet-send data. */ head = sc->sc_current_queue; sorted = 1; break; - case 2: /* In-flight to the active journal. */ - head = sc->sc_flush_queue; - sorted = 0; - break; + case 2: /* Skip flush queue as they are also in active queue */ + continue; case 3: /* Active journal. */ head = sc->sc_active.jj_queue; sorted = 1; @@ -1608,10 +1561,7 @@ g_journal_read(struct g_journal_softc *sc, struct bio default: panic("gjournal %s: i=%d", __func__, i); } - if (i == 0) - bp = g_journal_read_queue_find(&sc->sc_delayed_queue.queue, pbp, ostart, oend); - else - bp = g_journal_read_find(head, sorted, pbp, ostart, oend); + bp = g_journal_read_find(head, sorted, pbp, ostart, oend); if (bp == pbp) { /* Got the whole request. */ GJ_DEBUG(2, "Got the whole request from %u.", i); return; Modified: stable/11/sys/geom/journal/g_journal.h ============================================================================== --- stable/11/sys/geom/journal/g_journal.h Tue Aug 22 15:16:09 2017 (r322791) +++ stable/11/sys/geom/journal/g_journal.h Tue Aug 22 15:20:48 2017 (r322792) @@ -182,6 +182,17 @@ struct g_journal_softc { (pbp)->bio_next = (bp); \ } \ } while (0) +#define GJQ_LAST(head, bp) do { \ + struct bio *_bp; \ + \ + if ((head) == NULL) { \ + (bp) = (head); \ + break; \ + } \ + for (_bp = (head); _bp->bio_next != NULL; _bp = _bp->bio_next) \ + continue; \ + (bp) = (_bp); \ +} while (0) #define GJQ_FIRST(head) (head) #define GJQ_REMOVE(head, bp) do { \ struct bio *_bp; \