X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/b0df98f3a2968eb5aba3075d1cf9b1a3931907e0..91b5d028786b22bc4fe89b439ea55276ad09ec8a:/vl.c diff --git a/vl.c b/vl.c index 910abb6526..c03edf1bfb 100644 --- a/vl.c +++ b/vl.c @@ -263,9 +263,9 @@ static NotifierList exit_notifiers = static NotifierList machine_init_done_notifiers = NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); -static int tcg_allowed = 1; -int kvm_allowed = 0; -int xen_allowed = 0; +static bool tcg_allowed = true; +bool kvm_allowed; +bool xen_allowed; uint32_t xen_domid; enum xen_mode xen_mode = XEN_EMULATE; static int tcg_tb_size; @@ -1244,21 +1244,79 @@ char *get_boot_devices_list(size_t *size) return list; } -static void numa_add(const char *optarg) +static void numa_node_parse_cpus(int nodenr, const char *cpus) { - char option[128]; char *endptr; unsigned long long value, endvalue; - int nodenr; - value = endvalue = 0ULL; + /* Empty CPU range strings will be considered valid, they will simply + * not set any bit in the CPU bitmap. + */ + if (!*cpus) { + return; + } + + if (parse_uint(cpus, &value, &endptr, 10) < 0) { + goto error; + } + if (*endptr == '-') { + if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) { + goto error; + } + } else if (*endptr == '\0') { + endvalue = value; + } else { + goto error; + } + + if (endvalue >= MAX_CPUMASK_BITS) { + endvalue = MAX_CPUMASK_BITS - 1; + fprintf(stderr, + "qemu: NUMA: A max of %d VCPUs are supported\n", + MAX_CPUMASK_BITS); + } + + if (endvalue < value) { + goto error; + } + + bitmap_set(node_cpumask[nodenr], value, endvalue-value+1); + return; + +error: + fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus); + exit(1); +} + +static void numa_add(const char *optarg) +{ + char option[128]; + char *endptr; + unsigned long long nodenr; - optarg = get_opt_name(option, 128, optarg, ',') + 1; + optarg = get_opt_name(option, 128, optarg, ','); + if (*optarg == ',') { + optarg++; + } if (!strcmp(option, "node")) { + + if (nb_numa_nodes >= MAX_NODES) { + fprintf(stderr, "qemu: too many NUMA nodes\n"); + exit(1); + } + if (get_param_value(option, 128, "nodeid", optarg) == 0) { nodenr = nb_numa_nodes; } else { - nodenr = strtoull(option, NULL, 10); + if (parse_uint_full(option, &nodenr, 10) < 0) { + fprintf(stderr, "qemu: Invalid NUMA nodeid: %s\n", option); + exit(1); + } + } + + if (nodenr >= MAX_NODES) { + fprintf(stderr, "qemu: invalid NUMA nodeid: %llu\n", nodenr); + exit(1); } if (get_param_value(option, 128, "mem", optarg) == 0) { @@ -1273,23 +1331,12 @@ static void numa_add(const char *optarg) node_mem[nodenr] = sval; } if (get_param_value(option, 128, "cpus", optarg) != 0) { - value = strtoull(option, &endptr, 10); - if (*endptr == '-') { - endvalue = strtoull(endptr+1, &endptr, 10); - } else { - endvalue = value; - } - - if (!(endvalue < MAX_CPUMASK_BITS)) { - endvalue = MAX_CPUMASK_BITS - 1; - fprintf(stderr, - "A max of %d CPUs are supported in a guest\n", - MAX_CPUMASK_BITS); - } - - bitmap_set(node_cpumask[nodenr], value, endvalue-value+1); + numa_node_parse_cpus(nodenr, option); } nb_numa_nodes++; + } else { + fprintf(stderr, "Invalid -numa option: %s\n", option); + exit(1); } } @@ -1380,8 +1427,9 @@ static int usb_device_del(const char *devname) int bus_num, addr; const char *p; - if (strstart(devname, "host:", &p)) - return usb_host_device_close(p); + if (strstart(devname, "host:", &p)) { + return -1; + } if (!usb_enabled(false)) { return -1; @@ -2158,6 +2206,13 @@ static DisplayType select_display(const char *p) #else fprintf(stderr, "Curses support is disabled\n"); exit(1); +#endif + } else if (strstart(p, "gtk", &opts)) { +#ifdef CONFIG_GTK + display = DT_GTK; +#else + fprintf(stderr, "GTK support is disabled\n"); + exit(1); #endif } else if (strstart(p, "none", &opts)) { display = DT_NONE; @@ -2236,6 +2291,7 @@ static int device_init_func(QemuOpts *opts, void *opaque) dev = qdev_device_add(opts); if (!dev) return -1; + object_unref(OBJECT(dev)); return 0; } @@ -2544,7 +2600,7 @@ static struct { const char *name; int (*available)(void); int (*init)(void); - int *allowed; + bool *allowed; } accel_list[] = { { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed }, { "xen", "Xen", xen_available, xen_init, &xen_allowed }, @@ -2557,8 +2613,8 @@ static int configure_accelerator(void) const char *p = NULL; char buf[10]; int i, ret; - bool accel_initialised = 0; - bool init_failed = 0; + bool accel_initialised = false; + bool init_failed = false; QemuOptsList *list = qemu_find_opts("machine"); if (!QTAILQ_EMPTY(&list->head)) { @@ -2577,21 +2633,21 @@ static int configure_accelerator(void) p = get_opt_name(buf, sizeof (buf), p, ':'); for (i = 0; i < ARRAY_SIZE(accel_list); i++) { if (strcmp(accel_list[i].opt_name, buf) == 0) { - *(accel_list[i].allowed) = 1; + if (!accel_list[i].available()) { + printf("%s not supported for this target\n", + accel_list[i].name); + continue; + } + *(accel_list[i].allowed) = true; ret = accel_list[i].init(); if (ret < 0) { - init_failed = 1; - if (!accel_list[i].available()) { - printf("%s not supported for this target\n", - accel_list[i].name); - } else { - fprintf(stderr, "failed to initialize %s: %s\n", - accel_list[i].name, - strerror(-ret)); - } - *(accel_list[i].allowed) = 0; + init_failed = true; + fprintf(stderr, "failed to initialize %s: %s\n", + accel_list[i].name, + strerror(-ret)); + *(accel_list[i].allowed) = false; } else { - accel_initialised = 1; + accel_initialised = true; } break; } @@ -2602,7 +2658,9 @@ static int configure_accelerator(void) } if (!accel_initialised) { - fprintf(stderr, "No accelerator found!\n"); + if (!init_failed) { + fprintf(stderr, "No accelerator found!\n"); + } exit(1); } @@ -2936,7 +2994,7 @@ int main(int argc, char **argv, char **envp) drive_add(IF_MTD, -1, optarg, MTD_OPTS); break; case QEMU_OPTION_sd: - drive_add(IF_SD, 0, optarg, SD_OPTS); + drive_add(IF_SD, -1, optarg, SD_OPTS); break; case QEMU_OPTION_pflash: drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); @@ -2994,10 +3052,6 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_numa: - if (nb_numa_nodes >= MAX_NODES) { - fprintf(stderr, "qemu: too many NUMA nodes\n"); - exit(1); - } numa_add(optarg); break; case QEMU_OPTION_display: @@ -3089,8 +3143,10 @@ int main(int argc, char **argv, char **envp) exit(1); } } - qemu_opts_parse(qemu_find_opts("boot-opts"), - optarg, 0); + if (!qemu_opts_parse(qemu_find_opts("boot-opts"), + optarg, 0)) { + exit(1); + } } } break; @@ -3288,7 +3344,6 @@ int main(int argc, char **argv, char **envp) } opts = qemu_opts_parse(olist, optarg, 1); if (!opts) { - fprintf(stderr, "parse error: %s\n", optarg); exit(1); } break; @@ -3304,7 +3359,6 @@ int main(int argc, char **argv, char **envp) } opts = qemu_opts_parse(olist, optarg, 1); if (!opts) { - fprintf(stderr, "parse error: %s\n", optarg); exit(1); } @@ -3475,7 +3529,6 @@ int main(int argc, char **argv, char **envp) olist = qemu_find_opts("machine"); opts = qemu_opts_parse(olist, optarg, 1); if (!opts) { - fprintf(stderr, "parse error: %s\n", optarg); exit(1); } optarg = qemu_opt_get(opts, "type"); @@ -3580,6 +3633,9 @@ int main(int argc, char **argv, char **envp) exit(1); } opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1); + if (!opts) { + exit(1); + } option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); option_rom[nb_option_roms].bootindex = qemu_opt_get_number(opts, "bootindex", -1); @@ -3709,9 +3765,9 @@ int main(int argc, char **argv, char **envp) } opts = qemu_opts_parse(olist, optarg, 0); if (!opts) { - fprintf(stderr, "parse error: %s\n", optarg); exit(1); } + display_remote++; break; case QEMU_OPTION_writeconfig: { @@ -3738,14 +3794,14 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_sandbox: opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1); if (!opts) { - exit(0); + exit(1); } break; case QEMU_OPTION_add_fd: #ifndef _WIN32 opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0); if (!opts) { - exit(0); + exit(1); } #else error_report("File descriptor passing is disabled on this " @@ -3755,6 +3811,9 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_object: opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1); + if (!opts) { + exit(1); + } break; default: os_parse_cmd_args(popt->index, optarg); @@ -3814,10 +3873,17 @@ int main(int argc, char **argv, char **envp) * location or level of logging. */ if (log_mask) { + int mask; if (log_file) { - set_cpu_log_filename(log_file); + qemu_set_log_filename(log_file); } - set_cpu_log(log_mask); + + mask = qemu_str_to_log_mask(log_mask); + if (!mask) { + qemu_print_log_usage(stdout); + exit(1); + } + qemu_set_log(mask); } if (!trace_backend_init(trace_events, trace_file)) { @@ -3941,6 +4007,25 @@ int main(int argc, char **argv, char **envp) } } + if (display_type == DT_DEFAULT && !display_remote) { +#if defined(CONFIG_GTK) + display_type = DT_GTK; +#elif defined(CONFIG_SDL) || defined(CONFIG_COCOA) + display_type = DT_SDL; +#elif defined(CONFIG_VNC) + vnc_display = "localhost:0,to=99"; + show_vnc_port = 1; +#else + display_type = DT_NONE; +#endif + } + +#if defined(CONFIG_GTK) + if (display_type == DT_GTK) { + early_gtk_display_init(); + } +#endif + socket_init(); if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0) @@ -4169,20 +4254,6 @@ int main(int argc, char **argv, char **envp) /* just use the first displaystate for the moment */ ds = get_displaystate(); - if (using_spice) - display_remote++; - if (display_type == DT_DEFAULT && !display_remote) { -#if defined(CONFIG_SDL) || defined(CONFIG_COCOA) - display_type = DT_SDL; -#elif defined(CONFIG_VNC) - vnc_display = "localhost:0,to=99"; - show_vnc_port = 1; -#else - display_type = DT_NONE; -#endif - } - - /* init local displays */ switch (display_type) { case DT_NOGRAPHIC: @@ -4200,6 +4271,11 @@ int main(int argc, char **argv, char **envp) case DT_SDL: cocoa_display_init(ds, full_screen); break; +#endif +#if defined(CONFIG_GTK) + case DT_GTK: + gtk_display_init(ds); + break; #endif default: break;