git: 78267c2e703c - main - md: Replace BIO_DELETE emulation with vn_deallocate(9)

Ka Ho Ng khng at FreeBSD.org
Thu Aug 19 10:31:43 UTC 2021


The branch main has been updated by khng:

URL: https://cgit.FreeBSD.org/src/commit/?id=78267c2e703c236d37692da77a4ee92da9502943

commit 78267c2e703c236d37692da77a4ee92da9502943
Author:     Ka Ho Ng <khng at FreeBSD.org>
AuthorDate: 2021-08-19 10:30:13 +0000
Commit:     Ka Ho Ng <khng at FreeBSD.org>
CommitDate: 2021-08-19 10:30:13 +0000

    md: Replace BIO_DELETE emulation with vn_deallocate(9)
    
    Both zero-filling and/or deallocation can be done with vn_deallocate(9).
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D28899
---
 sys/dev/md/md.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)

diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c
index c5c90d9173ad..1627ee2e5fa6 100644
--- a/sys/dev/md/md.c
+++ b/sys/dev/md/md.c
@@ -875,7 +875,7 @@ mdstart_vnode(struct md_s *sc, struct bio *bp)
 	struct buf *pb;
 	bus_dma_segment_t *vlist;
 	struct thread *td;
-	off_t iolen, iostart, len, zerosize;
+	off_t iolen, iostart, off, len;
 	int ma_offs, npages;
 
 	switch (bp->bio_cmd) {
@@ -883,9 +883,9 @@ mdstart_vnode(struct md_s *sc, struct bio *bp)
 		auio.uio_rw = UIO_READ;
 		break;
 	case BIO_WRITE:
-	case BIO_DELETE:
 		auio.uio_rw = UIO_WRITE;
 		break;
+	case BIO_DELETE:
 	case BIO_FLUSH:
 		break;
 	default:
@@ -897,6 +897,7 @@ mdstart_vnode(struct md_s *sc, struct bio *bp)
 	pb = NULL;
 	piov = NULL;
 	ma_offs = bp->bio_ma_offset;
+	off = bp->bio_offset;
 	len = bp->bio_length;
 
 	/*
@@ -914,6 +915,11 @@ mdstart_vnode(struct md_s *sc, struct bio *bp)
 		VOP_UNLOCK(vp);
 		vn_finished_write(mp);
 		return (error);
+	} else if (bp->bio_cmd == BIO_DELETE) {
+		error = vn_deallocate(vp, &off, &len, 0,
+		    sc->flags & MD_ASYNC ? 0 : IO_SYNC, sc->cred, NOCRED);
+		bp->bio_resid = len;
+		return (error);
 	}
 
 	auio.uio_offset = (vm_ooffset_t)bp->bio_offset;
@@ -921,25 +927,7 @@ mdstart_vnode(struct md_s *sc, struct bio *bp)
 	auio.uio_segflg = UIO_SYSSPACE;
 	auio.uio_td = td;
 
-	if (bp->bio_cmd == BIO_DELETE) {
-		/*
-		 * Emulate BIO_DELETE by writing zeros.
-		 */
-		zerosize = ZERO_REGION_SIZE -
-		    (ZERO_REGION_SIZE % sc->sectorsize);
-		auio.uio_iovcnt = howmany(bp->bio_length, zerosize);
-		piov = malloc(sizeof(*piov) * auio.uio_iovcnt, M_MD, M_WAITOK);
-		auio.uio_iov = piov;
-		while (len > 0) {
-			piov->iov_base = __DECONST(void *, zero_region);
-			piov->iov_len = len;
-			if (len > zerosize)
-				piov->iov_len = zerosize;
-			len -= piov->iov_len;
-			piov++;
-		}
-		piov = auio.uio_iov;
-	} else if ((bp->bio_flags & BIO_VLIST) != 0) {
+	if ((bp->bio_flags & BIO_VLIST) != 0) {
 		piov = malloc(sizeof(*piov) * bp->bio_ma_n, M_MD, M_WAITOK);
 		auio.uio_iov = piov;
 		vlist = (bus_dma_segment_t *)bp->bio_data;


More information about the dev-commits-src-all mailing list