bhyve: Cast away const when fetching a config nvlist

Silence a warning from the compiler about "const" being discarded.  The
warning is correct: nvlist values are supposed to be immutable.
However, fixing this properly will require some contortions on behalf of
consumers who look up a subtree of the config and modify it.  Per a
discussion on freebsd-virtualization@, the solution will probably be to
outright replace the use of nvlists for VM configuration, but until that
happens let's document the problem and silence the warning.

No functional change intended.

MFC after:	2 weeks
Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D37293
This commit is contained in:
Mark Johnston 2022-11-11 10:02:42 -05:00
parent 8b1adff8bc
commit 719e307f80

View File

@ -65,7 +65,17 @@ _lookup_config_node(nvlist_t *parent, const char *path, bool create)
break;
}
if (nvlist_exists_nvlist(nvl, name))
nvl = (nvlist_t *)nvlist_get_nvlist(nvl, name);
/*
* XXX-MJ it is incorrect to cast away the const
* qualifier like this since the contract with nvlist
* says that values are immuatable, and some consumers
* will indeed add nodes to the returned nvlist. In
* practice, however, it appears to be harmless with the
* current nvlist implementation, so we just live with
* it until the implementation is reworked.
*/
nvl = __DECONST(nvlist_t *,
nvlist_get_nvlist(nvl, name));
else if (nvlist_exists(nvl, name)) {
for (copy = tofree; copy < name; copy++)
if (*copy == '\0')
@ -76,6 +86,10 @@ _lookup_config_node(nvlist_t *parent, const char *path, bool create)
nvl = NULL;
break;
} else if (create) {
/*
* XXX-MJ as with the case above, "new_nvl" shouldn't be
* mutated after its ownership is given to "nvl".
*/
new_nvl = nvlist_create(0);
if (new_nvl == NULL)
errx(4, "Failed to allocate memory");