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
This commit is contained in:
Ka Ho Ng 2021-08-07 17:10:30 +08:00
parent c18c74a87c
commit 3676512b60

View File

@ -239,6 +239,7 @@ blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be, uint8_t *buf)
off_t arg[2]; off_t arg[2];
ssize_t clen, len, off, boff, voff; ssize_t clen, len, off, boff, voff;
int i, err; int i, err;
struct spacectl_range range;
br = be->be_req; br = be->be_req;
if (br->br_iovcnt <= 1) if (br->br_iovcnt <= 1)
@ -336,8 +337,20 @@ blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be, uint8_t *buf)
err = errno; err = errno;
else else
br->br_resid = 0; br->br_resid = 0;
} else } else {
err = EOPNOTSUPP; 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; break;
default: default:
err = EINVAL; err = EINVAL;
@ -566,8 +579,11 @@ blockif_open(nvlist_t *nvl, const char *ident)
candelete = arg.value.i; candelete = arg.value.i;
if (ioctl(fd, DIOCGPROVIDERNAME, name) == 0) if (ioctl(fd, DIOCGPROVIDERNAME, name) == 0)
geom = 1; geom = 1;
} else } else {
psectsz = sbuf.st_blksize; psectsz = sbuf.st_blksize;
/* Avoid fallback implementation */
candelete = fpathconf(fd, _PC_DEALLOC_PRESENT) == 1;
}
#ifndef WITHOUT_CAPSICUM #ifndef WITHOUT_CAPSICUM
if (caph_ioctls_limit(fd, cmds, nitems(cmds)) == -1) if (caph_ioctls_limit(fd, cmds, nitems(cmds)) == -1)