Skip to content

Commit 7d1d15d

Browse files
committed
krun: Configure VM with pre-parsed config tree
The krun VM config was parsed before the VM was configured. Use the pre-parsed config tree already available instead of parsing it once more. Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
1 parent 13fcca9 commit 7d1d15d

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/libcrun/handlers/krun.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -159,39 +159,28 @@ libkrun_read_vm_config (yajl_val *config_tree, libcrun_error_t *err)
159159
}
160160

161161
static int
162-
libkrun_configure_vm (uint32_t ctx_id, void *handle, bool *configured, libcrun_error_t *err)
162+
libkrun_configure_vm (uint32_t ctx_id, void *handle, bool *configured, yajl_val *config_tree, libcrun_error_t *err)
163163
{
164164
int32_t (*krun_set_vm_config) (uint32_t ctx_id, uint8_t num_vcpus, uint32_t ram_mib);
165-
struct parser_context ctx = { 0, stderr };
166-
cleanup_free char *config = NULL;
167-
yajl_val config_tree = NULL;
168165
yajl_val cpus = NULL;
169166
yajl_val ram_mib = NULL;
170167
const char *path_cpus[] = { "cpus", (const char *) 0 };
171168
const char *path_ram_mib[] = { "ram_mib", (const char *) 0 };
172169
int ret;
173170

174-
if (access (KRUN_VM_FILE, F_OK) != 0)
171+
if (*config_tree == NULL)
175172
return 0;
176173

177-
ret = read_all_file (KRUN_VM_FILE, &config, NULL, err);
178-
if (UNLIKELY (ret < 0))
179-
return ret;
180-
181-
ret = parse_json_file (&config_tree, config, &ctx, err);
182-
if (UNLIKELY (ret < 0))
183-
return ret;
184-
185174
/* Try to configure an external kernel. If the configuration file doesn't
186175
* specify a kernel, libkrun automatically fall back to using libkrunfw,
187176
* if the library is present and was loaded while creating the context.
188177
*/
189-
ret = libkrun_configure_kernel (ctx_id, handle, &config_tree, err);
178+
ret = libkrun_configure_kernel (ctx_id, handle, config_tree, err);
190179
if (UNLIKELY (ret))
191180
return ret;
192181

193-
cpus = yajl_tree_get (config_tree, path_cpus, yajl_t_number);
194-
ram_mib = yajl_tree_get (config_tree, path_ram_mib, yajl_t_number);
182+
cpus = yajl_tree_get (*config_tree, path_cpus, yajl_t_number);
183+
ram_mib = yajl_tree_get (*config_tree, path_ram_mib, yajl_t_number);
195184
/* Both cpus and ram_mib must be present at the same time */
196185
if (cpus == NULL || ram_mib == NULL || ! YAJL_IS_INTEGER (cpus) || ! YAJL_IS_INTEGER (ram_mib))
197186
return 0;
@@ -285,7 +274,7 @@ libkrun_exec (void *cookie, libcrun_container_t *container, const char *pathname
285274
error (EXIT_FAILURE, -ret, "could not set krun root");
286275
}
287276

288-
ret = libkrun_configure_vm (ctx_id, handle, &configured, &err);
277+
ret = libkrun_configure_vm (ctx_id, handle, &configured, &config_tree, &err);
289278
if (UNLIKELY (ret))
290279
{
291280
libcrun_error_t *tmp_err = &err;

0 commit comments

Comments
 (0)