@@ -45,6 +45,7 @@ static void print_help(char *const name)
45
45
" -d --data-disk Path to a data disk in raw format\n"
46
46
" -h --help Show help\n"
47
47
" -i --initrd Path to initramfs\n"
48
+ " -n --nested Enabled nested virtualization\n"
48
49
" --net=NET_MODE Set network mode\n"
49
50
" --passt-socket=PATH Connect to passt socket at PATH"
50
51
"\n"
@@ -63,6 +64,7 @@ static const struct option long_options[] = {
63
64
{"kernel-cmdline" , required_argument , NULL , 'c' },
64
65
{"data-disk" , required_argument , NULL , 'd' },
65
66
{"initrd-path" , required_argument , NULL , 'i' },
67
+ {"nested" , no_argument , NULL , 'n' },
66
68
{"help" , no_argument , NULL , 'h' },
67
69
{"passt-socket" , required_argument , NULL , 'P' },
68
70
{NULL , 0 , NULL , 0 }};
@@ -77,6 +79,7 @@ struct cmdline
77
79
char const * kernel_path ;
78
80
char const * kernel_cmdline ;
79
81
char const * initrd_path ;
82
+ bool nested ;
80
83
};
81
84
82
85
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)
93
96
.kernel_path = NULL ,
94
97
.kernel_cmdline = NULL ,
95
98
.initrd_path = NULL ,
99
+ .nested = false,
96
100
};
97
101
98
102
int option_index = 0 ;
99
103
int c ;
100
104
// 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 )
102
106
{
103
107
switch (c )
104
108
{
@@ -117,6 +121,9 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
117
121
case 'i' :
118
122
cmdline -> initrd_path = optarg ;
119
123
break ;
124
+ case 'n' :
125
+ cmdline -> nested = true;
126
+ break ;
120
127
case 'P' :
121
128
cmdline -> passt_socket_path = optarg ;
122
129
break ;
@@ -307,6 +314,14 @@ int main(int argc, char *const argv[])
307
314
return -1 ;
308
315
}
309
316
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
+
310
325
// Start and enter the microVM. Unless there is some error while creating the microVM
311
326
// this function never returns.
312
327
if (err = krun_start_enter (ctx_id ))
0 commit comments