Page MenuHomeFreeBSD

D62519.1796669452.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D62519.1796669452.diff

diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -266,11 +266,21 @@
void
bhyve_cfg_warn(const char *old, const char *new)
{
- if (get_config_value(old) != NULL &&
- get_config_value(new) == NULL) {
+ char *value;
+
+ /*
+ * Remove the old variable before looking at the new one, as the
+ * old name may be a prefix of the new one (e.g., "monitor" and
+ * "monitor.enabled").
+ */
+ value = remove_config_value(old);
+ if (value == NULL)
+ return;
+ if (get_config_value(new) == NULL) {
warnx("'%s' is deprecated, use '%s' instead", old, new);
- set_config_value(new, get_config_value(old));
+ set_config_value(new, value);
}
+ free(value);
}
static void
diff --git a/usr.sbin/bhyve/config.h b/usr.sbin/bhyve/config.h
--- a/usr.sbin/bhyve/config.h
+++ b/usr.sbin/bhyve/config.h
@@ -124,6 +124,8 @@
void set_config_value_if_unset(const char *const path,
const char *const value);
+char *remove_config_value(const char *path);
+
/* Convenience wrappers for boolean variables. */
bool get_config_bool(const char *path);
bool get_config_bool_node(const nvlist_t *parent, const char *name);
diff --git a/usr.sbin/bhyve/config.c b/usr.sbin/bhyve/config.c
--- a/usr.sbin/bhyve/config.c
+++ b/usr.sbin/bhyve/config.c
@@ -201,6 +201,33 @@
set_config_value(path, value);
}
+char *
+remove_config_value(const char *path)
+{
+ const char *name;
+ char *node_name;
+ nvlist_t *nvl;
+
+ name = strrchr(path, '.');
+ if (name == NULL) {
+ nvl = config_root;
+ name = path;
+ } else {
+ node_name = strndup(path, name - path);
+ if (node_name == NULL)
+ errx(4, "Failed to allocate memory");
+ nvl = find_config_node(node_name);
+ free(node_name);
+ if (nvl == NULL)
+ return (NULL);
+ name++;
+ }
+
+ if (!nvlist_exists_string(nvl, name))
+ return (NULL);
+ return (nvlist_take_string(nvl, name));
+}
+
static const char *
get_raw_config_value(const char *path)
{
diff --git a/usr.sbin/bhyve/tests/bhyve_test.sh b/usr.sbin/bhyve/tests/bhyve_test.sh
--- a/usr.sbin/bhyve/tests/bhyve_test.sh
+++ b/usr.sbin/bhyve/tests/bhyve_test.sh
@@ -124,10 +124,87 @@
atf_check diff -u config.sorted config.2.sorted
}
+atf_test_case check_config_monitor
+check_config_monitor_head()
+{
+ atf_set "descr" "Check that -M sets monitor.enabled without warnings"
+ atf_set "require.progs" "bhyve"
+}
+
+check_config_monitor_body()
+{
+ atf_check -s exit:1 -o save:config bhyve -M -o config.dump=1 test-vm
+
+ atf_check grep -Fxq "monitor.enabled=true" config
+ atf_check -s exit:1 grep -q "^monitor=" config
+}
+
+check_deprecated_option()
+{
+ local old="$1" new="$2" value="$3"
+
+ atf_check -s exit:1 -o save:config \
+ -e match:"'${old}' is deprecated, use '${new}' instead" \
+ bhyve -o "${old}=${value}" -o config.dump=1 test-vm
+
+ atf_check grep -Fxq "${new}=${value}" config
+ atf_check -s exit:1 grep -Fq "${old}=" config
+}
+
+check_deprecated_option_both()
+{
+ local old="$1" new="$2" old_value="$3" new_value="$4"
+
+ # The new option takes precedence regardless of the order
+ atf_check -s exit:1 -o save:config \
+ bhyve -o "${old}=${old_value}" -o "${new}=${new_value}" \
+ -o config.dump=1 test-vm
+ atf_check grep -Fxq "${new}=${new_value}" config
+ atf_check -s exit:1 grep -Fq "${old}=" config
+
+ atf_check -s exit:1 -o save:config \
+ bhyve -o "${new}=${new_value}" -o "${old}=${old_value}" \
+ -o config.dump=1 test-vm
+ atf_check grep -Fxq "${new}=${new_value}" config
+ atf_check -s exit:1 grep -Fq "${old}=" config
+}
+
+atf_test_case check_config_deprecated
+check_config_deprecated_head()
+{
+ atf_set "descr" "Check that deprecated options are renamed"
+ atf_set "require.progs" "bhyve"
+}
+
+check_config_deprecated_body()
+{
+ check_deprecated_option monitor monitor.enabled true
+ check_deprecated_option virtio_msix virtio.msix false
+ check_deprecated_option_both virtio_msix virtio.msix true false
+}
+
+atf_test_case check_config_deprecated_lpc
+check_config_deprecated_lpc_head()
+{
+ atf_set "descr" "Check that deprecated LPC options are renamed"
+ atf_set "require.arch" "amd64"
+ atf_set "require.progs" "bhyve"
+}
+
+check_config_deprecated_lpc_body()
+{
+ check_deprecated_option lpc.bootrom bootrom /path/to/rom
+ check_deprecated_option lpc.bootvars bootvars /path/to/vars
+ check_deprecated_option_both lpc.bootrom bootrom /old/rom /new/rom
+}
+
atf_init_test_cases()
{
atf_add_test_case check_s_list
atf_add_test_case check_l_list
atf_add_test_case check_o_list
atf_add_test_case check_config_dump_sanity
+ atf_add_test_case check_config_monitor
+ atf_add_test_case check_config_deprecated
+ atf_add_test_case check_config_deprecated_lpc
}

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 7, 6:50 PM (21 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42277383
Default Alt Text
D62519.1796669452.diff (4 KB)

Event Timeline