From owner-dev-commits-src-all@freebsd.org Sat Aug 7 09:11:19 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E4B7B667E83; Sat, 7 Aug 2021 09:11:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Ghc5z6BNVz4tcw; Sat, 7 Aug 2021 09:11:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BDE421E4FE; Sat, 7 Aug 2021 09:11:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1779BJs5045409; Sat, 7 Aug 2021 09:11:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1779BJki045408; Sat, 7 Aug 2021 09:11:19 GMT (envelope-from git) Date: Sat, 7 Aug 2021 09:11:19 GMT Message-Id: <202108070911.1779BJki045408@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ka Ho Ng Subject: git: 3676512b60d6 - main - bhyve: Use fspacectl(2) for BOP_DELETE on regular file images MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: khng X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3676512b60d65ff68fb807ede2fa6e89af18c490 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Aug 2021 09:11:20 -0000 The branch main has been updated by khng: URL: https://cgit.FreeBSD.org/src/commit/?id=3676512b60d65ff68fb807ede2fa6e89af18c490 commit 3676512b60d65ff68fb807ede2fa6e89af18c490 Author: Ka Ho Ng AuthorDate: 2021-08-07 09:10:30 +0000 Commit: Ka Ho Ng 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)