/* Needed early for CONFIG_BSD etc. */
#include "config-host.h"
-/* Needed early to override system queue definitions on BSD */
-#include "sys-queue.h"
#ifndef _WIN32
#include <libgen.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
-#if defined(__NetBSD__)
-#include <net/if_tap.h>
-#endif
-#ifdef __linux__
-#include <linux/if_tun.h>
-#endif
#include <arpa/inet.h>
#include <dirent.h>
#include <netdb.h>
#include <sys/select.h>
#ifdef CONFIG_BSD
#include <sys/stat.h>
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
#include <libutil.h>
#else
#include <util.h>
#endif
-#elif defined (__GLIBC__) && defined (__FreeBSD_kernel__)
-#include <freebsd/stdlib.h>
#else
#ifdef __linux__
#include <pty.h>
#include <net/if.h>
#include <syslog.h>
#include <stropts.h>
+/* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
+ discussion about Solaris header problems */
+extern int madvise(caddr_t, size_t, int);
#endif
#endif
#endif
#include "hw/smbios.h"
#include "hw/xen.h"
#include "hw/qdev.h"
+#include "hw/loader.h"
#include "bt-host.h"
#include "net.h"
+#include "net/slirp.h"
#include "monitor.h"
#include "console.h"
#include "sysemu.h"
#include "qemu-char.h"
#include "cache-utils.h"
#include "block.h"
+#include "block_int.h"
+#include "block-migration.h"
#include "dma.h"
#include "audio/audio.h"
#include "migration.h"
#include "balloon.h"
#include "qemu-option.h"
#include "qemu-config.h"
+#include "qemu-objects.h"
#include "disas.h"
#include "slirp/libslirp.h"
+#include "qemu-queue.h"
+
//#define DEBUG_NET
//#define DEBUG_SLIRP
#define DEFAULT_RAM_SIZE 128
+#define MAX_VIRTIO_CONSOLES 1
+
static const char *data_dir;
const char *bios_name = NULL;
/* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
to store the VM snapshots */
-struct drivelist drives = TAILQ_HEAD_INITIALIZER(drives);
-struct driveoptlist driveopts = TAILQ_HEAD_INITIALIZER(driveopts);
+struct drivelist drives = QTAILQ_HEAD_INITIALIZER(drives);
+struct driveoptlist driveopts = QTAILQ_HEAD_INITIALIZER(driveopts);
enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
static DisplayState *display_state;
DisplayType display_type = DT_DEFAULT;
const char* keyboard_layout = NULL;
-int64_t ticks_per_sec;
ram_addr_t ram_size;
int nb_nics;
NICInfo nd_table[MAX_NICS];
int autostart;
static int rtc_utc = 1;
static int rtc_date_offset = -1; /* -1 means no change */
-int vga_interface_type = VGA_CIRRUS;
+QEMUClock *rtc_clock;
+int vga_interface_type = VGA_NONE;
#ifdef TARGET_SPARC
int graphic_width = 1024;
int graphic_height = 768;
int singlestep = 0;
int smp_cpus = 1;
int max_cpus = 0;
+int smp_cores = 1;
+int smp_threads = 1;
const char *vnc_display;
int acpi_enabled = 1;
int no_hpet = 0;
-int virtio_balloon = 1;
-const char *virtio_balloon_devaddr;
int fd_bootchk = 1;
int no_reboot = 0;
int no_shutdown = 0;
#ifndef _WIN32
int daemonize = 0;
#endif
-WatchdogTimerModel *watchdog = NULL;
-int watchdog_action = WDT_RESET;
+const char *watchdog;
const char *option_rom[MAX_OPTION_ROMS];
int nb_option_roms;
int semihosting_enabled = 0;
#endif
const char *qemu_name;
int alt_grab = 0;
+int ctrl_grab = 0;
#if defined(TARGET_SPARC) || defined(TARGET_PPC)
unsigned int nb_prom_envs = 0;
const char *prom_envs[MAX_PROM_ENVS];
static QEMUBootSetHandler *boot_set_handler;
static void *boot_set_opaque;
+static int default_serial = 1;
+static int default_parallel = 1;
+static int default_virtcon = 1;
+static int default_monitor = 1;
+static int default_vga = 1;
+static int default_floppy = 1;
+static int default_cdrom = 1;
+static int default_sdcard = 1;
+
+static struct {
+ const char *driver;
+ int *flag;
+} default_list[] = {
+ { .driver = "isa-serial", .flag = &default_serial },
+ { .driver = "isa-parallel", .flag = &default_parallel },
+ { .driver = "isa-fdc", .flag = &default_floppy },
+ { .driver = "ide-drive", .flag = &default_cdrom },
+ { .driver = "virtio-serial-pci", .flag = &default_virtcon },
+ { .driver = "virtio-serial-s390", .flag = &default_virtcon },
+ { .driver = "virtio-serial", .flag = &default_virtcon },
+ { .driver = "VGA", .flag = &default_vga },
+ { .driver = "cirrus-vga", .flag = &default_vga },
+ { .driver = "vmware-svga", .flag = &default_vga },
+};
+
+static int default_driver_check(QemuOpts *opts, void *opaque)
+{
+ const char *driver = qemu_opt_get(opts, "driver");
+ int i;
+
+ if (!driver)
+ return 0;
+ for (i = 0; i < ARRAY_SIZE(default_list); i++) {
+ if (strcmp(default_list[i].driver, driver) != 0)
+ continue;
+ *(default_list[i].flag) = 0;
+ }
+ return 0;
+}
+
/***********************************************************/
/* x86 ISA bus support */
qemu_balloon_event_opaque = opaque;
}
-void qemu_balloon(ram_addr_t target)
-{
- if (qemu_balloon_event)
- qemu_balloon_event(qemu_balloon_event_opaque, target);
-}
-
-ram_addr_t qemu_balloon_status(void)
-{
- if (qemu_balloon_event)
- return qemu_balloon_event(qemu_balloon_event_opaque, 0);
- return 0;
-}
-
-/***********************************************************/
-/* keyboard/mouse */
-
-static QEMUPutKBDEvent *qemu_put_kbd_event;
-static void *qemu_put_kbd_event_opaque;
-static QEMUPutMouseEntry *qemu_put_mouse_event_head;
-static QEMUPutMouseEntry *qemu_put_mouse_event_current;
-
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
-{
- qemu_put_kbd_event_opaque = opaque;
- qemu_put_kbd_event = func;
-}
-
-QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
- void *opaque, int absolute,
- const char *name)
-{
- QEMUPutMouseEntry *s, *cursor;
-
- s = qemu_mallocz(sizeof(QEMUPutMouseEntry));
-
- s->qemu_put_mouse_event = func;
- s->qemu_put_mouse_event_opaque = opaque;
- s->qemu_put_mouse_event_absolute = absolute;
- s->qemu_put_mouse_event_name = qemu_strdup(name);
- s->next = NULL;
-
- if (!qemu_put_mouse_event_head) {
- qemu_put_mouse_event_head = qemu_put_mouse_event_current = s;
- return s;
- }
-
- cursor = qemu_put_mouse_event_head;
- while (cursor->next != NULL)
- cursor = cursor->next;
-
- cursor->next = s;
- qemu_put_mouse_event_current = s;
-
- return s;
-}
-
-void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
-{
- QEMUPutMouseEntry *prev = NULL, *cursor;
-
- if (!qemu_put_mouse_event_head || entry == NULL)
- return;
-
- cursor = qemu_put_mouse_event_head;
- while (cursor != NULL && cursor != entry) {
- prev = cursor;
- cursor = cursor->next;
- }
-
- if (cursor == NULL) // does not exist or list empty
- return;
- else if (prev == NULL) { // entry is head
- qemu_put_mouse_event_head = cursor->next;
- if (qemu_put_mouse_event_current == entry)
- qemu_put_mouse_event_current = cursor->next;
- qemu_free(entry->qemu_put_mouse_event_name);
- qemu_free(entry);
- return;
- }
-
- prev->next = entry->next;
-
- if (qemu_put_mouse_event_current == entry)
- qemu_put_mouse_event_current = prev;
-
- qemu_free(entry->qemu_put_mouse_event_name);
- qemu_free(entry);
-}
-
-void kbd_put_keycode(int keycode)
-{
- if (qemu_put_kbd_event) {
- qemu_put_kbd_event(qemu_put_kbd_event_opaque, keycode);
- }
-}
-
-void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
+int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
{
- QEMUPutMouseEvent *mouse_event;
- void *mouse_event_opaque;
- int width;
-
- if (!qemu_put_mouse_event_current) {
- return;
- }
-
- mouse_event =
- qemu_put_mouse_event_current->qemu_put_mouse_event;
- mouse_event_opaque =
- qemu_put_mouse_event_current->qemu_put_mouse_event_opaque;
-
- if (mouse_event) {
- if (graphic_rotate) {
- if (qemu_put_mouse_event_current->qemu_put_mouse_event_absolute)
- width = 0x7fff;
- else
- width = graphic_width - 1;
- mouse_event(mouse_event_opaque,
- width - dy, dx, dz, buttons_state);
- } else
- mouse_event(mouse_event_opaque,
- dx, dy, dz, buttons_state);
+ if (qemu_balloon_event) {
+ qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque);
+ return 1;
+ } else {
+ return 0;
}
}
-int kbd_mouse_is_absolute(void)
+int qemu_balloon_status(MonitorCompletion cb, void *opaque)
{
- if (!qemu_put_mouse_event_current)
+ if (qemu_balloon_event) {
+ qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque);
+ return 1;
+ } else {
return 0;
-
- return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute;
-}
-
-void do_info_mice(Monitor *mon)
-{
- QEMUPutMouseEntry *cursor;
- int index = 0;
-
- if (!qemu_put_mouse_event_head) {
- monitor_printf(mon, "No mouse devices connected\n");
- return;
- }
-
- monitor_printf(mon, "Mouse devices available:\n");
- cursor = qemu_put_mouse_event_head;
- while (cursor != NULL) {
- monitor_printf(mon, "%c Mouse #%d: %s\n",
- (cursor == qemu_put_mouse_event_current ? '*' : ' '),
- index, cursor->qemu_put_mouse_event_name);
- index++;
- cursor = cursor->next;
}
}
-void do_mouse_set(Monitor *mon, int index)
-{
- QEMUPutMouseEntry *cursor;
- int i = 0;
-
- if (!qemu_put_mouse_event_head) {
- monitor_printf(mon, "No mouse devices connected\n");
- return;
- }
-
- cursor = qemu_put_mouse_event_head;
- while (cursor != NULL && index != i) {
- i++;
- cursor = cursor->next;
- }
- if (cursor != NULL)
- qemu_put_mouse_event_current = cursor;
- else
- monitor_printf(mon, "Mouse at given index not found\n");
-}
+/***********************************************************/
+/* real time host monotonic timer */
/* compute with 96 bit intermediate result: (a*b)/c */
uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
return res.ll;
}
-/***********************************************************/
-/* real time host monotonic timer */
+static int64_t get_clock_realtime(void)
+{
+ struct timeval tv;
-#define QEMU_TIMER_BASE 1000000000LL
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000);
+}
#ifdef WIN32
{
LARGE_INTEGER ti;
QueryPerformanceCounter(&ti);
- return muldiv64(ti.QuadPart, QEMU_TIMER_BASE, clock_freq);
+ return muldiv64(ti.QuadPart, get_ticks_per_sec(), clock_freq);
}
#else
{
use_rt_clock = 0;
#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \
- || defined(__DragonFly__)
+ || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
static int64_t get_clock(void)
{
#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \
- || defined(__DragonFly__)
+ || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
if (use_rt_clock) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
{
/* XXX: using gettimeofday leads to problems if the date
changes, so it should be avoided. */
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000);
+ return get_clock_realtime();
}
}
#endif
/***********************************************************/
/* guest cycle counter */
-static int64_t cpu_ticks_prev;
-static int64_t cpu_ticks_offset;
-static int64_t cpu_clock_offset;
-static int cpu_ticks_enabled;
+typedef struct TimersState {
+ int64_t cpu_ticks_prev;
+ int64_t cpu_ticks_offset;
+ int64_t cpu_clock_offset;
+ int32_t cpu_ticks_enabled;
+ int64_t dummy;
+} TimersState;
+
+TimersState timers_state;
/* return the host CPU cycle counter and handle stop/restart */
int64_t cpu_get_ticks(void)
if (use_icount) {
return cpu_get_icount();
}
- if (!cpu_ticks_enabled) {
- return cpu_ticks_offset;
+ if (!timers_state.cpu_ticks_enabled) {
+ return timers_state.cpu_ticks_offset;
} else {
int64_t ticks;
ticks = cpu_get_real_ticks();
- if (cpu_ticks_prev > ticks) {
+ if (timers_state.cpu_ticks_prev > ticks) {
/* Note: non increasing ticks may happen if the host uses
software suspend */
- cpu_ticks_offset += cpu_ticks_prev - ticks;
+ timers_state.cpu_ticks_offset += timers_state.cpu_ticks_prev - ticks;
}
- cpu_ticks_prev = ticks;
- return ticks + cpu_ticks_offset;
+ timers_state.cpu_ticks_prev = ticks;
+ return ticks + timers_state.cpu_ticks_offset;
}
}
static int64_t cpu_get_clock(void)
{
int64_t ti;
- if (!cpu_ticks_enabled) {
- return cpu_clock_offset;
+ if (!timers_state.cpu_ticks_enabled) {
+ return timers_state.cpu_clock_offset;
} else {
ti = get_clock();
- return ti + cpu_clock_offset;
+ return ti + timers_state.cpu_clock_offset;
}
}
/* enable cpu_get_ticks() */
void cpu_enable_ticks(void)
{
- if (!cpu_ticks_enabled) {
- cpu_ticks_offset -= cpu_get_real_ticks();
- cpu_clock_offset -= get_clock();
- cpu_ticks_enabled = 1;
+ if (!timers_state.cpu_ticks_enabled) {
+ timers_state.cpu_ticks_offset -= cpu_get_real_ticks();
+ timers_state.cpu_clock_offset -= get_clock();
+ timers_state.cpu_ticks_enabled = 1;
}
}
cpu_get_ticks() after that. */
void cpu_disable_ticks(void)
{
- if (cpu_ticks_enabled) {
- cpu_ticks_offset = cpu_get_ticks();
- cpu_clock_offset = cpu_get_clock();
- cpu_ticks_enabled = 0;
+ if (timers_state.cpu_ticks_enabled) {
+ timers_state.cpu_ticks_offset = cpu_get_ticks();
+ timers_state.cpu_clock_offset = cpu_get_clock();
+ timers_state.cpu_ticks_enabled = 0;
}
}
/***********************************************************/
/* timers */
-#define QEMU_TIMER_REALTIME 0
-#define QEMU_TIMER_VIRTUAL 1
+#define QEMU_CLOCK_REALTIME 0
+#define QEMU_CLOCK_VIRTUAL 1
+#define QEMU_CLOCK_HOST 2
struct QEMUClock {
int type;
fairly approximate, so ignore small variation.
When the guest is idle real and virtual time will be aligned in
the IO wait loop. */
-#define ICOUNT_WOBBLE (QEMU_TIMER_BASE / 10)
+#define ICOUNT_WOBBLE (get_ticks_per_sec() / 10)
static void icount_adjust(void)
{
static void icount_adjust_vm(void * opaque)
{
qemu_mod_timer(icount_vm_timer,
- qemu_get_clock(vm_clock) + QEMU_TIMER_BASE / 10);
+ qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10);
icount_adjust();
}
qemu_get_clock(rt_clock) + 1000);
icount_vm_timer = qemu_new_timer(vm_clock, icount_adjust_vm, NULL);
qemu_mod_timer(icount_vm_timer,
- qemu_get_clock(vm_clock) + QEMU_TIMER_BASE / 10);
+ qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10);
}
static struct qemu_alarm_timer alarm_timers[] = {
exit(0);
}
- arg = strdup(opt);
+ arg = qemu_strdup(opt);
/* Reorder the array */
name = strtok(arg, ",");
name = strtok(NULL, ",");
}
- free(arg);
+ qemu_free(arg);
if (cur) {
/* Disable remaining timers */
}
}
+#define QEMU_NUM_CLOCKS 3
+
QEMUClock *rt_clock;
QEMUClock *vm_clock;
+QEMUClock *host_clock;
-static QEMUTimer *active_timers[2];
+static QEMUTimer *active_timers[QEMU_NUM_CLOCKS];
static QEMUClock *qemu_new_clock(int type)
{
int64_t qemu_get_clock(QEMUClock *clock)
{
switch(clock->type) {
- case QEMU_TIMER_REALTIME:
+ case QEMU_CLOCK_REALTIME:
return get_clock() / 1000000;
default:
- case QEMU_TIMER_VIRTUAL:
+ case QEMU_CLOCK_VIRTUAL:
if (use_icount) {
return cpu_get_icount();
} else {
return cpu_get_clock();
}
+ case QEMU_CLOCK_HOST:
+ return get_clock_realtime();
}
}
-static void init_timers(void)
+static void init_clocks(void)
{
init_get_clock();
- ticks_per_sec = QEMU_TIMER_BASE;
- rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME);
- vm_clock = qemu_new_clock(QEMU_TIMER_VIRTUAL);
+ rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME);
+ vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL);
+ host_clock = qemu_new_clock(QEMU_CLOCK_HOST);
+
+ rtc_clock = host_clock;
}
/* save a timer */
}
}
-static void timer_save(QEMUFile *f, void *opaque)
-{
- if (cpu_ticks_enabled) {
- hw_error("cannot save state if virtual timers are running");
- }
- qemu_put_be64(f, cpu_ticks_offset);
- qemu_put_be64(f, ticks_per_sec);
- qemu_put_be64(f, cpu_clock_offset);
-}
-
-static int timer_load(QEMUFile *f, void *opaque, int version_id)
-{
- if (version_id != 1 && version_id != 2)
- return -EINVAL;
- if (cpu_ticks_enabled) {
- return -EINVAL;
- }
- cpu_ticks_offset=qemu_get_be64(f);
- ticks_per_sec=qemu_get_be64(f);
- if (version_id == 2) {
- cpu_clock_offset=qemu_get_be64(f);
+static const VMStateDescription vmstate_timers = {
+ .name = "timer",
+ .version_id = 2,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .fields = (VMStateField []) {
+ VMSTATE_INT64(cpu_ticks_offset, TimersState),
+ VMSTATE_INT64(dummy, TimersState),
+ VMSTATE_INT64_V(cpu_clock_offset, TimersState, 2),
+ VMSTATE_END_OF_LIST()
}
- return 0;
-}
+};
static void qemu_event_increment(void);
delta_cum += delta;
if (++count == DISP_FREQ) {
printf("timer: min=%" PRId64 " us max=%" PRId64 " us avg=%" PRId64 " us avg_freq=%0.3f Hz\n",
- muldiv64(delta_min, 1000000, ticks_per_sec),
- muldiv64(delta_max, 1000000, ticks_per_sec),
- muldiv64(delta_cum, 1000000 / DISP_FREQ, ticks_per_sec),
- (double)ticks_per_sec / ((double)delta_cum / DISP_FREQ));
+ muldiv64(delta_min, 1000000, get_ticks_per_sec()),
+ muldiv64(delta_max, 1000000, get_ticks_per_sec()),
+ muldiv64(delta_cum, 1000000 / DISP_FREQ, get_ticks_per_sec()),
+ (double)get_ticks_per_sec() / ((double)delta_cum / DISP_FREQ));
count = 0;
delta_min = INT64_MAX;
delta_max = 0;
#endif
if (alarm_has_dynticks(alarm_timer) ||
(!use_icount &&
- qemu_timer_expired(active_timers[QEMU_TIMER_VIRTUAL],
+ qemu_timer_expired(active_timers[QEMU_CLOCK_VIRTUAL],
qemu_get_clock(vm_clock))) ||
- qemu_timer_expired(active_timers[QEMU_TIMER_REALTIME],
- qemu_get_clock(rt_clock))) {
+ qemu_timer_expired(active_timers[QEMU_CLOCK_REALTIME],
+ qemu_get_clock(rt_clock)) ||
+ qemu_timer_expired(active_timers[QEMU_CLOCK_HOST],
+ qemu_get_clock(host_clock))) {
qemu_event_increment();
if (alarm_timer) alarm_timer->flags |= ALARM_FLAG_EXPIRED;
static int64_t qemu_next_deadline(void)
{
- int64_t delta;
+ /* To avoid problems with overflow limit this to 2^32. */
+ int64_t delta = INT32_MAX;
- if (active_timers[QEMU_TIMER_VIRTUAL]) {
- delta = active_timers[QEMU_TIMER_VIRTUAL]->expire_time -
+ if (active_timers[QEMU_CLOCK_VIRTUAL]) {
+ delta = active_timers[QEMU_CLOCK_VIRTUAL]->expire_time -
qemu_get_clock(vm_clock);
- } else {
- /* To avoid problems with overflow limit this to 2^32. */
- delta = INT32_MAX;
+ }
+ if (active_timers[QEMU_CLOCK_HOST]) {
+ int64_t hdelta = active_timers[QEMU_CLOCK_HOST]->expire_time -
+ qemu_get_clock(host_clock);
+ if (hdelta < delta)
+ delta = hdelta;
}
if (delta < 0)
return delta;
}
-#if defined(__linux__) || defined(_WIN32)
+#if defined(__linux__)
static uint64_t qemu_next_deadline_dyntick(void)
{
int64_t delta;
else
delta = (qemu_next_deadline() + 999) / 1000;
- if (active_timers[QEMU_TIMER_REALTIME]) {
- rtdelta = (active_timers[QEMU_TIMER_REALTIME]->expire_time -
+ if (active_timers[QEMU_CLOCK_REALTIME]) {
+ rtdelta = (active_timers[QEMU_CLOCK_REALTIME]->expire_time -
qemu_get_clock(rt_clock))*1000;
if (rtdelta < delta)
delta = rtdelta;
struct hpet_info info;
int r, fd;
- fd = open("/dev/hpet", O_RDONLY);
+ fd = qemu_open("/dev/hpet", O_RDONLY);
if (fd < 0)
return -1;
int rtc_fd;
unsigned long current_rtc_freq = 0;
- TFR(rtc_fd = open("/dev/rtc", O_RDONLY));
+ TFR(rtc_fd = qemu_open("/dev/rtc", O_RDONLY));
if (rtc_fd < 0)
return -1;
ioctl(rtc_fd, RTC_IRQP_READ, ¤t_rtc_freq);
int64_t nearest_delta_us = INT64_MAX;
int64_t current_us;
- if (!active_timers[QEMU_TIMER_REALTIME] &&
- !active_timers[QEMU_TIMER_VIRTUAL])
+ if (!active_timers[QEMU_CLOCK_REALTIME] &&
+ !active_timers[QEMU_CLOCK_VIRTUAL] &&
+ !active_timers[QEMU_CLOCK_HOST])
return;
nearest_delta_us = qemu_next_deadline_dyntick();
flags);
if (!data->timerId) {
- perror("Failed to initialize win32 alarm timer");
+ fprintf(stderr, "Failed to initialize win32 alarm timer: %ld\n",
+ GetLastError());
timeEndPeriod(data->period);
return -1;
}
static void win32_rearm_timer(struct qemu_alarm_timer *t)
{
struct qemu_alarm_win32 *data = t->priv;
- uint64_t nearest_delta_us;
- if (!active_timers[QEMU_TIMER_REALTIME] &&
- !active_timers[QEMU_TIMER_VIRTUAL])
+ if (!active_timers[QEMU_CLOCK_REALTIME] &&
+ !active_timers[QEMU_CLOCK_VIRTUAL] &&
+ !active_timers[QEMU_CLOCK_HOST])
return;
- nearest_delta_us = qemu_next_deadline_dyntick();
- nearest_delta_us /= 1000;
-
timeKillEvent(data->timerId);
data->timerId = timeSetEvent(1,
TIME_ONESHOT | TIME_PERIODIC);
if (!data->timerId) {
- perror("Failed to re-arm win32 alarm timer");
+ fprintf(stderr, "Failed to re-arm win32 alarm timer %ld\n",
+ GetLastError());
timeEndPeriod(data->period);
exit(1);
return seconds - time(NULL);
}
+static void configure_rtc_date_offset(const char *startdate, int legacy)
+{
+ time_t rtc_start_date;
+ struct tm tm;
+
+ if (!strcmp(startdate, "now") && legacy) {
+ rtc_date_offset = -1;
+ } else {
+ if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
+ &tm.tm_year,
+ &tm.tm_mon,
+ &tm.tm_mday,
+ &tm.tm_hour,
+ &tm.tm_min,
+ &tm.tm_sec) == 6) {
+ /* OK */
+ } else if (sscanf(startdate, "%d-%d-%d",
+ &tm.tm_year,
+ &tm.tm_mon,
+ &tm.tm_mday) == 3) {
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ } else {
+ goto date_fail;
+ }
+ tm.tm_year -= 1900;
+ tm.tm_mon--;
+ rtc_start_date = mktimegm(&tm);
+ if (rtc_start_date == -1) {
+ date_fail:
+ fprintf(stderr, "Invalid date format. Valid formats are:\n"
+ "'2006-06-17T16:01:21' or '2006-06-17'\n");
+ exit(1);
+ }
+ rtc_date_offset = time(NULL) - rtc_start_date;
+ }
+}
+
+static void configure_rtc(QemuOpts *opts)
+{
+ const char *value;
+
+ value = qemu_opt_get(opts, "base");
+ if (value) {
+ if (!strcmp(value, "utc")) {
+ rtc_utc = 1;
+ } else if (!strcmp(value, "localtime")) {
+ rtc_utc = 0;
+ } else {
+ configure_rtc_date_offset(value, 0);
+ }
+ }
+ value = qemu_opt_get(opts, "clock");
+ if (value) {
+ if (!strcmp(value, "host")) {
+ rtc_clock = host_clock;
+ } else if (!strcmp(value, "vm")) {
+ rtc_clock = vm_clock;
+ } else {
+ fprintf(stderr, "qemu: invalid option value '%s'\n", value);
+ exit(1);
+ }
+ }
+#ifdef CONFIG_TARGET_I386
+ value = qemu_opt_get(opts, "driftfix");
+ if (value) {
+ if (!strcmp(buf, "slew")) {
+ rtc_td_hack = 1;
+ } else if (!strcmp(buf, "none")) {
+ rtc_td_hack = 0;
+ } else {
+ fprintf(stderr, "qemu: invalid option value '%s'\n", value);
+ exit(1);
+ }
+ }
+#endif
+}
+
#ifdef _WIN32
static void socket_cleanup(void)
{
/* seek interface, bus and unit */
- TAILQ_FOREACH(dinfo, &drives, next) {
+ QTAILQ_FOREACH(dinfo, &drives, next) {
if (dinfo->type == type &&
dinfo->bus == bus &&
dinfo->unit == unit)
{
DriveInfo *dinfo;
- TAILQ_FOREACH(dinfo, &drives, next) {
+ QTAILQ_FOREACH(dinfo, &drives, next) {
if (strcmp(id, dinfo->id))
continue;
return dinfo;
DriveInfo *dinfo;
max_bus = -1;
- TAILQ_FOREACH(dinfo, &drives, next) {
+ QTAILQ_FOREACH(dinfo, &drives, next) {
if(dinfo->type == type &&
dinfo->bus > max_bus)
max_bus = dinfo->bus;
{
DriveInfo *dinfo;
- TAILQ_FOREACH(dinfo, &drives, next) {
+ QTAILQ_FOREACH(dinfo, &drives, next) {
if (dinfo->bdrv == bdrv)
return dinfo->serial;
}
return "\0";
}
-BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv)
+BlockInterfaceErrorAction drive_get_on_error(
+ BlockDriverState *bdrv, int is_read)
{
DriveInfo *dinfo;
- TAILQ_FOREACH(dinfo, &drives, next) {
+ QTAILQ_FOREACH(dinfo, &drives, next) {
if (dinfo->bdrv == bdrv)
- return dinfo->onerror;
+ return is_read ? dinfo->on_read_error : dinfo->on_write_error;
}
- return BLOCK_ERR_STOP_ENOSPC;
+ return is_read ? BLOCK_ERR_REPORT : BLOCK_ERR_STOP_ENOSPC;
}
static void bdrv_format_print(void *opaque, const char *name)
fprintf(stderr, " %s", name);
}
-void drive_uninit(BlockDriverState *bdrv)
+void drive_uninit(DriveInfo *dinfo)
{
- DriveInfo *dinfo;
+ qemu_opts_del(dinfo->opts);
+ bdrv_delete(dinfo->bdrv);
+ QTAILQ_REMOVE(&drives, dinfo, next);
+ qemu_free(dinfo);
+}
- TAILQ_FOREACH(dinfo, &drives, next) {
- if (dinfo->bdrv != bdrv)
- continue;
- qemu_opts_del(dinfo->opts);
- TAILQ_REMOVE(&drives, dinfo, next);
- qemu_free(dinfo);
- break;
+static int parse_block_error_action(const char *buf, int is_read)
+{
+ if (!strcmp(buf, "ignore")) {
+ return BLOCK_ERR_IGNORE;
+ } else if (!is_read && !strcmp(buf, "enospc")) {
+ return BLOCK_ERR_STOP_ENOSPC;
+ } else if (!strcmp(buf, "stop")) {
+ return BLOCK_ERR_STOP_ANY;
+ } else if (!strcmp(buf, "report")) {
+ return BLOCK_ERR_REPORT;
+ } else {
+ fprintf(stderr, "qemu: '%s' invalid %s error action\n",
+ buf, is_read ? "read" : "write");
+ return -1;
}
}
int max_devs;
int index;
int cache;
- int bdrv_flags, onerror;
+ int aio = 0;
+ int ro = 0;
+ int bdrv_flags;
+ int on_read_error, on_write_error;
const char *devaddr;
DriveInfo *dinfo;
int snapshot = 0;
translation = BIOS_ATA_TRANSLATION_AUTO;
cache = 1;
- if (machine->use_scsi) {
+ if (machine && machine->use_scsi) {
type = IF_SCSI;
max_devs = MAX_SCSI_DEVS;
pstrcpy(devname, sizeof(devname), "scsi");
secs = qemu_opt_get_number(opts, "secs", 0);
snapshot = qemu_opt_get_bool(opts, "snapshot", 0);
+ ro = qemu_opt_get_bool(opts, "readonly", 0);
file = qemu_opt_get(opts, "file");
serial = qemu_opt_get(opts, "serial");
}
if (cyls || heads || secs) {
- if (cyls < 1 || cyls > 16383) {
+ if (cyls < 1 || (type == IF_IDE && cyls > 16383)) {
fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", buf);
return NULL;
}
- if (heads < 1 || heads > 16) {
+ if (heads < 1 || (type == IF_IDE && heads > 16)) {
fprintf(stderr, "qemu: '%s' invalid physical heads number\n", buf);
return NULL;
}
- if (secs < 1 || secs > 63) {
+ if (secs < 1 || (type == IF_IDE && secs > 63)) {
fprintf(stderr, "qemu: '%s' invalid physical secs number\n", buf);
return NULL;
}
}
}
+#ifdef CONFIG_LINUX_AIO
+ if ((buf = qemu_opt_get(opts, "aio")) != NULL) {
+ if (!strcmp(buf, "threads"))
+ aio = 0;
+ else if (!strcmp(buf, "native"))
+ aio = 1;
+ else {
+ fprintf(stderr, "qemu: invalid aio option\n");
+ return NULL;
+ }
+ }
+#endif
+
if ((buf = qemu_opt_get(opts, "format")) != NULL) {
if (strcmp(buf, "?") == 0) {
fprintf(stderr, "qemu: Supported formats:");
fprintf(stderr, "\n");
return NULL;
}
- drv = bdrv_find_format(buf);
+ drv = bdrv_find_whitelisted_format(buf);
if (!drv) {
fprintf(stderr, "qemu: '%s' invalid format\n", buf);
return NULL;
}
}
- onerror = BLOCK_ERR_STOP_ENOSPC;
+ on_write_error = BLOCK_ERR_STOP_ENOSPC;
if ((buf = qemu_opt_get(opts, "werror")) != NULL) {
if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) {
fprintf(stderr, "werror is no supported by this format\n");
return NULL;
}
- if (!strcmp(buf, "ignore"))
- onerror = BLOCK_ERR_IGNORE;
- else if (!strcmp(buf, "enospc"))
- onerror = BLOCK_ERR_STOP_ENOSPC;
- else if (!strcmp(buf, "stop"))
- onerror = BLOCK_ERR_STOP_ANY;
- else if (!strcmp(buf, "report"))
- onerror = BLOCK_ERR_REPORT;
- else {
- fprintf(stderr, "qemu: '%s' invalid write error action\n", buf);
+
+ on_write_error = parse_block_error_action(buf, 0);
+ if (on_write_error < 0) {
+ return NULL;
+ }
+ }
+
+ on_read_error = BLOCK_ERR_REPORT;
+ if ((buf = qemu_opt_get(opts, "rerror")) != NULL) {
+ if (type != IF_IDE && type != IF_VIRTIO) {
+ fprintf(stderr, "rerror is no supported by this format\n");
+ return NULL;
+ }
+
+ on_read_error = parse_block_error_action(buf, 1);
+ if (on_read_error < 0) {
return NULL;
}
}
dinfo->type = type;
dinfo->bus = bus_id;
dinfo->unit = unit_id;
- dinfo->onerror = onerror;
+ dinfo->on_read_error = on_read_error;
+ dinfo->on_write_error = on_write_error;
dinfo->opts = opts;
if (serial)
strncpy(dinfo->serial, serial, sizeof(serial));
- TAILQ_INSERT_TAIL(&drives, dinfo, next);
+ QTAILQ_INSERT_TAIL(&drives, dinfo, next);
switch(type) {
case IF_IDE:
case IF_SCSI:
case IF_XEN:
+ case IF_NONE:
switch(media) {
case MEDIA_DISK:
if (cyls != 0) {
break;
case IF_PFLASH:
case IF_MTD:
- case IF_NONE:
break;
case IF_VIRTIO:
/* add virtio block device */
bdrv_flags |= BDRV_O_NOCACHE;
else if (cache == 2) /* write-back */
bdrv_flags |= BDRV_O_CACHE_WB;
+
+ if (aio == 1) {
+ bdrv_flags |= BDRV_O_NATIVE_AIO;
+ } else {
+ bdrv_flags &= ~BDRV_O_NATIVE_AIO;
+ }
+
+ if (ro == 1) {
+ if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY) {
+ fprintf(stderr, "qemu: readonly flag not supported for drive with this interface\n");
+ return NULL;
+ }
+ }
+ /*
+ * cdrom is read-only. Set it now, after above interface checking
+ * since readonly attribute not explicitly required, so no error.
+ */
+ if (media == MEDIA_CDROM) {
+ ro = 1;
+ }
+ bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
+
if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
- fprintf(stderr, "qemu: could not open disk image %s\n",
- file);
+ fprintf(stderr, "qemu: could not open disk image %s: %s\n",
+ file, strerror(errno));
return NULL;
}
+
if (bdrv_key_required(dinfo->bdrv))
autostart = 0;
*fatal_error = 0;
return;
}
-/***********************************************************/
-/* USB devices */
-
-static USBPort *used_usb_ports;
-static USBPort *free_usb_ports;
-
-/* ??? Maybe change this to register a hub to keep track of the topology. */
-void qemu_register_usb_port(USBPort *port, void *opaque, int index,
- usb_attachfn attach)
-{
- port->opaque = opaque;
- port->index = index;
- port->attach = attach;
- port->next = free_usb_ports;
- free_usb_ports = port;
-}
-
-int usb_device_add_dev(USBDevice *dev)
+static void smp_parse(const char *optarg)
{
- USBPort *port;
-
- /* Find a USB port to add the device to. */
- port = free_usb_ports;
- if (!port->next) {
- USBDevice *hub;
-
- /* Create a new hub and chain it on. */
- free_usb_ports = NULL;
- port->next = used_usb_ports;
- used_usb_ports = port;
+ int smp, sockets = 0, threads = 0, cores = 0;
+ char *endptr;
+ char option[128];
- hub = usb_hub_init(VM_USB_HUB_SIZE);
- usb_attach(port, hub);
- port = free_usb_ports;
+ smp = strtoul(optarg, &endptr, 10);
+ if (endptr != optarg) {
+ if (*endptr == ',') {
+ endptr++;
+ }
}
-
- free_usb_ports = port->next;
- port->next = used_usb_ports;
- used_usb_ports = port;
- usb_attach(port, dev);
- return 0;
+ if (get_param_value(option, 128, "sockets", endptr) != 0)
+ sockets = strtoull(option, NULL, 10);
+ if (get_param_value(option, 128, "cores", endptr) != 0)
+ cores = strtoull(option, NULL, 10);
+ if (get_param_value(option, 128, "threads", endptr) != 0)
+ threads = strtoull(option, NULL, 10);
+ if (get_param_value(option, 128, "maxcpus", endptr) != 0)
+ max_cpus = strtoull(option, NULL, 10);
+
+ /* compute missing values, prefer sockets over cores over threads */
+ if (smp == 0 || sockets == 0) {
+ sockets = sockets > 0 ? sockets : 1;
+ cores = cores > 0 ? cores : 1;
+ threads = threads > 0 ? threads : 1;
+ if (smp == 0) {
+ smp = cores * threads * sockets;
+ }
+ } else {
+ if (cores == 0) {
+ threads = threads > 0 ? threads : 1;
+ cores = smp / (sockets * threads);
+ } else {
+ if (sockets) {
+ threads = smp / (cores * sockets);
+ }
+ }
+ }
+ smp_cpus = smp;
+ smp_cores = cores > 0 ? cores : 1;
+ smp_threads = threads > 0 ? threads : 1;
+ if (max_cpus == 0)
+ max_cpus = smp_cpus;
}
-static void usb_msd_password_cb(void *opaque, int err)
-{
- USBDevice *dev = opaque;
-
- if (!err)
- usb_device_add_dev(dev);
- else
- dev->handle_destroy(dev);
-}
+/***********************************************************/
+/* USB devices */
static int usb_device_add(const char *devname, int is_hotplug)
{
const char *p;
- USBDevice *dev;
+ USBDevice *dev = NULL;
- if (!free_usb_ports)
+ if (!usb_enabled)
return -1;
+ /* drivers with .usbdevice_name entry in USBDeviceInfo */
+ dev = usbdevice_create(devname);
+ if (dev)
+ goto done;
+
+ /* the other ones */
if (strstart(devname, "host:", &p)) {
dev = usb_host_device_open(p);
- } else if (!strcmp(devname, "mouse")) {
- dev = usb_mouse_init();
- } else if (!strcmp(devname, "tablet")) {
- dev = usb_tablet_init();
- } else if (!strcmp(devname, "keyboard")) {
- dev = usb_keyboard_init();
- } else if (strstart(devname, "disk:", &p)) {
- BlockDriverState *bs;
-
- dev = usb_msd_init(p);
- if (!dev)
- return -1;
- bs = usb_msd_get_bdrv(dev);
- if (bdrv_key_required(bs)) {
- autostart = 0;
- if (is_hotplug) {
- monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb,
- dev);
- return 0;
- }
- }
- } else if (!strcmp(devname, "wacom-tablet")) {
- dev = usb_wacom_init();
- } else if (strstart(devname, "serial:", &p)) {
- dev = usb_serial_init(p);
-#ifdef CONFIG_BRLAPI
- } else if (!strcmp(devname, "braille")) {
- dev = usb_baum_init();
-#endif
- } else if (strstart(devname, "net:", &p)) {
- int nic = nb_nics;
-
- if (net_client_init(NULL, "nic", p) < 0)
- return -1;
- nd_table[nic].model = "usb";
- dev = usb_net_init(&nd_table[nic]);
} else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
dev = usb_bt_init(devname[2] ? hci_init(p) :
bt_new_hci(qemu_find_bt_vlan(0)));
if (!dev)
return -1;
- return usb_device_add_dev(dev);
-}
-
-int usb_device_del_addr(int bus_num, int addr)
-{
- USBPort *port;
- USBPort **lastp;
- USBDevice *dev;
-
- if (!used_usb_ports)
- return -1;
-
- if (bus_num != 0)
- return -1;
-
- lastp = &used_usb_ports;
- port = used_usb_ports;
- while (port && port->dev->addr != addr) {
- lastp = &port->next;
- port = port->next;
- }
-
- if (!port)
- return -1;
-
- dev = port->dev;
- *lastp = port->next;
- usb_attach(port, NULL);
- dev->handle_destroy(dev);
- port->next = free_usb_ports;
- free_usb_ports = port;
+done:
return 0;
}
if (strstart(devname, "host:", &p))
return usb_host_device_close(p);
- if (!used_usb_ports)
+ if (!usb_enabled)
return -1;
p = strchr(devname, '.');
bus_num = strtoul(devname, NULL, 0);
addr = strtoul(p + 1, NULL, 0);
- return usb_device_del_addr(bus_num, addr);
+ return usb_device_delete_addr(bus_num, addr);
}
static int usb_parse(const char *cmdline)
{
- return usb_device_add(cmdline, 0);
-}
-
-void do_usb_add(Monitor *mon, const char *devname)
-{
- usb_device_add(devname, 1);
+ int r;
+ r = usb_device_add(cmdline, 0);
+ if (r < 0) {
+ fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
+ }
+ return r;
}
-void do_usb_del(Monitor *mon, const char *devname)
+void do_usb_add(Monitor *mon, const QDict *qdict)
{
- usb_device_del(devname);
+ const char *devname = qdict_get_str(qdict, "devname");
+ if (usb_device_add(devname, 1) < 0) {
+ qemu_error("could not add USB device '%s'\n", devname);
+ }
}
-void usb_info(Monitor *mon)
+void do_usb_del(Monitor *mon, const QDict *qdict)
{
- USBDevice *dev;
- USBPort *port;
- const char *speed_str;
-
- if (!usb_enabled) {
- monitor_printf(mon, "USB support not enabled\n");
- return;
- }
-
- for (port = used_usb_ports; port; port = port->next) {
- dev = port->dev;
- if (!dev)
- continue;
- switch(dev->speed) {
- case USB_SPEED_LOW:
- speed_str = "1.5";
- break;
- case USB_SPEED_FULL:
- speed_str = "12";
- break;
- case USB_SPEED_HIGH:
- speed_str = "480";
- break;
- default:
- speed_str = "?";
- break;
- }
- monitor_printf(mon, " Device %d.%d, Speed %s Mb/s, Product %s\n",
- 0, dev->addr, speed_str, dev->devname);
+ const char *devname = qdict_get_str(qdict, "devname");
+ if (usb_device_del(devname) < 0) {
+ qemu_error("could not delete USB device '%s'\n", devname);
}
}
/***********************************************************/
/* ram save/restore */
-static int ram_get_page(QEMUFile *f, uint8_t *buf, int len)
+#define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */
+#define RAM_SAVE_FLAG_COMPRESS 0x02
+#define RAM_SAVE_FLAG_MEM_SIZE 0x04
+#define RAM_SAVE_FLAG_PAGE 0x08
+#define RAM_SAVE_FLAG_EOS 0x10
+
+static int is_dup_page(uint8_t *page, uint8_t ch)
{
- int v;
+ uint32_t val = ch << 24 | ch << 16 | ch << 8 | ch;
+ uint32_t *array = (uint32_t *)page;
+ int i;
- v = qemu_get_byte(f);
- switch(v) {
- case 0:
- if (qemu_get_buffer(f, buf, len) != len)
- return -EIO;
- break;
- case 1:
- v = qemu_get_byte(f);
- memset(buf, v, len);
- break;
- default:
- return -EINVAL;
+ for (i = 0; i < (TARGET_PAGE_SIZE / 4); i++) {
+ if (array[i] != val)
+ return 0;
}
- if (qemu_file_has_error(f))
- return -EIO;
-
- return 0;
-}
-
-static int ram_load_v1(QEMUFile *f, void *opaque)
-{
- int ret;
- ram_addr_t i;
-
- if (qemu_get_be32(f) != last_ram_offset)
- return -EINVAL;
- for(i = 0; i < last_ram_offset; i+= TARGET_PAGE_SIZE) {
- ret = ram_get_page(f, qemu_get_ram_ptr(i), TARGET_PAGE_SIZE);
- if (ret)
- return ret;
- }
- return 0;
-}
-
-#define BDRV_HASH_BLOCK_SIZE 1024
-#define IOBUF_SIZE 4096
-#define RAM_CBLOCK_MAGIC 0xfabe
-
-typedef struct RamDecompressState {
- z_stream zstream;
- QEMUFile *f;
- uint8_t buf[IOBUF_SIZE];
-} RamDecompressState;
-
-static int ram_decompress_open(RamDecompressState *s, QEMUFile *f)
-{
- int ret;
- memset(s, 0, sizeof(*s));
- s->f = f;
- ret = inflateInit(&s->zstream);
- if (ret != Z_OK)
- return -1;
- return 0;
-}
-
-static int ram_decompress_buf(RamDecompressState *s, uint8_t *buf, int len)
-{
- int ret, clen;
-
- s->zstream.avail_out = len;
- s->zstream.next_out = buf;
- while (s->zstream.avail_out > 0) {
- if (s->zstream.avail_in == 0) {
- if (qemu_get_be16(s->f) != RAM_CBLOCK_MAGIC)
- return -1;
- clen = qemu_get_be16(s->f);
- if (clen > IOBUF_SIZE)
- return -1;
- qemu_get_buffer(s->f, s->buf, clen);
- s->zstream.avail_in = clen;
- s->zstream.next_in = s->buf;
- }
- ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
- if (ret != Z_OK && ret != Z_STREAM_END) {
- return -1;
- }
- }
- return 0;
-}
-
-static void ram_decompress_close(RamDecompressState *s)
-{
- inflateEnd(&s->zstream);
-}
-
-#define RAM_SAVE_FLAG_FULL 0x01
-#define RAM_SAVE_FLAG_COMPRESS 0x02
-#define RAM_SAVE_FLAG_MEM_SIZE 0x04
-#define RAM_SAVE_FLAG_PAGE 0x08
-#define RAM_SAVE_FLAG_EOS 0x10
-
-static int is_dup_page(uint8_t *page, uint8_t ch)
-{
- uint32_t val = ch << 24 | ch << 16 | ch << 8 | ch;
- uint32_t *array = (uint32_t *)page;
- int i;
-
- for (i = 0; i < (TARGET_PAGE_SIZE / 4); i++) {
- if (array[i] != val)
- return 0;
- }
-
- return 1;
-}
+ return 1;
+}
static int ram_save_block(QEMUFile *f)
{
return found;
}
-static uint64_t bytes_transferred = 0;
+static uint64_t bytes_transferred;
static ram_addr_t ram_save_remaining(void)
{
return last_ram_offset;
}
-static int ram_save_live(QEMUFile *f, int stage, void *opaque)
+static int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
{
ram_addr_t addr;
uint64_t bytes_transferred_last;
double bwidth = 0;
uint64_t expected_time = 0;
+ if (stage < 0) {
+ cpu_physical_memory_set_dirty_tracking(0);
+ return 0;
+ }
+
if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {
qemu_file_set_error(f);
return 0;
}
if (stage == 1) {
+ bytes_transferred = 0;
+
/* Make sure all dirty bits are set */
for (addr = 0; addr < last_ram_offset; addr += TARGET_PAGE_SIZE) {
if (!cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG))
bwidth = 0.000001;
/* try transferring iterative blocks of memory */
-
if (stage == 3) {
-
/* flush all remaining blocks regardless of rate limiting */
while (ram_save_block(f) != 0) {
bytes_transferred += TARGET_PAGE_SIZE;
return (stage == 2) && (expected_time <= migrate_max_downtime());
}
-static int ram_load_dead(QEMUFile *f, void *opaque)
-{
- RamDecompressState s1, *s = &s1;
- uint8_t buf[10];
- ram_addr_t i;
-
- if (ram_decompress_open(s, f) < 0)
- return -EINVAL;
- for(i = 0; i < last_ram_offset; i+= BDRV_HASH_BLOCK_SIZE) {
- if (ram_decompress_buf(s, buf, 1) < 0) {
- fprintf(stderr, "Error while reading ram block header\n");
- goto error;
- }
- if (buf[0] == 0) {
- if (ram_decompress_buf(s, qemu_get_ram_ptr(i),
- BDRV_HASH_BLOCK_SIZE) < 0) {
- fprintf(stderr, "Error while reading ram block address=0x%08" PRIx64, (uint64_t)i);
- goto error;
- }
- } else {
- error:
- printf("Error block header\n");
- return -EINVAL;
- }
- }
- ram_decompress_close(s);
-
- return 0;
-}
-
static int ram_load(QEMUFile *f, void *opaque, int version_id)
{
ram_addr_t addr;
int flags;
- if (version_id == 1)
- return ram_load_v1(f, opaque);
-
- if (version_id == 2) {
- if (qemu_get_be32(f) != last_ram_offset)
- return -EINVAL;
- return ram_load_dead(f, opaque);
- }
-
if (version_id != 3)
return -EINVAL;
return -EINVAL;
}
- if (flags & RAM_SAVE_FLAG_FULL) {
- if (ram_load_dead(f, opaque) < 0)
- return -EINVAL;
- }
-
if (flags & RAM_SAVE_FLAG_COMPRESS) {
uint8_t ch = qemu_get_byte(f);
memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE);
madvise(qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE, MADV_DONTNEED);
}
#endif
- } else if (flags & RAM_SAVE_FLAG_PAGE)
+ } else if (flags & RAM_SAVE_FLAG_PAGE) {
qemu_get_buffer(f, qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE);
+ }
+ if (qemu_file_has_error(f)) {
+ return -EIO;
+ }
} while (!(flags & RAM_SAVE_FLAG_EOS));
return 0;
qemu_notify_event();
}
-/***********************************************************/
-/* bottom halves (can be seen as timers which expire ASAP) */
-
-struct QEMUBH {
- QEMUBHFunc *cb;
- void *opaque;
- int scheduled;
- int idle;
- int deleted;
- QEMUBH *next;
-};
-
-static QEMUBH *first_bh = NULL;
-
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
-{
- QEMUBH *bh;
- bh = qemu_mallocz(sizeof(QEMUBH));
- bh->cb = cb;
- bh->opaque = opaque;
- bh->next = first_bh;
- first_bh = bh;
- return bh;
-}
-
-int qemu_bh_poll(void)
-{
- QEMUBH *bh, **bhp;
- int ret;
-
- ret = 0;
- for (bh = first_bh; bh; bh = bh->next) {
- if (!bh->deleted && bh->scheduled) {
- bh->scheduled = 0;
- if (!bh->idle)
- ret = 1;
- bh->idle = 0;
- bh->cb(bh->opaque);
- }
- }
-
- /* remove deleted bhs */
- bhp = &first_bh;
- while (*bhp) {
- bh = *bhp;
- if (bh->deleted) {
- *bhp = bh->next;
- qemu_free(bh);
- } else
- bhp = &bh->next;
- }
-
- return ret;
-}
-
-void qemu_bh_schedule_idle(QEMUBH *bh)
-{
- if (bh->scheduled)
- return;
- bh->scheduled = 1;
- bh->idle = 1;
-}
-
-void qemu_bh_schedule(QEMUBH *bh)
-{
- if (bh->scheduled)
- return;
- bh->scheduled = 1;
- bh->idle = 0;
- /* stop the currently executing CPU to execute the BH ASAP */
- qemu_notify_event();
-}
-
-void qemu_bh_cancel(QEMUBH *bh)
-{
- bh->scheduled = 0;
-}
-
-void qemu_bh_delete(QEMUBH *bh)
-{
- bh->scheduled = 0;
- bh->deleted = 1;
-}
-
-static void qemu_bh_update_timeout(int *timeout)
-{
- QEMUBH *bh;
-
- for (bh = first_bh; bh; bh = bh->next) {
- if (!bh->deleted && bh->scheduled) {
- if (bh->idle) {
- /* idle bottom halves will be polled at least
- * every 10ms */
- *timeout = MIN(10, *timeout);
- } else {
- /* non-idle bottom halves will be executed
- * immediately */
- *timeout = 0;
- break;
- }
- }
- }
-}
-
/***********************************************************/
/* machine registration */
struct vm_change_state_entry {
VMChangeStateHandler *cb;
void *opaque;
- LIST_ENTRY (vm_change_state_entry) entries;
+ QLIST_ENTRY (vm_change_state_entry) entries;
};
-static LIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
+static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
void *opaque)
e->cb = cb;
e->opaque = opaque;
- LIST_INSERT_HEAD(&vm_change_state_head, e, entries);
+ QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
return e;
}
void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
{
- LIST_REMOVE (e, entries);
+ QLIST_REMOVE (e, entries);
qemu_free (e);
}
/* reset/shutdown handler */
typedef struct QEMUResetEntry {
- TAILQ_ENTRY(QEMUResetEntry) entry;
+ QTAILQ_ENTRY(QEMUResetEntry) entry;
QEMUResetHandler *func;
void *opaque;
} QEMUResetEntry;
-static TAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
- TAILQ_HEAD_INITIALIZER(reset_handlers);
+static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
+ QTAILQ_HEAD_INITIALIZER(reset_handlers);
static int reset_requested;
static int shutdown_requested;
static int powerdown_requested;
re->func = func;
re->opaque = opaque;
- TAILQ_INSERT_TAIL(&reset_handlers, re, entry);
+ QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
}
void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
{
QEMUResetEntry *re;
- TAILQ_FOREACH(re, &reset_handlers, entry) {
+ QTAILQ_FOREACH(re, &reset_handlers, entry) {
if (re->func == func && re->opaque == opaque) {
- TAILQ_REMOVE(&reset_handlers, re, entry);
+ QTAILQ_REMOVE(&reset_handlers, re, entry);
qemu_free(re);
return;
}
QEMUResetEntry *re, *nre;
/* reset all devices */
- TAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
+ QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
re->func(re->opaque);
}
}
static void qemu_event_increment(void)
{
static const char byte = 0;
+ ssize_t ret;
if (io_thread_fd == -1)
return;
- write(io_thread_fd, &byte, sizeof(byte));
+ ret = write(io_thread_fd, &byte, sizeof(byte));
+ if (ret < 0 && (errno != EINTR && errno != EAGAIN)) {
+ fprintf(stderr, "qemu_event_increment: write() filed: %s\n",
+ strerror(errno));
+ exit (1);
+ }
}
static void qemu_event_read(void *opaque)
int err;
int fds[2];
- err = pipe(fds);
+ err = qemu_pipe(fds);
if (err == -1)
return -errno;
{
qemu_event_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!qemu_event_handle) {
- perror("Failed CreateEvent");
+ fprintf(stderr, "Failed CreateEvent: %ld\n", GetLastError());
return -1;
}
qemu_add_wait_object(qemu_event_handle, dummy_event_handler, NULL);
static void qemu_event_increment(void)
{
- SetEvent(qemu_event_handle);
+ if (!SetEvent(qemu_event_handle)) {
+ fprintf(stderr, "qemu_event_increment: SetEvent failed: %ld\n",
+ GetLastError());
+ exit (1);
+ }
}
#endif
{
CPUState *env = _env;
+ env->nr_cores = smp_cores;
+ env->nr_threads = smp_threads;
if (kvm_enabled())
kvm_init_vcpu(env);
return;
}
}
-#define qemu_mutex_lock_iothread() do { } while (0)
-#define qemu_mutex_unlock_iothread() do { } while (0)
+void qemu_mutex_lock_iothread(void) {}
+void qemu_mutex_unlock_iothread(void) {}
void vm_stop(int reason)
{
block_io_signals();
qemu_thread_self(env->thread);
+ if (kvm_enabled())
+ kvm_init_vcpu(env);
/* signal CPU creation */
qemu_mutex_lock(&qemu_global_mutex);
qemu_thread_signal(env->thread, SIGUSR1);
}
-int qemu_cpu_self(void *env)
+int qemu_cpu_self(void *_env)
{
- return (cpu_single_env != NULL);
+ CPUState *env = _env;
+ QemuThread this;
+
+ qemu_thread_self(&this);
+
+ return qemu_thread_equal(&this, env->thread);
}
static void cpu_signal(int sig)
qemu_mutex_unlock(&qemu_fair_mutex);
}
-static void qemu_mutex_lock_iothread(void)
+void qemu_mutex_lock_iothread(void)
{
if (kvm_enabled()) {
qemu_mutex_lock(&qemu_fair_mutex);
qemu_signal_lock(100);
}
-static void qemu_mutex_unlock_iothread(void)
+void qemu_mutex_unlock_iothread(void)
{
qemu_mutex_unlock(&qemu_global_mutex);
}
static void kvm_start_vcpu(CPUState *env)
{
- kvm_init_vcpu(env);
env->thread = qemu_mallocz(sizeof(QemuThread));
env->halt_cond = qemu_mallocz(sizeof(QemuCond));
qemu_cond_init(env->halt_cond);
{
CPUState *env = _env;
+ env->nr_cores = smp_cores;
+ env->nr_threads = smp_threads;
if (kvm_enabled())
kvm_start_vcpu(env);
else
/* vm time timers */
if (vm_running) {
if (!cur_cpu || likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER)))
- qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL],
- qemu_get_clock(vm_clock));
+ qemu_run_timers(&active_timers[QEMU_CLOCK_VIRTUAL],
+ qemu_get_clock(vm_clock));
}
/* real time timers */
- qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],
+ qemu_run_timers(&active_timers[QEMU_CLOCK_REALTIME],
qemu_get_clock(rt_clock));
+ qemu_run_timers(&active_timers[QEMU_CLOCK_HOST],
+ qemu_get_clock(host_clock));
+
/* Check bottom-halves last in case any of the earlier events triggered
them. */
qemu_bh_poll();
#endif
} while (vm_can_run());
- if (qemu_debug_requested())
+ if (qemu_debug_requested()) {
+ monitor_protocol_event(QEVENT_DEBUG, NULL);
vm_stop(EXCP_DEBUG);
+ }
if (qemu_shutdown_requested()) {
+ monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
if (no_shutdown) {
vm_stop(0);
no_shutdown = 0;
break;
}
if (qemu_reset_requested()) {
+ monitor_protocol_event(QEVENT_RESET, NULL);
pause_all_vcpus();
qemu_system_reset();
resume_all_vcpus();
}
if (qemu_powerdown_requested()) {
+ monitor_protocol_event(QEVENT_POWERDOWN, NULL);
qemu_irq_raise(qemu_system_powerdown);
}
- if ((r = qemu_vmstop_requested()))
+ if ((r = qemu_vmstop_requested())) {
+ monitor_protocol_event(QEVENT_STOP, NULL);
vm_stop(r);
+ }
}
pause_all_vcpus();
}
l = !e ? strlen (p) : (size_t) (e - p);
for (c = soundhw; c->name; ++c) {
- if (!strncmp (c->name, p, l)) {
+ if (!strncmp (c->name, p, l) && !c->name[l]) {
c->enabled = 1;
break;
}
{
const char *opts;
+ default_vga = 0;
vga_interface_type = VGA_NONE;
if (strstart(p, "std", &opts)) {
vga_interface_type = VGA_STD;
#ifdef TARGET_I386
static int balloon_parse(const char *arg)
{
- char buf[128];
- const char *p;
+ QemuOpts *opts;
- if (!strcmp(arg, "none")) {
- virtio_balloon = 0;
- } else if (!strncmp(arg, "virtio", 6)) {
- virtio_balloon = 1;
- if (arg[6] == ',') {
- p = arg + 7;
- if (get_param_value(buf, sizeof(buf), "addr", p)) {
- virtio_balloon_devaddr = strdup(buf);
- }
+ if (strcmp(arg, "none") == 0) {
+ return 0;
+ }
+
+ if (!strncmp(arg, "virtio", 6)) {
+ if (arg[6] == ',') {
+ /* have params -> parse them */
+ opts = qemu_opts_parse(&qemu_device_opts, arg+7, NULL);
+ if (!opts)
+ return -1;
+ } else {
+ /* create empty opts */
+ opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
}
- } else {
- return -1;
+ qemu_opt_set(opts, "driver", "virtio-balloon-pci");
+ return 0;
}
- return 0;
+
+ return -1;
}
#endif
return 0;
}
-#define MAX_NET_CLIENTS 32
-
#ifndef _WIN32
static void termsig_handler(int signal)
char *dir;
char *p = NULL;
char *res;
-#ifdef PATH_MAX
char buf[PATH_MAX];
-#endif
size_t max_len;
#if defined(__linux__)
/* If we don't have any way of figuring out the actual executable
location then try argv[0]. */
if (!p) {
-#ifdef PATH_MAX
- p = buf;
-#endif
- p = realpath(argv0, p);
+ p = realpath(argv0, buf);
if (!p) {
return NULL;
}
res = NULL;
}
}
-#ifndef PATH_MAX
- free(p);
-#endif
+
return res;
}
#undef SHARE_SUFFIX
/* If name contains path separators then try it as a straight path. */
if ((strchr(name, '/') || strchr(name, '\\'))
&& access(name, R_OK) == 0) {
- return strdup(name);
+ return qemu_strdup(name);
}
switch (type) {
case QEMU_FILE_TYPE_BIOS:
return 0;
}
+static int chardev_init_func(QemuOpts *opts, void *opaque)
+{
+ CharDriverState *chr;
+
+ chr = qemu_chr_open_opts(opts, NULL);
+ if (!chr)
+ return -1;
+ return 0;
+}
+
+static int mon_init_func(QemuOpts *opts, void *opaque)
+{
+ CharDriverState *chr;
+ const char *chardev;
+ const char *mode;
+ int flags;
+
+ mode = qemu_opt_get(opts, "mode");
+ if (mode == NULL) {
+ mode = "readline";
+ }
+ if (strcmp(mode, "readline") == 0) {
+ flags = MONITOR_USE_READLINE;
+ } else if (strcmp(mode, "control") == 0) {
+ flags = MONITOR_USE_CONTROL;
+ } else {
+ fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
+ exit(1);
+ }
+
+ if (qemu_opt_get_bool(opts, "default", 0))
+ flags |= MONITOR_IS_DEFAULT;
+
+ chardev = qemu_opt_get(opts, "chardev");
+ chr = qemu_chr_find(chardev);
+ if (chr == NULL) {
+ fprintf(stderr, "chardev \"%s\" not found\n", chardev);
+ exit(1);
+ }
+
+ monitor_init(chr, flags);
+ return 0;
+}
+
+static void monitor_parse(const char *optarg, const char *mode)
+{
+ static int monitor_device_index = 0;
+ QemuOpts *opts;
+ const char *p;
+ char label[32];
+ int def = 0;
+
+ if (strstart(optarg, "chardev:", &p)) {
+ snprintf(label, sizeof(label), "%s", p);
+ } else {
+ if (monitor_device_index) {
+ snprintf(label, sizeof(label), "monitor%d",
+ monitor_device_index);
+ } else {
+ snprintf(label, sizeof(label), "monitor");
+ def = 1;
+ }
+ opts = qemu_chr_parse_compat(label, optarg);
+ if (!opts) {
+ fprintf(stderr, "parse error: %s\n", optarg);
+ exit(1);
+ }
+ }
+
+ opts = qemu_opts_create(&qemu_mon_opts, label, 1);
+ if (!opts) {
+ fprintf(stderr, "duplicate chardev: %s\n", label);
+ exit(1);
+ }
+ qemu_opt_set(opts, "mode", mode);
+ qemu_opt_set(opts, "chardev", label);
+ if (def)
+ qemu_opt_set(opts, "default", "on");
+ monitor_device_index++;
+}
+
struct device_config {
enum {
- DEV_USB, /* -usbdevice */
- DEV_BT, /* -bt */
+ DEV_USB, /* -usbdevice */
+ DEV_BT, /* -bt */
+ DEV_SERIAL, /* -serial */
+ DEV_PARALLEL, /* -parallel */
+ DEV_VIRTCON, /* -virtioconsole */
+ DEV_DEBUGCON, /* -debugcon */
} type;
const char *cmdline;
- TAILQ_ENTRY(device_config) next;
+ QTAILQ_ENTRY(device_config) next;
};
-TAILQ_HEAD(, device_config) device_configs = TAILQ_HEAD_INITIALIZER(device_configs);
+QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
static void add_device_config(int type, const char *cmdline)
{
conf = qemu_mallocz(sizeof(*conf));
conf->type = type;
conf->cmdline = cmdline;
- TAILQ_INSERT_TAIL(&device_configs, conf, next);
+ QTAILQ_INSERT_TAIL(&device_configs, conf, next);
}
static int foreach_device_config(int type, int (*func)(const char *cmdline))
struct device_config *conf;
int rc;
- TAILQ_FOREACH(conf, &device_configs, next) {
+ QTAILQ_FOREACH(conf, &device_configs, next) {
if (conf->type != type)
continue;
rc = func(conf->cmdline);
return 0;
}
+static int serial_parse(const char *devname)
+{
+ static int index = 0;
+ char label[32];
+
+ if (strcmp(devname, "none") == 0)
+ return 0;
+ if (index == MAX_SERIAL_PORTS) {
+ fprintf(stderr, "qemu: too many serial ports\n");
+ exit(1);
+ }
+ snprintf(label, sizeof(label), "serial%d", index);
+ serial_hds[index] = qemu_chr_open(label, devname, NULL);
+ if (!serial_hds[index]) {
+ fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
+ devname, strerror(errno));
+ return -1;
+ }
+ index++;
+ return 0;
+}
+
+static int parallel_parse(const char *devname)
+{
+ static int index = 0;
+ char label[32];
+
+ if (strcmp(devname, "none") == 0)
+ return 0;
+ if (index == MAX_PARALLEL_PORTS) {
+ fprintf(stderr, "qemu: too many parallel ports\n");
+ exit(1);
+ }
+ snprintf(label, sizeof(label), "parallel%d", index);
+ parallel_hds[index] = qemu_chr_open(label, devname, NULL);
+ if (!parallel_hds[index]) {
+ fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
+ devname, strerror(errno));
+ return -1;
+ }
+ index++;
+ return 0;
+}
+
+static int virtcon_parse(const char *devname)
+{
+ static int index = 0;
+ char label[32];
+ QemuOpts *bus_opts, *dev_opts;
+
+ if (strcmp(devname, "none") == 0)
+ return 0;
+ if (index == MAX_VIRTIO_CONSOLES) {
+ fprintf(stderr, "qemu: too many virtio consoles\n");
+ exit(1);
+ }
+
+ bus_opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
+ qemu_opt_set(bus_opts, "driver", "virtio-serial");
+
+ dev_opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
+ qemu_opt_set(dev_opts, "driver", "virtconsole");
+
+ snprintf(label, sizeof(label), "virtcon%d", index);
+ virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
+ if (!virtcon_hds[index]) {
+ fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
+ devname, strerror(errno));
+ return -1;
+ }
+ qemu_opt_set(dev_opts, "chardev", label);
+
+ index++;
+ return 0;
+}
+
+static int debugcon_parse(const char *devname)
+{
+ QemuOpts *opts;
+
+ if (!qemu_chr_open("debugcon", devname, NULL)) {
+ exit(1);
+ }
+ opts = qemu_opts_create(&qemu_device_opts, "debugcon", 1);
+ if (!opts) {
+ fprintf(stderr, "qemu: already have a debugcon device\n");
+ exit(1);
+ }
+ qemu_opt_set(opts, "driver", "isa-debugcon");
+ qemu_opt_set(opts, "chardev", "debugcon");
+ return 0;
+}
+
+static const QEMUOption *lookup_opt(int argc, char **argv,
+ const char **poptarg, int *poptind)
+{
+ const QEMUOption *popt;
+ int optind = *poptind;
+ char *r = argv[optind];
+ const char *optarg;
+
+ optind++;
+ /* Treat --foo the same as -foo. */
+ if (r[1] == '-')
+ r++;
+ popt = qemu_options;
+ for(;;) {
+ if (!popt->name) {
+ fprintf(stderr, "%s: invalid option -- '%s'\n",
+ argv[0], r);
+ exit(1);
+ }
+ if (!strcmp(popt->name, r + 1))
+ break;
+ popt++;
+ }
+ if (popt->flags & HAS_ARG) {
+ if (optind >= argc) {
+ fprintf(stderr, "%s: option '%s' requires an argument\n",
+ argv[0], r);
+ exit(1);
+ }
+ optarg = argv[optind++];
+ } else {
+ optarg = NULL;
+ }
+
+ *poptarg = optarg;
+ *poptind = optind;
+
+ return popt;
+}
+
int main(int argc, char **argv, char **envp)
{
const char *gdbstub_dev = NULL;
DisplayState *ds;
DisplayChangeListener *dcl;
int cyls, heads, secs, translation;
- const char *net_clients[MAX_NET_CLIENTS];
- int nb_net_clients;
QemuOpts *hda_opts = NULL, *opts;
int optind;
- const char *r, *optarg;
- CharDriverState *monitor_hd = NULL;
- const char *monitor_device;
- const char *serial_devices[MAX_SERIAL_PORTS];
- int serial_device_index;
- const char *parallel_devices[MAX_PARALLEL_PORTS];
- int parallel_device_index;
- const char *virtio_consoles[MAX_VIRTIO_CONSOLES];
- int virtio_console_index;
+ const char *optarg;
const char *loadvm = NULL;
QEMUMachine *machine;
const char *cpu_model;
#endif
CPUState *env;
int show_vnc_port = 0;
+ int defconfig = 1;
+ init_clocks();
+
+ qemu_errors_to_file(stderr);
qemu_cache_utils_init(envp);
- LIST_INIT (&vm_change_state_head);
+ QLIST_INIT (&vm_change_state_head);
#ifndef _WIN32
{
struct sigaction act;
kernel_cmdline = "";
cyls = heads = secs = 0;
translation = BIOS_ATA_TRANSLATION_AUTO;
- monitor_device = "vc:80Cx24C";
-
- serial_devices[0] = "vc:80Cx24C";
- for(i = 1; i < MAX_SERIAL_PORTS; i++)
- serial_devices[i] = NULL;
- serial_device_index = 0;
-
- parallel_devices[0] = "vc:80Cx24C";
- for(i = 1; i < MAX_PARALLEL_PORTS; i++)
- parallel_devices[i] = NULL;
- parallel_device_index = 0;
-
- for(i = 0; i < MAX_VIRTIO_CONSOLES; i++)
- virtio_consoles[i] = NULL;
- virtio_console_index = 0;
for (i = 0; i < MAX_NODES; i++) {
node_mem[i] = 0;
node_cpumask[i] = 0;
}
- nb_net_clients = 0;
nb_numa_nodes = 0;
nb_nics = 0;
tb_size = 0;
autostart= 1;
- register_watchdogs();
+ /* first pass of option parsing */
+ optind = 1;
+ while (optind < argc) {
+ if (argv[optind][0] != '-') {
+ /* disk image */
+ optind++;
+ continue;
+ } else {
+ const QEMUOption *popt;
+
+ popt = lookup_opt(argc, argv, &optarg, &optind);
+ switch (popt->index) {
+ case QEMU_OPTION_nodefconfig:
+ defconfig=0;
+ break;
+ }
+ }
+ }
+
+ if (defconfig) {
+ FILE *fp;
+ fp = fopen(CONFIG_QEMU_CONFDIR "/qemu.conf", "r");
+ if (fp) {
+ if (qemu_config_parse(fp) != 0) {
+ exit(1);
+ }
+ fclose(fp);
+ }
+
+ fp = fopen(CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", "r");
+ if (fp) {
+ if (qemu_config_parse(fp) != 0) {
+ exit(1);
+ }
+ fclose(fp);
+ }
+ }
+ /* second pass of option parsing */
optind = 1;
for(;;) {
if (optind >= argc)
break;
- r = argv[optind];
- if (r[0] != '-') {
+ if (argv[optind][0] != '-') {
hda_opts = drive_add(argv[optind++], HD_ALIAS, 0);
} else {
const QEMUOption *popt;
- optind++;
- /* Treat --foo the same as -foo. */
- if (r[1] == '-')
- r++;
- popt = qemu_options;
- for(;;) {
- if (!popt->name) {
- fprintf(stderr, "%s: invalid option -- '%s'\n",
- argv[0], r);
- exit(1);
- }
- if (!strcmp(popt->name, r + 1))
- break;
- popt++;
- }
- if (popt->flags & HAS_ARG) {
- if (optind >= argc) {
- fprintf(stderr, "%s: option '%s' requires an argument\n",
- argv[0], r);
- exit(1);
- }
- optarg = argv[optind++];
- } else {
- optarg = NULL;
- }
-
+ popt = lookup_opt(argc, argv, &optarg, &optind);
switch(popt->index) {
case QEMU_OPTION_M:
machine = find_machine(optarg);
if (qemu_set_option(optarg) != 0)
exit(1);
break;
+ case QEMU_OPTION_global:
+ if (qemu_global_option(optarg) != 0)
+ exit(1);
+ break;
case QEMU_OPTION_mtdblock:
drive_add(optarg, MTD_ALIAS);
break;
fd_bootchk = 0;
break;
#endif
+ case QEMU_OPTION_netdev:
+ if (net_client_parse(&qemu_netdev_opts, optarg) == -1) {
+ exit(1);
+ }
+ break;
case QEMU_OPTION_net:
- if (nb_net_clients >= MAX_NET_CLIENTS) {
- fprintf(stderr, "qemu: too many network clients\n");
+ if (net_client_parse(&qemu_net_opts, optarg) == -1) {
exit(1);
}
- net_clients[nb_net_clients] = optarg;
- nb_net_clients++;
break;
#ifdef CONFIG_SLIRP
case QEMU_OPTION_tftp:
break;
#ifndef _WIN32
case QEMU_OPTION_smb:
- net_slirp_smb(optarg);
+ if (net_slirp_smb(optarg) < 0)
+ exit(1);
break;
#endif
case QEMU_OPTION_redir:
- net_slirp_redir(optarg);
+ if (net_slirp_redir(optarg) < 0)
+ exit(1);
break;
#endif
case QEMU_OPTION_bt:
case QEMU_OPTION_S:
autostart = 0;
break;
-#ifndef _WIN32
case QEMU_OPTION_k:
keyboard_layout = optarg;
break;
-#endif
case QEMU_OPTION_localtime:
rtc_utc = 0;
break;
break;
}
case QEMU_OPTION_monitor:
- monitor_device = optarg;
+ monitor_parse(optarg, "readline");
+ default_monitor = 0;
break;
- case QEMU_OPTION_serial:
- if (serial_device_index >= MAX_SERIAL_PORTS) {
- fprintf(stderr, "qemu: too many serial ports\n");
+ case QEMU_OPTION_qmp:
+ monitor_parse(optarg, "control");
+ default_monitor = 0;
+ break;
+ case QEMU_OPTION_mon:
+ opts = qemu_opts_parse(&qemu_mon_opts, optarg, "chardev");
+ if (!opts) {
+ fprintf(stderr, "parse error: %s\n", optarg);
+ exit(1);
+ }
+ default_monitor = 0;
+ break;
+ case QEMU_OPTION_chardev:
+ opts = qemu_opts_parse(&qemu_chardev_opts, optarg, "backend");
+ if (!opts) {
+ fprintf(stderr, "parse error: %s\n", optarg);
exit(1);
}
- serial_devices[serial_device_index] = optarg;
- serial_device_index++;
+ break;
+ case QEMU_OPTION_serial:
+ add_device_config(DEV_SERIAL, optarg);
+ default_serial = 0;
break;
case QEMU_OPTION_watchdog:
- i = select_watchdog(optarg);
- if (i > 0)
- exit (i == 1 ? 1 : 0);
+ if (watchdog) {
+ fprintf(stderr,
+ "qemu: only one watchdog option may be given\n");
+ return 1;
+ }
+ watchdog = optarg;
break;
case QEMU_OPTION_watchdog_action:
if (select_watchdog_action(optarg) == -1) {
}
break;
case QEMU_OPTION_virtiocon:
- if (virtio_console_index >= MAX_VIRTIO_CONSOLES) {
- fprintf(stderr, "qemu: too many virtio consoles\n");
- exit(1);
- }
- virtio_consoles[virtio_console_index] = optarg;
- virtio_console_index++;
+ add_device_config(DEV_VIRTCON, optarg);
+ default_virtcon = 0;
break;
case QEMU_OPTION_parallel:
- if (parallel_device_index >= MAX_PARALLEL_PORTS) {
- fprintf(stderr, "qemu: too many parallel ports\n");
- exit(1);
- }
- parallel_devices[parallel_device_index] = optarg;
- parallel_device_index++;
+ add_device_config(DEV_PARALLEL, optarg);
+ default_parallel = 0;
+ break;
+ case QEMU_OPTION_debugcon:
+ add_device_config(DEV_DEBUGCON, optarg);
break;
case QEMU_OPTION_loadvm:
loadvm = optarg;
case QEMU_OPTION_alt_grab:
alt_grab = 1;
break;
+ case QEMU_OPTION_ctrl_grab:
+ ctrl_grab = 1;
+ break;
case QEMU_OPTION_no_quit:
no_quit = 1;
break;
add_device_config(DEV_USB, optarg);
break;
case QEMU_OPTION_device:
- opts = qemu_opts_parse(&qemu_device_opts, optarg, "driver");
- if (!opts) {
- fprintf(stderr, "parse error: %s\n", optarg);
+ if (!qemu_opts_parse(&qemu_device_opts, optarg, "driver")) {
exit(1);
}
break;
case QEMU_OPTION_smp:
- {
- char *p;
- char option[128];
- smp_cpus = strtol(optarg, &p, 10);
+ smp_parse(optarg);
if (smp_cpus < 1) {
fprintf(stderr, "Invalid number of CPUs\n");
exit(1);
}
- if (*p++ != ',')
- break;
- if (get_param_value(option, 128, "maxcpus", p))
- max_cpus = strtol(option, NULL, 0);
if (max_cpus < smp_cpus) {
fprintf(stderr, "maxcpus must be equal to or greater than "
"smp\n");
exit(1);
}
break;
- }
case QEMU_OPTION_vnc:
display_type = DT_VNC;
vnc_display = optarg;
configure_alarms(optarg);
break;
case QEMU_OPTION_startdate:
- {
- struct tm tm;
- time_t rtc_start_date;
- if (!strcmp(optarg, "now")) {
- rtc_date_offset = -1;
- } else {
- if (sscanf(optarg, "%d-%d-%dT%d:%d:%d",
- &tm.tm_year,
- &tm.tm_mon,
- &tm.tm_mday,
- &tm.tm_hour,
- &tm.tm_min,
- &tm.tm_sec) == 6) {
- /* OK */
- } else if (sscanf(optarg, "%d-%d-%d",
- &tm.tm_year,
- &tm.tm_mon,
- &tm.tm_mday) == 3) {
- tm.tm_hour = 0;
- tm.tm_min = 0;
- tm.tm_sec = 0;
- } else {
- goto date_fail;
- }
- tm.tm_year -= 1900;
- tm.tm_mon--;
- rtc_start_date = mktimegm(&tm);
- if (rtc_start_date == -1) {
- date_fail:
- fprintf(stderr, "Invalid date format. Valid format are:\n"
- "'now' or '2006-06-17T16:01:21' or '2006-06-17'\n");
- exit(1);
- }
- rtc_date_offset = time(NULL) - rtc_start_date;
- }
+ configure_rtc_date_offset(optarg, 1);
+ break;
+ case QEMU_OPTION_rtc:
+ opts = qemu_opts_parse(&qemu_rtc_opts, optarg, NULL);
+ if (!opts) {
+ fprintf(stderr, "parse error: %s\n", optarg);
+ exit(1);
}
+ configure_rtc(opts);
break;
case QEMU_OPTION_tb_size:
tb_size = strtol(optarg, NULL, 0);
case QEMU_OPTION_incoming:
incoming = optarg;
break;
+ case QEMU_OPTION_nodefaults:
+ default_serial = 0;
+ default_parallel = 0;
+ default_virtcon = 0;
+ default_monitor = 0;
+ default_vga = 0;
+ default_net = 0;
+ default_floppy = 0;
+ default_cdrom = 0;
+ default_sdcard = 0;
+ break;
#ifndef _WIN32
case QEMU_OPTION_chroot:
chroot_dir = optarg;
xen_mode = XEN_ATTACH;
break;
#endif
+ case QEMU_OPTION_readconfig:
+ {
+ FILE *fp;
+ fp = fopen(optarg, "r");
+ if (fp == NULL) {
+ fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
+ exit(1);
+ }
+ if (qemu_config_parse(fp) != 0) {
+ exit(1);
+ }
+ fclose(fp);
+ break;
+ }
+ case QEMU_OPTION_writeconfig:
+ {
+ FILE *fp;
+ if (strcmp(optarg, "-") == 0) {
+ fp = stdout;
+ } else {
+ fp = fopen(optarg, "w");
+ if (fp == NULL) {
+ fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
+ exit(1);
+ }
+ }
+ qemu_config_write(fp);
+ fclose(fp);
+ break;
+ }
}
}
}
exit(1);
}
- if (display_type == DT_NOGRAPHIC) {
- if (serial_device_index == 0)
- serial_devices[0] = "stdio";
- if (parallel_device_index == 0)
- parallel_devices[0] = "null";
- if (strncmp(monitor_device, "vc", 2) == 0)
- monitor_device = "stdio";
+ qemu_opts_foreach(&qemu_device_opts, default_driver_check, NULL, 0);
+ qemu_opts_foreach(&qemu_global_opts, default_driver_check, NULL, 0);
+
+ if (machine->no_serial) {
+ default_serial = 0;
+ }
+ if (machine->no_parallel) {
+ default_parallel = 0;
+ }
+ if (!machine->use_virtcon) {
+ default_virtcon = 0;
+ }
+ if (machine->no_vga) {
+ default_vga = 0;
}
+ if (machine->no_floppy) {
+ default_floppy = 0;
+ }
+ if (machine->no_cdrom) {
+ default_cdrom = 0;
+ }
+ if (machine->no_sdcard) {
+ default_sdcard = 0;
+ }
+
+ if (display_type == DT_NOGRAPHIC) {
+ if (default_parallel)
+ add_device_config(DEV_PARALLEL, "null");
+ if (default_serial && default_monitor) {
+ add_device_config(DEV_SERIAL, "mon:stdio");
+ } else if (default_virtcon && default_monitor) {
+ add_device_config(DEV_VIRTCON, "mon:stdio");
+ } else {
+ if (default_serial)
+ add_device_config(DEV_SERIAL, "stdio");
+ if (default_virtcon)
+ add_device_config(DEV_VIRTCON, "stdio");
+ if (default_monitor)
+ monitor_parse("stdio", "readline");
+ }
+ } else {
+ if (default_serial)
+ add_device_config(DEV_SERIAL, "vc:80Cx24C");
+ if (default_parallel)
+ add_device_config(DEV_PARALLEL, "vc:80Cx24C");
+ if (default_monitor)
+ monitor_parse("vc:80Cx24C", "readline");
+ if (default_virtcon)
+ add_device_config(DEV_VIRTCON, "vc:80Cx24C");
+ }
+ if (default_vga)
+ vga_interface_type = VGA_CIRRUS;
+
+ if (qemu_opts_foreach(&qemu_chardev_opts, chardev_init_func, NULL, 1) != 0)
+ exit(1);
#ifndef _WIN32
if (daemonize) {
if (len != 1)
exit(1);
else if (status == 1) {
- fprintf(stderr, "Could not acquire pidfile\n");
+ fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno));
exit(1);
} else
exit(0);
} else if (pid < 0)
exit(1);
+ close(fds[0]);
+ qemu_set_cloexec(fds[1]);
+
setsid();
pid = fork();
signal(SIGTTOU, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
}
+#endif
if (pid_file && qemu_create_pidfile(pid_file) != 0) {
+#ifndef _WIN32
if (daemonize) {
uint8_t status = 1;
- write(fds[1], &status, 1);
+ if (write(fds[1], &status, 1) != 1) {
+ perror("daemonize. Writing to pipe\n");
+ }
} else
- fprintf(stderr, "Could not acquire pid file\n");
+#endif
+ fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
exit(1);
}
-#endif
+
+ if (kvm_enabled()) {
+ int ret;
+
+ ret = kvm_init(smp_cpus);
+ if (ret < 0) {
+ fprintf(stderr, "failed to initialize KVM\n");
+ exit(1);
+ }
+ }
if (qemu_init_main_loop()) {
fprintf(stderr, "qemu_init_main_loop failed\n");
setvbuf(stdout, NULL, _IOLBF, 0);
#endif
- init_timers();
if (init_timer_alarm() < 0) {
fprintf(stderr, "could not initialize alarm timer\n");
exit(1);
socket_init();
#endif
- /* init network clients */
- if (nb_net_clients == 0) {
- /* if no clients, we use a default config */
- net_clients[nb_net_clients++] = "nic";
-#ifdef CONFIG_SLIRP
- net_clients[nb_net_clients++] = "user";
-#endif
- }
-
- for(i = 0;i < nb_net_clients; i++) {
- if (net_client_parse(net_clients[i]) < 0)
- exit(1);
+ if (net_init_clients() < 0) {
+ exit(1);
}
net_boot = (boot_devices_bitmap >> ('n' - 'a')) & 0xF;
net_set_boot_mask(net_boot);
- net_client_check();
-
/* init the bluetooth world */
if (foreach_device_config(DEV_BT, bt_parse))
exit(1);
/* init the dynamic translator */
cpu_exec_init_all(tb_size * 1024 * 1024);
- bdrv_init();
+ bdrv_init_with_whitelist();
- /* we always create the cdrom drive, even if no disk is there */
- drive_add(NULL, CDROM_ALIAS);
+ blk_mig_init();
- /* we always create at least one floppy */
- drive_add(NULL, FD_ALIAS, 0);
+ if (default_cdrom) {
+ /* we always create the cdrom drive, even if no disk is there */
+ drive_add(NULL, CDROM_ALIAS);
+ }
- /* we always create one sd slot, even if no card is in it */
- drive_add(NULL, SD_ALIAS);
+ if (default_floppy) {
+ /* we always create at least one floppy */
+ drive_add(NULL, FD_ALIAS, 0);
+ }
+
+ if (default_sdcard) {
+ /* we always create one sd slot, even if no card is in it */
+ drive_add(NULL, SD_ALIAS);
+ }
/* open the virtual block devices */
if (snapshot)
if (qemu_opts_foreach(&qemu_drive_opts, drive_init_func, machine, 1) != 0)
exit(1);
- register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
- register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL);
-
-#ifndef _WIN32
- /* must be after terminal init, SDL library changes signal handlers */
- sighandler_setup();
-#endif
-
- /* Maintain compatibility with multiple stdio monitors */
- if (!strcmp(monitor_device,"stdio")) {
- for (i = 0; i < MAX_SERIAL_PORTS; i++) {
- const char *devname = serial_devices[i];
- if (devname && !strcmp(devname,"mon:stdio")) {
- monitor_device = NULL;
- break;
- } else if (devname && !strcmp(devname,"stdio")) {
- monitor_device = NULL;
- serial_devices[i] = "mon:stdio";
- break;
- }
- }
- }
+ vmstate_register(0, &vmstate_timers ,&timers_state);
+ register_savevm_live("ram", 0, 3, NULL, ram_save_live, NULL,
+ ram_load, NULL);
if (nb_numa_nodes > 0) {
int i;
}
}
- if (kvm_enabled()) {
- int ret;
-
- ret = kvm_init(smp_cpus);
- if (ret < 0) {
- fprintf(stderr, "failed to initialize KVM\n");
- exit(1);
- }
- }
-
- if (monitor_device) {
- monitor_hd = qemu_chr_open("monitor", monitor_device, NULL);
- if (!monitor_hd) {
- fprintf(stderr, "qemu: could not open monitor device '%s'\n", monitor_device);
- exit(1);
- }
- }
-
- for(i = 0; i < MAX_SERIAL_PORTS; i++) {
- const char *devname = serial_devices[i];
- if (devname && strcmp(devname, "none")) {
- char label[32];
- snprintf(label, sizeof(label), "serial%d", i);
- serial_hds[i] = qemu_chr_open(label, devname, NULL);
- if (!serial_hds[i]) {
- fprintf(stderr, "qemu: could not open serial device '%s'\n",
- devname);
- exit(1);
- }
- }
- }
+ if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
+ exit(1);
+ if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
+ exit(1);
+ if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
+ exit(1);
+ if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
+ exit(1);
- for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
- const char *devname = parallel_devices[i];
- if (devname && strcmp(devname, "none")) {
- char label[32];
- snprintf(label, sizeof(label), "parallel%d", i);
- parallel_hds[i] = qemu_chr_open(label, devname, NULL);
- if (!parallel_hds[i]) {
- fprintf(stderr, "qemu: could not open parallel device '%s'\n",
- devname);
- exit(1);
- }
- }
- }
+ module_call_init(MODULE_INIT_DEVICE);
- for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
- const char *devname = virtio_consoles[i];
- if (devname && strcmp(devname, "none")) {
- char label[32];
- snprintf(label, sizeof(label), "virtcon%d", i);
- virtcon_hds[i] = qemu_chr_open(label, devname, NULL);
- if (!virtcon_hds[i]) {
- fprintf(stderr, "qemu: could not open virtio console '%s'\n",
- devname);
- exit(1);
- }
- }
+ if (watchdog) {
+ i = select_watchdog(watchdog);
+ if (i > 0)
+ exit (i == 1 ? 1 : 0);
}
- module_call_init(MODULE_INIT_DEVICE);
-
if (machine->compat_props) {
- qdev_prop_register_compat(machine->compat_props);
+ qdev_prop_register_global_list(machine->compat_props);
}
+ qemu_add_globals();
+
machine->init(ram_size, boot_devices,
kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
+#ifndef _WIN32
+ /* must be after terminal init, SDL library changes signal handlers */
+ sighandler_setup();
+#endif
+
for (env = first_cpu; env != NULL; env = env->next_cpu) {
for (i = 0; i < nb_numa_nodes; i++) {
if (node_cpumask[i] & (1 << env->cpu_index)) {
/* init USB devices */
if (usb_enabled) {
- foreach_device_config(DEV_USB, usb_parse);
+ if (foreach_device_config(DEV_USB, usb_parse) < 0)
+ exit(1);
}
/* init generic devices */
}
text_consoles_set_display(display_state);
- qemu_chr_initial_reset();
-
- if (monitor_device && monitor_hd)
- monitor_init(monitor_hd, MONITOR_USE_READLINE | MONITOR_IS_DEFAULT);
-
- for(i = 0; i < MAX_SERIAL_PORTS; i++) {
- const char *devname = serial_devices[i];
- if (devname && strcmp(devname, "none")) {
- if (strstart(devname, "vc", 0))
- qemu_chr_printf(serial_hds[i], "serial%d console\r\n", i);
- }
- }
-
- for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
- const char *devname = parallel_devices[i];
- if (devname && strcmp(devname, "none")) {
- if (strstart(devname, "vc", 0))
- qemu_chr_printf(parallel_hds[i], "parallel%d console\r\n", i);
- }
- }
- for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
- const char *devname = virtio_consoles[i];
- if (virtcon_hds[i] && devname) {
- if (strstart(devname, "vc", 0))
- qemu_chr_printf(virtcon_hds[i], "virtio console%d\r\n", i);
- }
- }
+ if (qemu_opts_foreach(&qemu_mon_opts, mon_init_func, NULL, 1) != 0)
+ exit(1);
if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
exit(1);
}
- if (loadvm)
- do_loadvm(cur_mon, loadvm);
+ qdev_machine_creation_done();
+
+ if (rom_load_all() != 0) {
+ fprintf(stderr, "rom loading failed\n");
+ exit(1);
+ }
+
+ qemu_system_reset();
+ if (loadvm) {
+ if (load_vmstate(cur_mon, loadvm) < 0) {
+ autostart = 0;
+ }
+ }
if (incoming) {
qemu_start_incoming_migration(incoming);
if (len != 1)
exit(1);
- chdir("/");
- TFR(fd = open("/dev/null", O_RDWR));
+ if (chdir("/")) {
+ perror("not able to chdir to /");
+ exit(1);
+ }
+ TFR(fd = qemu_open("/dev/null", O_RDWR));
if (fd == -1)
exit(1);
}
fprintf(stderr, "chroot failed\n");
exit(1);
}
- chdir("/");
+ if (chdir("/")) {
+ perror("not able to chdir to /");
+ exit(1);
+ }
}
if (run_as) {