Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/freebsd/freebsd-src.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2022-11-11 18:02:42 +0300
committerMark Johnston <markj@FreeBSD.org>2022-11-11 18:02:42 +0300
commit719e307f80c724a39814557e35ac890c75dcd402 (patch)
tree2982a2d295a019916c1a71734783af6b4883a00d
parent8b1adff8bcbdf0e58878431c6ed5a14553178d4d (diff)
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
-rw-r--r--usr.sbin/bhyve/config.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/usr.sbin/bhyve/config.c b/usr.sbin/bhyve/config.c
index de138795f4d1..6339ddb9f2ee 100644
--- a/usr.sbin/bhyve/config.c
+++ b/usr.sbin/bhyve/config.c
@@ -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");