Skip to content

Commit b965cf4

Browse files
committed
examples/external_kernel: support nested virt
Add the flag "-n" to request the enablement of nested virtualization. Signed-off-by: Sergio Lopez <[email protected]>
1 parent d185043 commit b965cf4

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

examples/external_kernel.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static void print_help(char *const name)
4545
" -d --data-disk Path to a data disk in raw format\n"
4646
" -h --help Show help\n"
4747
" -i --initrd Path to initramfs\n"
48+
" -n --nested Enabled nested virtualization\n"
4849
" --net=NET_MODE Set network mode\n"
4950
" --passt-socket=PATH Connect to passt socket at PATH"
5051
"\n"
@@ -63,6 +64,7 @@ static const struct option long_options[] = {
6364
{"kernel-cmdline", required_argument, NULL, 'c'},
6465
{"data-disk", required_argument, NULL, 'd'},
6566
{"initrd-path", required_argument, NULL, 'i'},
67+
{"nested", no_argument, NULL, 'n'},
6668
{"help", no_argument, NULL, 'h'},
6769
{"passt-socket", required_argument, NULL, 'P'},
6870
{NULL, 0, NULL, 0}};
@@ -77,6 +79,7 @@ struct cmdline
7779
char const *kernel_path;
7880
char const *kernel_cmdline;
7981
char const *initrd_path;
82+
bool nested;
8083
};
8184

8285
bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
@@ -93,12 +96,13 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
9396
.kernel_path = NULL,
9497
.kernel_cmdline = NULL,
9598
.initrd_path = NULL,
99+
.nested = false,
96100
};
97101

98102
int option_index = 0;
99103
int c;
100104
// the '+' in optstring is a GNU extension that disables permutating argv
101-
while ((c = getopt_long(argc, argv, "+hb:c:d:i:", long_options, &option_index)) != -1)
105+
while ((c = getopt_long(argc, argv, "+hb:c:d:i:n", long_options, &option_index)) != -1)
102106
{
103107
switch (c)
104108
{
@@ -117,6 +121,9 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
117121
case 'i':
118122
cmdline->initrd_path = optarg;
119123
break;
124+
case 'n':
125+
cmdline->nested = true;
126+
break;
120127
case 'P':
121128
cmdline->passt_socket_path = optarg;
122129
break;
@@ -307,6 +314,14 @@ int main(int argc, char *const argv[])
307314
return -1;
308315
}
309316

317+
fprintf(stderr, "nested=%d\n", cmdline.nested);
318+
if (err = krun_set_nested_virt(ctx_id, cmdline.nested))
319+
{
320+
errno = -err;
321+
perror("Error configuring nested virtualization");
322+
return -1;
323+
}
324+
310325
// Start and enter the microVM. Unless there is some error while creating the microVM
311326
// this function never returns.
312327
if (err = krun_start_enter(ctx_id))

0 commit comments

Comments
 (0)