lib/kernel-args: Store kernel args as key/value entries

Define an `OstreeKernelArgsEntry` structure, which holds
both the key and the value. The kargs order array stores
entries for each key/value pair, instead of just the keys.
The hash table is used to locate entries, by storing
entries in a pointer array for each key. The same public
interface is preserved, while maintaining ordering
information of each key/value pair when
appending/replacing/deleting kargs.

Fixes: #1859
This commit is contained in:
Robert Fairley committed 2019-11-07 23:39:10 -05:00
1 parent 49513ccc1b
commit aadc4db012
4 files changed
+244 -92

No files matched your search

+4
View File
@@ -66,4 +66,8 @@ assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'option
assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*TESTARG=TESTVALUE'
assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*APPENDARG=VALAPPEND .*APPENDARG=2NDAPPEND'
# Check correct ordering of different-valued args of the same key.
${CMD_PREFIX} ostree admin deploy --os=testos --karg-append=FOO=TESTORDERED --karg-append=APPENDARG=3RDAPPEND testos:testos/buildmaster/x86_64-runtime
assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*APPENDARG=VALAPPEND .*APPENDARG=2NDAPPEND .*FOO=TESTORDERED .*APPENDARG=3RDAPPEND'
echo "ok deploy --karg-append"
+24 -15
View File
@@ -32,6 +32,22 @@ check_string_existance (OstreeKernelArgs *karg,
return g_strv_contains ((const char* const*) string_list, string_to_find);
}
static gboolean
kernel_args_entry_value_equal (gconstpointer data,
gconstpointer value)
{
const OstreeKernelArgsEntry *e = data;
return g_strcmp0 (_ostree_kernel_args_entry_get_value (e), value) == 0;
}
static gboolean
kernel_args_entry_key_equal (gconstpointer data,
gconstpointer key)
{
const OstreeKernelArgsEntry *e = data;
return g_strcmp0 (_ostree_kernel_args_entry_get_key (e), key) == 0;
}
static void
test_kargs_delete (void)
{
@@ -82,7 +98,7 @@ test_kargs_delete (void)
g_assert (ret);
/* verify the value array is properly updated */
GPtrArray *kargs_array = _ostree_kernel_arg_get_key_array (karg);
g_assert (!ot_ptr_array_find_with_equal_func (kargs_array, "single_key", g_str_equal, NULL));
g_assert (!ot_ptr_array_find_with_equal_func (kargs_array, "single_key", kernel_args_entry_value_equal, NULL));
g_assert (!check_string_existance (karg, "single_key"));
/* Delete specific key/value pair */
@@ -177,13 +193,6 @@ test_kargs_replace (void)
g_assert (check_string_existance (karg, "test=newval"));
}
static gboolean
strcmp0_equal (gconstpointer v1,
gconstpointer v2)
{
return g_strcmp0 (v1, v2) == 0;
}
/* In this function, we want to verify that ostree_kernel_args_append
* and ostree_kernel_args_to_string is correct. After that
* we will use these two functions(append and tostring) in other tests: delete and replace
@@ -208,22 +217,22 @@ test_kargs_append (void)
{
if (g_str_equal (key, "test"))
{
g_assert (ot_ptr_array_find_with_equal_func (value_array, "valid", strcmp0_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (value_array, "secondvalid", strcmp0_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (value_array, "", strcmp0_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, strcmp0_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (value_array, "valid", kernel_args_entry_value_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (value_array, "secondvalid", kernel_args_entry_value_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (value_array, "", kernel_args_entry_value_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, kernel_args_entry_value_equal, NULL));
}
else
{
g_assert_cmpstr (key, ==, "second_test");
g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, strcmp0_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, kernel_args_entry_value_equal, NULL));
}
}
/* verify the value array is properly updated */
GPtrArray *kargs_array = _ostree_kernel_arg_get_key_array (append_arg);
g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "test", g_str_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "second_test", g_str_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "test", kernel_args_entry_key_equal, NULL));
g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "second_test", kernel_args_entry_key_equal, NULL));
/* Up till this point, we verified that the above was all correct, we then
* check ostree_kernel_args_to_string has the right result