From f8c665221e436f88f33e93dc1f2a35ad1b2e3de6 Mon Sep 17 00:00:00 2001 From: mav Date: Tue, 28 Oct 2014 14:01:58 +0000 Subject: [PATCH] MFS10 r273767 / MFC r273638: Revert somewhat hackish geom_disk optimization, committed as part of r256880, and the following r273143 commit, supposed to workaround introduced issue by quite innocent-looking change. While there is no clear understanding why, but r273143 is accused in data corruption in some environments with high I/O load. I personally don't see any problem in that commit, and possibly it is just a trigger to some other bug somewhere, but better safe then sorry for now. Requested by: scottl@ Approved by: re (kib@) git-svn-id: svn://svn.freebsd.org/base/releng/10.1@273776 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/geom/geom_disk.c | 59 ++++++++++++-------------------------------- sys/kern/vfs_bio.c | 4 ++- 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c index 2c6b00b1a..9319b970e 100644 --- a/sys/geom/geom_disk.c +++ b/sys/geom/geom_disk.c @@ -255,25 +255,6 @@ g_disk_done(struct bio *bp) g_destroy_bio(bp); } -static void -g_disk_done_single(struct bio *bp) -{ - struct bintime now; - struct g_disk_softc *sc; - - bp->bio_completed = bp->bio_length - bp->bio_resid; - bp->bio_done = (void *)bp->bio_to; - bp->bio_to = LIST_FIRST(&bp->bio_disk->d_geom->provider); - if ((bp->bio_cmd & (BIO_READ|BIO_WRITE|BIO_DELETE|BIO_FLUSH)) != 0) { - binuptime(&now); - sc = bp->bio_to->private; - mtx_lock(&sc->done_mtx); - devstat_end_transaction_bio_bt(sc->dp->d_devstat, bp, &now); - mtx_unlock(&sc->done_mtx); - } - g_io_deliver(bp, bp->bio_error); -} - static int g_disk_ioctl(struct g_provider *pp, u_long cmd, void * data, int fflag, struct thread *td) { @@ -299,7 +280,7 @@ g_disk_start(struct bio *bp) struct disk *dp; struct g_disk_softc *sc; int error; - off_t d_maxsize, off; + off_t off; sc = bp->bio_to->private; if (sc == NULL || (dp = sc->dp) == NULL || dp->d_destroyed) { @@ -316,22 +297,6 @@ g_disk_start(struct bio *bp) /* fall-through */ case BIO_READ: case BIO_WRITE: - d_maxsize = (bp->bio_cmd == BIO_DELETE) ? - dp->d_delmaxsize : dp->d_maxsize; - if (bp->bio_length <= d_maxsize) { - bp->bio_disk = dp; - bp->bio_to = (void *)bp->bio_done; - bp->bio_done = g_disk_done_single; - bp->bio_pblkno = bp->bio_offset / dp->d_sectorsize; - bp->bio_bcount = bp->bio_length; - mtx_lock(&sc->start_mtx); - devstat_start_transaction_bio(dp->d_devstat, bp); - mtx_unlock(&sc->start_mtx); - g_disk_lock_giant(dp); - dp->d_strategy(bp); - g_disk_unlock_giant(dp); - break; - } off = 0; bp3 = NULL; bp2 = g_clone_bio(bp); @@ -340,6 +305,10 @@ g_disk_start(struct bio *bp) break; } do { + off_t d_maxsize; + + d_maxsize = (bp->bio_cmd == BIO_DELETE) ? + dp->d_delmaxsize : dp->d_maxsize; bp2->bio_offset += off; bp2->bio_length -= off; if ((bp->bio_flags & BIO_UNMAPPED) == 0) { @@ -447,14 +416,18 @@ g_disk_start(struct bio *bp) error = EOPNOTSUPP; break; } - bp->bio_disk = dp; - bp->bio_to = (void *)bp->bio_done; - bp->bio_done = g_disk_done_single; - mtx_lock(&sc->start_mtx); - devstat_start_transaction_bio(dp->d_devstat, bp); - mtx_unlock(&sc->start_mtx); + bp2 = g_clone_bio(bp); + if (bp2 == NULL) { + g_io_deliver(bp, ENOMEM); + return; + } + bp2->bio_done = g_disk_done; + bp2->bio_disk = dp; + mtx_lock(&sc->start_mtx); + devstat_start_transaction_bio(dp->d_devstat, bp2); + mtx_unlock(&sc->start_mtx); g_disk_lock_giant(dp); - dp->d_strategy(bp); + dp->d_strategy(bp2); g_disk_unlock_giant(dp); break; default: diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index d04aae520..1cbc891ab 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -3582,8 +3582,10 @@ biodone(struct bio *bp) bp->bio_flags |= BIO_DONE; wakeup(bp); mtx_unlock(mtxp); - } else + } else { + bp->bio_flags |= BIO_DONE; done(bp); + } } /* -- 2.42.0