Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Aug 2021 09:11:19 GMT
From:      Ka Ho Ng <khng@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 3676512b60d6 - main - bhyve: Use fspacectl(2) for BOP_DELETE on regular file images
Message-ID:  <202108070911.1779BJki045408@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by khng:

URL: https://cgit.FreeBSD.org/src/commit/?id=3676512b60d65ff68fb807ede2fa6e89af18c490

commit 3676512b60d65ff68fb807ede2fa6e89af18c490
Author:     Ka Ho Ng <khng@FreeBSD.org>
AuthorDate: 2021-08-07 09:10:30 +0000
Commit:     Ka Ho Ng <khng@FreeBSD.org>
CommitDate: 2021-08-07 09:10:30 +0000

    bhyve: Use fspacectl(2) for BOP_DELETE on regular file images
    
    bhyve can also make use of fspacectl(2) to implement BOP_DELETE with
    hole-punching. Since it is not desirable to do zero-filling for large
    DEALLOCATE/UNMAP range, candelete is not set if pathconf(2) indicates
    that the underlying file system does not support native
    VOP_DEALLOCATE(9).
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    grehan
    Differential Revision:  https://reviews.freebsd.org/D28880
---
 usr.sbin/bhyve/block_if.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/bhyve/block_if.c b/usr.sbin/bhyve/block_if.c
index 98c0f9f5f38b..9d7371bec50f 100644
--- a/usr.sbin/bhyve/block_if.c
+++ b/usr.sbin/bhyve/block_if.c
@@ -239,6 +239,7 @@ blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be, uint8_t *buf)
 	off_t arg[2];
 	ssize_t clen, len, off, boff, voff;
 	int i, err;
+	struct spacectl_range range;
 
 	br = be->be_req;
 	if (br->br_iovcnt <= 1)
@@ -336,8 +337,20 @@ blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be, uint8_t *buf)
 				err = errno;
 			else
 				br->br_resid = 0;
-		} else
-			err = EOPNOTSUPP;
+		} else {
+			range.r_offset = br->br_offset;
+			range.r_len = br->br_resid;
+
+			while (range.r_len > 0) {
+				if (fspacectl(bc->bc_fd, SPACECTL_DEALLOC,
+				    &range, 0, &range) != 0) {
+					err = errno;
+					break;
+				}
+			}
+			if (err == 0)
+				br->br_resid = 0;
+		}
 		break;
 	default:
 		err = EINVAL;
@@ -566,8 +579,11 @@ blockif_open(nvlist_t *nvl, const char *ident)
 			candelete = arg.value.i;
 		if (ioctl(fd, DIOCGPROVIDERNAME, name) == 0)
 			geom = 1;
-	} else
+	} else {
 		psectsz = sbuf.st_blksize;
+		/* Avoid fallback implementation */
+		candelete = fpathconf(fd, _PC_DEALLOC_PRESENT) == 1;
+	}
 
 #ifndef WITHOUT_CAPSICUM
 	if (caph_ioctls_limit(fd, cmds, nitems(cmds)) == -1)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202108070911.1779BJki045408>