diff options
89 files changed, 708 insertions, 796 deletions
diff --git a/audio/audio.c b/audio/audio.c index e60c124de8..9d4dcc72dd 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1131,8 +1131,6 @@ static void audio_timer (void *opaque) */ int AUD_write (SWVoiceOut *sw, void *buf, int size) { - int bytes; - if (!sw) { /* XXX: Consider options */ return size; @@ -1143,14 +1141,11 @@ int AUD_write (SWVoiceOut *sw, void *buf, int size) return 0; } - bytes = sw->hw->pcm_ops->write (sw, buf, size); - return bytes; + return sw->hw->pcm_ops->write(sw, buf, size); } int AUD_read (SWVoiceIn *sw, void *buf, int size) { - int bytes; - if (!sw) { /* XXX: Consider options */ return size; @@ -1161,8 +1156,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size) return 0; } - bytes = sw->hw->pcm_ops->read (sw, buf, size); - return bytes; + return sw->hw->pcm_ops->read(sw, buf, size); } int AUD_get_buffer_size_out (SWVoiceOut *sw) @@ -301,9 +301,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque) assert(cco->drv); ret = cco->drv->bdrv_create(cco->filename, cco->opts, &local_err); - if (local_err) { - error_propagate(&cco->err, local_err); - } + error_propagate(&cco->err, local_err); cco->ret = ret; } @@ -364,9 +362,7 @@ int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp) } ret = bdrv_create(drv, filename, opts, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } @@ -1763,18 +1759,14 @@ fail: QDECREF(options); bs->options = NULL; bdrv_unref(bs); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return NULL; close_and_fail: bdrv_unref(bs); QDECREF(snapshot_options); QDECREF(options); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return NULL; } @@ -3599,9 +3591,7 @@ void bdrv_img_create(const char *filename, const char *fmt, out: qemu_opts_del(opts); qemu_opts_free(create_opts); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } AioContext *bdrv_get_aio_context(BlockDriverState *bs) @@ -3609,18 +3599,34 @@ AioContext *bdrv_get_aio_context(BlockDriverState *bs) return bs->aio_context; } +static void bdrv_do_remove_aio_context_notifier(BdrvAioNotifier *ban) +{ + QLIST_REMOVE(ban, list); + g_free(ban); +} + void bdrv_detach_aio_context(BlockDriverState *bs) { - BdrvAioNotifier *baf; + BdrvAioNotifier *baf, *baf_tmp; BdrvChild *child; if (!bs->drv) { return; } - QLIST_FOREACH(baf, &bs->aio_notifiers, list) { - baf->detach_aio_context(baf->opaque); + assert(!bs->walking_aio_notifiers); + bs->walking_aio_notifiers = true; + QLIST_FOREACH_SAFE(baf, &bs->aio_notifiers, list, baf_tmp) { + if (baf->deleted) { + bdrv_do_remove_aio_context_notifier(baf); + } else { + baf->detach_aio_context(baf->opaque); + } } + /* Never mind iterating again to check for ->deleted. bdrv_close() will + * remove remaining aio notifiers if we aren't called again. + */ + bs->walking_aio_notifiers = false; if (bs->drv->bdrv_detach_aio_context) { bs->drv->bdrv_detach_aio_context(bs); @@ -3635,7 +3641,7 @@ void bdrv_detach_aio_context(BlockDriverState *bs) void bdrv_attach_aio_context(BlockDriverState *bs, AioContext *new_context) { - BdrvAioNotifier *ban; + BdrvAioNotifier *ban, *ban_tmp; BdrvChild *child; if (!bs->drv) { @@ -3651,9 +3657,16 @@ void bdrv_attach_aio_context(BlockDriverState *bs, bs->drv->bdrv_attach_aio_context(bs, new_context); } - QLIST_FOREACH(ban, &bs->aio_notifiers, list) { - ban->attached_aio_context(new_context, ban->opaque); + assert(!bs->walking_aio_notifiers); + bs->walking_aio_notifiers = true; + QLIST_FOREACH_SAFE(ban, &bs->aio_notifiers, list, ban_tmp) { + if (ban->deleted) { + bdrv_do_remove_aio_context_notifier(ban); + } else { + ban->attached_aio_context(new_context, ban->opaque); + } } + bs->walking_aio_notifiers = false; } void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context) @@ -3695,11 +3708,14 @@ void bdrv_remove_aio_context_notifier(BlockDriverState *bs, QLIST_FOREACH_SAFE(ban, &bs->aio_notifiers, list, ban_next) { if (ban->attached_aio_context == attached_aio_context && ban->detach_aio_context == detach_aio_context && - ban->opaque == opaque) + ban->opaque == opaque && + ban->deleted == false) { - QLIST_REMOVE(ban, list); - g_free(ban); - + if (bs->walking_aio_notifiers) { + ban->deleted = true; + } else { + bdrv_do_remove_aio_context_notifier(ban); + } return; } } diff --git a/block/archipelago.c b/block/archipelago.c index b9f5e69d4a..37b8aca78d 100644 --- a/block/archipelago.c +++ b/block/archipelago.c @@ -974,11 +974,9 @@ err_exit2: static int64_t qemu_archipelago_getlength(BlockDriverState *bs) { - int64_t ret; BDRVArchipelagoState *s = bs->opaque; - ret = archipelago_volume_info(s); - return ret; + return archipelago_volume_info(s); } static int qemu_archipelago_truncate(BlockDriverState *bs, int64_t offset) diff --git a/block/backup.c b/block/backup.c index feeb9f8bf2..581269b29a 100644 --- a/block/backup.c +++ b/block/backup.c @@ -246,12 +246,20 @@ static void backup_abort(BlockJob *job) } } +static void backup_attached_aio_context(BlockJob *job, AioContext *aio_context) +{ + BackupBlockJob *s = container_of(job, BackupBlockJob, common); + + blk_set_aio_context(s->target, aio_context); +} + static const BlockJobDriver backup_job_driver = { - .instance_size = sizeof(BackupBlockJob), - .job_type = BLOCK_JOB_TYPE_BACKUP, - .set_speed = backup_set_speed, - .commit = backup_commit, - .abort = backup_abort, + .instance_size = sizeof(BackupBlockJob), + .job_type = BLOCK_JOB_TYPE_BACKUP, + .set_speed = backup_set_speed, + .commit = backup_commit, + .abort = backup_abort, + .attached_aio_context = backup_attached_aio_context, }; static BlockErrorAction backup_error_action(BackupBlockJob *job, @@ -392,9 +400,7 @@ static void coroutine_fn backup_run(void *opaque) while (!block_job_is_cancelled(&job->common)) { /* Yield until the job is cancelled. We just let our before_write * notify callback service CoW requests. */ - job->common.busy = false; - qemu_coroutine_yield(); - job->common.busy = true; + block_job_yield(&job->common); } } else if (job->sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) { ret = backup_run_incremental(job); diff --git a/block/io.c b/block/io.c index ebdb9d834c..7cf3645ade 100644 --- a/block/io.c +++ b/block/io.c @@ -2347,9 +2347,13 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, return 0; } - tracked_request_begin(&req, bs, sector_num, nb_sectors, - BDRV_TRACKED_DISCARD); - bdrv_set_dirty(bs, sector_num, nb_sectors); + tracked_request_begin(&req, bs, sector_num << BDRV_SECTOR_BITS, + nb_sectors << BDRV_SECTOR_BITS, BDRV_TRACKED_DISCARD); + + ret = notifier_with_return_list_notify(&bs->before_write_notifiers, &req); + if (ret < 0) { + goto out; + } max_discard = MIN_NON_ZERO(bs->bl.max_discard, BDRV_REQUEST_MAX_SECTORS); while (nb_sectors > 0) { @@ -2398,6 +2402,8 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, } ret = 0; out: + bdrv_set_dirty(bs, req.offset >> BDRV_SECTOR_BITS, + req.bytes >> BDRV_SECTOR_BITS); tracked_request_end(&req); return ret; } diff --git a/block/mirror.c b/block/mirror.c index 075384a9cf..a04ed9c7a4 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -331,6 +331,8 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) mirror_wait_for_io(s); } + block_job_pause_point(&s->common); + /* Find the number of consective dirty chunks following the first dirty * one, and wait for in flight requests in them. */ while (nb_chunks * sectors_per_chunk < (s->buf_size >> BDRV_SECTOR_BITS)) { @@ -582,6 +584,8 @@ static void coroutine_fn mirror_run(void *opaque) if (now - last_pause_ns > SLICE_TIME) { last_pause_ns = now; block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, 0); + } else { + block_job_pause_point(&s->common); } if (block_job_is_cancelled(&s->common)) { @@ -613,6 +617,8 @@ static void coroutine_fn mirror_run(void *opaque) goto immediate_exit; } + block_job_pause_point(&s->common); + cnt = bdrv_get_dirty_count(s->dirty_bitmap); /* s->common.offset contains the number of bytes already processed so * far, cnt is the number of dirty sectors remaining and @@ -795,18 +801,39 @@ static void mirror_complete(BlockJob *job, Error **errp) block_job_enter(&s->common); } +/* There is no matching mirror_resume() because mirror_run() will begin + * iterating again when the job is resumed. + */ +static void coroutine_fn mirror_pause(BlockJob *job) +{ + MirrorBlockJob *s = container_of(job, MirrorBlockJob, common); + + mirror_drain(s); +} + +static void mirror_attached_aio_context(BlockJob *job, AioContext *new_context) +{ + MirrorBlockJob *s = container_of(job, MirrorBlockJob, common); + + blk_set_aio_context(s->target, new_context); +} + static const BlockJobDriver mirror_job_driver = { - .instance_size = sizeof(MirrorBlockJob), - .job_type = BLOCK_JOB_TYPE_MIRROR, - .set_speed = mirror_set_speed, - .complete = mirror_complete, + .instance_size = sizeof(MirrorBlockJob), + .job_type = BLOCK_JOB_TYPE_MIRROR, + .set_speed = mirror_set_speed, + .complete = mirror_complete, + .pause = mirror_pause, + .attached_aio_context = mirror_attached_aio_context, }; static const BlockJobDriver commit_active_job_driver = { - .instance_size = sizeof(MirrorBlockJob), - .job_type = BLOCK_JOB_TYPE_COMMIT, - .set_speed = mirror_set_speed, - .complete = mirror_complete, + .instance_size = sizeof(MirrorBlockJob), + .job_type = BLOCK_JOB_TYPE_COMMIT, + .set_speed = mirror_set_speed, + .complete = mirror_complete, + .pause = mirror_pause, + .attached_aio_context = mirror_attached_aio_context, }; static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target, diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 893ddf6798..0fb43566fb 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -154,11 +154,9 @@ static int l2_load(BlockDriverState *bs, uint64_t l2_offset, uint64_t **l2_table) { BDRVQcow2State *s = bs->opaque; - int ret; - - ret = qcow2_cache_get(bs, s->l2_table_cache, l2_offset, (void**) l2_table); - return ret; + return qcow2_cache_get(bs, s->l2_table_cache, l2_offset, + (void **)l2_table); } /* diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 66f187a74b..3bef410839 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -218,13 +218,10 @@ static int load_refcount_block(BlockDriverState *bs, void **refcount_block) { BDRVQcow2State *s = bs->opaque; - int ret; BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_LOAD); - ret = qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset, - refcount_block); - - return ret; + return qcow2_cache_get(bs, s->refcount_block_cache, refcount_block_offset, + refcount_block); } /* diff --git a/block/qcow2.c b/block/qcow2.c index 4718f8250e..23f666d4ae 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2403,9 +2403,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp) ret = qcow2_create2(filename, size, backing_file, backing_fmt, flags, cluster_size, prealloc, opts, version, refcount_order, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); finish: g_free(backing_file); diff --git a/block/quorum.c b/block/quorum.c index ec6f3b9059..331b726f97 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -971,9 +971,7 @@ close_exit: exit: qemu_opts_del(opts); /* propagate error */ - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } diff --git a/block/raw-posix.c b/block/raw-posix.c index aacf13203f..bef7a671a6 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -582,15 +582,9 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVRawState *s = bs->opaque; - Error *local_err = NULL; - int ret; s->type = FTYPE_FILE; - ret = raw_open_common(bs, options, flags, 0, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } - return ret; + return raw_open_common(bs, options, flags, 0, errp); } static int raw_reopen_prepare(BDRVReopenState *state, @@ -2236,9 +2230,7 @@ hdev_open_Mac_error: ret = raw_open_common(bs, options, flags, 0, &local_err); if (ret < 0) { - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); #if defined(__APPLE__) && defined(__MACH__) if (*bsd_path) { filename = bsd_path; @@ -2443,17 +2435,11 @@ static int cdrom_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVRawState *s = bs->opaque; - Error *local_err = NULL; - int ret; s->type = FTYPE_CD; /* open will not fail even if no CD is inserted, so add O_NONBLOCK */ - ret = raw_open_common(bs, options, flags, O_NONBLOCK, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } - return ret; + return raw_open_common(bs, options, flags, O_NONBLOCK, errp); } static int cdrom_probe_device(const char *filename) @@ -2571,9 +2557,7 @@ static int cdrom_open(BlockDriverState *bs, QDict *options, int flags, ret = raw_open_common(bs, options, flags, 0, &local_err); if (ret) { - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } diff --git a/block/raw_bsd.c b/block/raw_bsd.c index b1d5237135..7f637914b7 100644 --- a/block/raw_bsd.c +++ b/block/raw_bsd.c @@ -190,14 +190,7 @@ static int raw_has_zero_init(BlockDriverState *bs) static int raw_create(const char *filename, QemuOpts *opts, Error **errp) { - Error *local_err = NULL; - int ret; - - ret = bdrv_create_file(filename, opts, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } - return ret; + return bdrv_create_file(filename, opts, errp); } static int raw_open(BlockDriverState *bs, QDict *options, int flags, diff --git a/block/rbd.c b/block/rbd.c index 5226b6fef8..0a5840d08b 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -883,10 +883,8 @@ static int qemu_rbd_snap_rollback(BlockDriverState *bs, const char *snapshot_name) { BDRVRBDState *s = bs->opaque; - int r; - r = rbd_snap_rollback(s->image, snapshot_name); - return r; + return rbd_snap_rollback(s->image, snapshot_name); } static int qemu_rbd_snap_list(BlockDriverState *bs, diff --git a/block/snapshot.c b/block/snapshot.c index da89d2b085..bf5c2ca5e1 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -358,9 +358,7 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs, ret = bdrv_snapshot_load_tmp(bs, NULL, id_or_name, &local_err); } - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); return ret; } diff --git a/block/vmdk.c b/block/vmdk.c index ee09423b46..2901692700 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1260,15 +1260,13 @@ static VmdkExtent *find_extent(BDRVVmdkState *s, static inline uint64_t vmdk_find_offset_in_cluster(VmdkExtent *extent, int64_t offset) { - uint64_t offset_in_cluster, extent_begin_offset, extent_relative_offset; + uint64_t extent_begin_offset, extent_relative_offset; uint64_t cluster_size = extent->cluster_sectors * BDRV_SECTOR_SIZE; extent_begin_offset = (extent->end_sector - extent->sectors) * BDRV_SECTOR_SIZE; extent_relative_offset = offset - extent_begin_offset; - offset_in_cluster = extent_relative_offset % cluster_size; - - return offset_in_cluster; + return extent_relative_offset % cluster_size; } static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent, diff --git a/block/vvfat.c b/block/vvfat.c index 6d2e21ce11..5569450616 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -114,15 +114,12 @@ static inline int array_ensure_allocated(array_t* array, int index) static inline void* array_get_next(array_t* array) { unsigned int next = array->next; - void* result; if (array_ensure_allocated(array, next) < 0) return NULL; array->next = next + 1; - result = array_get(array, next); - - return result; + return array_get(array, next); } static inline void* array_insert(array_t* array,unsigned int index,unsigned int count) { diff --git a/blockdev.c b/blockdev.c index c9a0068cd6..3a104a0aaa 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3644,9 +3644,7 @@ void qmp_drive_mirror(const char *device, const char *target, has_unmap, unmap, &local_err); bdrv_unref(target_bs); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); out: aio_context_release(aio_context); } @@ -3701,9 +3699,7 @@ void qmp_blockdev_mirror(const char *device, const char *target, has_on_target_error, on_target_error, true, true, &local_err); - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); aio_context_release(aio_context); } @@ -3811,6 +3807,7 @@ void qmp_block_job_resume(const char *device, Error **errp) job->user_paused = false; trace_qmp_block_job_resume(job); + block_job_iostatus_reset(job); block_job_resume(job); aio_context_release(aio_context); } @@ -3913,9 +3910,7 @@ void qmp_change_backing_file(const char *device, if (ro) { bdrv_reopen(image_bs, open_flags, &local_err); - if (local_err) { - error_propagate(errp, local_err); /* will preserve prior errp */ - } + error_propagate(errp, local_err); } out: diff --git a/blockjob.c b/blockjob.c index 01b896b7e7..90c4e262b0 100644 --- a/blockjob.c +++ b/blockjob.c @@ -60,6 +60,49 @@ BlockJob *block_job_next(BlockJob *job) return QLIST_NEXT(job, job_list); } +/* Normally the job runs in its BlockBackend's AioContext. The exception is + * block_job_defer_to_main_loop() where it runs in the QEMU main loop. Code + * that supports both cases uses this helper function. + */ +static AioContext *block_job_get_aio_context(BlockJob *job) +{ + return job->deferred_to_main_loop ? + qemu_get_aio_context() : + blk_get_aio_context(job->blk); +} + +static void block_job_attached_aio_context(AioContext *new_context, + void *opaque) +{ + BlockJob *job = opaque; + + if (job->driver->attached_aio_context) { + job->driver->attached_aio_context(job, new_context); + } + + block_job_resume(job); +} + +static void block_job_detach_aio_context(void *opaque) +{ + BlockJob *job = opaque; + + /* In case the job terminates during aio_poll()... */ + block_job_ref(job); + + block_job_pause(job); + + if (!job->paused) { + /* If job is !job->busy this kicks it into the next pause point. */ + block_job_enter(job); + } + while (!job->paused && !job->completed) { + aio_poll(block_job_get_aio_context(job), true); + } + + block_job_unref(job); +} + void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, int64_t speed, BlockCompletionFunc *cb, void *opaque, Error **errp) @@ -92,6 +135,9 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs, QLIST_INSERT_HEAD(&block_jobs, job, job_list); + blk_add_aio_context_notifier(blk, block_job_attached_aio_context, + block_job_detach_aio_context, job); + /* Only set speed when necessary to avoid NotSupported error */ if (speed != 0) { Error *local_err = NULL; @@ -117,6 +163,9 @@ void block_job_unref(BlockJob *job) BlockDriverState *bs = blk_bs(job->blk); bs->job = NULL; bdrv_op_unblock_all(bs, job->blocker); + blk_remove_aio_context_notifier(job->blk, + block_job_attached_aio_context, + block_job_detach_aio_context, job); blk_unref(job->blk); error_free(job->blocker); g_free(job->id); @@ -252,11 +301,37 @@ void block_job_pause(BlockJob *job) job->pause_count++; } -bool block_job_is_paused(BlockJob *job) +static bool block_job_should_pause(BlockJob *job) { return job->pause_count > 0; } +void coroutine_fn block_job_pause_point(BlockJob *job) +{ + if (!block_job_should_pause(job)) { + return; + } + if (block_job_is_cancelled(job)) { + return; + } + + if (job->driver->pause) { + job->driver->pause(job); + } + + if (block_job_should_pause(job) && !block_job_is_cancelled(job)) { + job->paused = true; + job->busy = false; + qemu_coroutine_yield(); /* wait for block_job_resume() */ + job->busy = true; + job->paused = false; + } + + if (job->driver->resume) { + job->driver->resume(job); + } +} + void block_job_resume(BlockJob *job) { assert(job->pause_count > 0); @@ -269,7 +344,6 @@ void block_job_resume(BlockJob *job) void block_job_enter(BlockJob *job) { - block_job_iostatus_reset(job); if (job->co && !job->busy) { qemu_coroutine_enter(job->co, NULL); } @@ -278,6 +352,7 @@ void block_job_enter(BlockJob *job) void block_job_cancel(BlockJob *job) { job->cancelled = true; + block_job_iostatus_reset(job); block_job_enter(job); } @@ -311,9 +386,7 @@ static int block_job_finish_sync(BlockJob *job, return -EBUSY; } while (!job->completed) { - aio_poll(job->deferred_to_main_loop ? qemu_get_aio_context() : - blk_get_aio_context(job->blk), - true); + aio_poll(block_job_get_aio_context(job), true); } ret = (job->cancelled && job->ret == 0) ? -ECANCELED : job->ret; block_job_unref(job); @@ -361,14 +434,12 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns) } job->busy = false; - if (!block_job_is_paused(job)) { + if (!block_job_should_pause(job)) { co_aio_sleep_ns(blk_get_aio_context(job->blk), type, ns); } - /* The job can be paused while sleeping, so check this again */ - if (block_job_is_paused(job)) { - qemu_coroutine_yield(); - } job->busy = true; + + block_job_pause_point(job); } void block_job_yield(BlockJob *job) @@ -381,8 +452,12 @@ void block_job_yield(BlockJob *job) } job->busy = false; - qemu_coroutine_yield(); + if (!block_job_should_pause(job)) { + qemu_coroutine_yield(); + } job->busy = true; + + block_job_pause_point(job); } BlockJobInfo *block_job_query(BlockJob *job) diff --git a/bootdevice.c b/bootdevice.c index bb9c08e535..33e3029e40 100644 --- a/bootdevice.c +++ b/bootdevice.c @@ -302,9 +302,7 @@ static void device_set_bootindex(Object *obj, Visitor *v, const char *name, add_boot_device_path(*prop->bootindex, prop->dev, prop->suffix); out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static void property_release_bootindex(Object *obj, const char *name, diff --git a/bsd-user/main.c b/bsd-user/main.c index abe9a26f9b..4819b9ec63 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include <machine/trap.h> +#include "qapi/error.h" #include "qemu.h" #include "qemu/path.h" #include "qemu/help_option.h" @@ -847,7 +848,7 @@ int main(int argc, char **argv) /* init debug */ qemu_log_needs_buffers(); - qemu_set_log_filename(log_file); + qemu_set_log_filename(log_file, &error_fatal); if (log_mask) { int mask; @@ -918,9 +918,7 @@ static void write_dump_header(DumpState *s, Error **errp) } else { create_header64(s, &local_err); } - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static size_t dump_bitmap_get_bufsize(DumpState *s) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 123160a94e..874e473cac 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -324,12 +324,9 @@ static void aml_free(gpointer data, gpointer user_data) Aml *init_aml_allocator(void) { - Aml *var; - assert(!alloc_list); alloc_list = g_ptr_array_new(); - var = aml_alloc(); - return var; + return aml_alloc(); } void free_aml_allocator(void) @@ -451,12 +448,10 @@ Aml *aml_name_decl(const char *name, Aml *val) /* ACPI 1.0b: 16.2.6.1 Arg Objects Encoding */ Aml *aml_arg(int pos) { - Aml *var; uint8_t op = 0x68 /* ARG0 op */ + pos; assert(pos <= 6); - var = aml_opcode(op); - return var; + return aml_opcode(op); } /* ACPI 2.0a: 17.2.4.4 Type 2 Opcodes Encoding: DefToInteger */ @@ -1082,12 +1077,10 @@ Aml *aml_string(const char *name_format, ...) /* ACPI 1.0b: 16.2.6.2 Local Objects Encoding */ Aml *aml_local(int num) { - Aml *var; uint8_t op = 0x60 /* Local0Op */ + num; assert(num <= 7); - var = aml_opcode(op); - return var; + return aml_opcode(op); } /* ACPI 2.0a: 17.2.2 Data Objects Encoding: DefVarPackage */ diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c index 93d7669fb5..098b17d020 100644 --- a/hw/audio/intel-hda.c +++ b/hw/audio/intel-hda.c @@ -219,10 +219,7 @@ static void intel_hda_reset(DeviceState *dev); static hwaddr intel_hda_addr(uint32_t lbase, uint32_t ubase) { - hwaddr addr; - - addr = ((uint64_t)ubase << 32) | lbase; - return addr; + return ((uint64_t)ubase << 32) | lbase; } static void intel_hda_update_int_sts(IntelHDAState *d) diff --git a/hw/audio/milkymist-ac97.c b/hw/audio/milkymist-ac97.c index 5075c2b148..bc8db71ae0 100644 --- a/hw/audio/milkymist-ac97.c +++ b/hw/audio/milkymist-ac97.c @@ -18,7 +18,7 @@ * * * Specification available at: - * http://www.milkymist.org/socdoc/ac97.pdf + * http://milkymist.walle.cc/socdoc/ac97.pdf */ #include "qemu/osdep.h" diff --git a/hw/char/milkymist-uart.c b/hw/char/milkymist-uart.c index 72f8484668..baddb37648 100644 --- a/hw/char/milkymist-uart.c +++ b/hw/char/milkymist-uart.c @@ -18,7 +18,7 @@ * * * Specification available at: - * http://www.milkymist.org/socdoc/uart.pdf + * http://milkymist.walle.cc/socdoc/uart.pdf */ #include "qemu/osdep.h" diff --git a/hw/display/milkymist-tmu2.c b/hw/display/milkymist-tmu2.c index 9bc88f93b6..356483fb21 100644 --- a/hw/display/milkymist-tmu2.c +++ b/hw/display/milkymist-tmu2.c @@ -20,7 +20,7 @@ * * * Specification available at: - * http://www.milkymist.org/socdoc/tmu2.pdf + * http://milkymist.walle.cc/socdoc/tmu2.pdf * */ @@ -443,21 +443,25 @@ static void milkymist_tmu2_reset(DeviceState *d) } } -static int milkymist_tmu2_init(SysBusDevice *dev) +static void milkymist_tmu2_init(Object *obj) { - MilkymistTMU2State *s = MILKYMIST_TMU2(dev); - - if (tmu2_glx_init(s)) { - return 1; - } + MilkymistTMU2State *s = MILKYMIST_TMU2(obj); + SysBusDevice *dev = SYS_BUS_DEVICE(obj); sysbus_init_irq(dev, &s->irq); - memory_region_init_io(&s->regs_region, OBJECT(s), &tmu2_mmio_ops, s, + memory_region_init_io(&s->regs_region, obj, &tmu2_mmio_ops, s, "milkymist-tmu2", R_MAX * 4); sysbus_init_mmio(dev, &s->regs_region); +} - return 0; +static void milkymist_tmu2_realize(DeviceState *dev, Error **errp) +{ + MilkymistTMU2State *s = MILKYMIST_TMU2(dev); + + if (tmu2_glx_init(s)) { + error_setg(errp, "tmu2_glx_init failed"); + } } static const VMStateDescription vmstate_milkymist_tmu2 = { @@ -473,9 +477,8 @@ static const VMStateDescription vmstate_milkymist_tmu2 = { static void milkymist_tmu2_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = milkymist_tmu2_init; + dc->realize = milkymist_tmu2_realize; dc->reset = milkymist_tmu2_reset; dc->vmsd = &vmstate_milkymist_tmu2; } @@ -484,6 +487,7 @@ static const TypeInfo milkymist_tmu2_info = { .name = TYPE_MILKYMIST_TMU2, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(MilkymistTMU2State), + .instance_init = milkymist_tmu2_init, .class_init = milkymist_tmu2_class_init, }; diff --git a/hw/display/milkymist-vgafb.c b/hw/display/milkymist-vgafb.c index 19ca256479..177fdac7d8 100644 --- a/hw/display/milkymist-vgafb.c +++ b/hw/display/milkymist-vgafb.c @@ -19,7 +19,7 @@ * * * Specification available at: - * http://www.milkymist.org/socdoc/vgafb.pdf + * http://milkymist.walle.cc/socdoc/vgafb.pdf */ #include "qemu/osdep.h" @@ -292,17 +292,21 @@ static const GraphicHwOps vgafb_ops = { .gfx_update = vgafb_update_display, }; -static int milkymist_vgafb_init(SysBusDevice *dev) +static void milkymist_vgafb_init(Object *obj) { - MilkymistVgafbState *s = MILKYMIST_VGAFB(dev); + MilkymistVgafbState *s = MILKYMIST_VGAFB(obj); + SysBusDevice *dev = SYS_BUS_DEVICE(obj); memory_region_init_io(&s->regs_region, OBJECT(s), &vgafb_mmio_ops, s, "milkymist-vgafb", R_MAX * 4); sysbus_init_mmio(dev, &s->regs_region); +} - s->con = graphic_console_init(DEVICE(dev), 0, &vgafb_ops, s); +static void milkymist_vgafb_realize(DeviceState *dev, Error **errp) +{ + MilkymistVgafbState *s = MILKYMIST_VGAFB(dev); - return 0; + s->con = graphic_console_init(dev, 0, &vgafb_ops, s); } static int vgafb_post_load(void *opaque, int version_id) @@ -331,18 +335,18 @@ static Property milkymist_vgafb_properties[] = { static void milkymist_vgafb_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = milkymist_vgafb_init; dc->reset = milkymist_vgafb_reset; dc->vmsd = &vmstate_milkymist_vgafb; dc->props = milkymist_vgafb_properties; + dc->realize = milkymist_vgafb_realize; } static const TypeInfo milkymist_vgafb_info = { .name = TYPE_MILKYMIST_VGAFB, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(MilkymistVgafbState), + .instance_init = milkymist_vgafb_init, .class_init = milkymist_vgafb_class_init, }; diff --git a/hw/display/vga.c b/hw/display/vga.c index 9ebc54f22b..2a88b3c1b4 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -700,9 +700,7 @@ static void vbe_update_vgaregs(VGACommonState *s) static uint32_t vbe_ioport_read_index(void *opaque, uint32_t addr) { VGACommonState *s = opaque; - uint32_t val; - val = s->vbe_index; - return val; + return s->vbe_index; } uint32_t vbe_ioport_read_data(void *opaque, uint32_t addr) diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 4bc74a32d2..6842a5596a 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -233,9 +233,7 @@ static void ide_dev_set_bootindex(Object *obj, Visitor *v, const char *name, d->unit ? "/disk@1" : "/disk@0"); } out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static void ide_dev_instance_init(Object *obj) diff --git a/hw/intc/lm32_pic.c b/hw/intc/lm32_pic.c index edc08f184a..3dad01c5ba 100644 --- a/hw/intc/lm32_pic.c +++ b/hw/intc/lm32_pic.c @@ -152,17 +152,16 @@ static void pic_reset(DeviceState *d) } } -static int lm32_pic_init(SysBusDevice *sbd) +static void lm32_pic_init(Object *obj) { - DeviceState *dev = DEVICE(sbd); - LM32PicState *s = LM32_PIC(dev); + DeviceState *dev = DEVICE(obj); + LM32PicState *s = LM32_PIC(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); qdev_init_gpio_in(dev, irq_handler, 32); sysbus_init_irq(sbd, &s->parent_irq); pic = s; - - return 0; } static const VMStateDescription vmstate_lm32_pic = { @@ -181,9 +180,7 @@ static const VMStateDescription vmstate_lm32_pic = { static void lm32_pic_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = lm32_pic_init; dc->reset = pic_reset; dc->vmsd = &vmstate_lm32_pic; } @@ -192,6 +189,7 @@ static const TypeInfo lm32_pic_info = { .name = TYPE_LM32_PIC, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(LM32PicState), + .instance_init = lm32_pic_init, .class_init = lm32_pic_class_init, }; diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c index 680857f0c7..fef808011f 100644 --- a/hw/intc/s390_flic_kvm.c +++ b/hw/intc/s390_flic_kvm.c @@ -195,7 +195,7 @@ static int kvm_s390_register_io_adapter(S390FLICState *fs, uint32_t id, .swap = swap, }; KVMS390FLICState *flic = KVM_S390_FLIC(fs); - int r, ret; + int r; struct kvm_device_attr attr = { .group = KVM_DEV_FLIC_ADAPTER_REGISTER, .addr = (uint64_t)&adapter, @@ -208,8 +208,7 @@ static int kvm_s390_register_io_adapter(S390FLICState *fs, uint32_t id, r = ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr); - ret = r ? -errno : 0; - return ret; + return r ? -errno : 0; } static int kvm_s390_io_adapter_map(S390FLICState *fs, uint32_t id, diff --git a/hw/misc/milkymist-hpdmc.c b/hw/misc/milkymist-hpdmc.c index b97000fc49..e6140eec6b 100644 --- a/hw/misc/milkymist-hpdmc.c +++ b/hw/misc/milkymist-hpdmc.c @@ -18,7 +18,7 @@ * * * Specification available at: - * http://www.milkymist.org/socdoc/hpdmc.pdf + * http://milkymist.walle.cc/socdoc/hpdmc.pdf */ #include "qemu/osdep.h" diff --git a/hw/misc/milkymist-pfpu.c b/hw/misc/milkymist-pfpu.c index 57acd7b365..1da21a643e 100644 --- a/hw/misc/milkymist-pfpu.c +++ b/hw/misc/milkymist-pfpu.c @@ -18,7 +18,7 @@ * * * Specification available at: - * http://www.milkymist.org/socdoc/pfpu.pdf + * http://milkymist.walle.cc/socdoc/pfpu.pdf * */ diff --git a/hw/net/ne2000-isa.c b/hw/net/ne2000-isa.c index a7f5a9464d..8fab7ae2ec 100644 --- a/hw/net/ne2000-isa.c +++ b/hw/net/ne2000-isa.c @@ -127,9 +127,7 @@ static void isa_ne2000_set_bootindex(Object *obj, Visitor *v, s->c.bootindex = boot_index; out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static void isa_ne2000_instance_init(Object *obj) diff --git a/hw/pci-host/uninorth.c b/hw/pci-host/uninorth.c index 15b1054232..7aac4d67a4 100644 --- a/hw/pci-host/uninorth.c +++ b/hw/pci-host/uninorth.c @@ -62,12 +62,9 @@ typedef struct UNINState { static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num) { - int retval; int devfn = pci_dev->devfn & 0x00FFFFFF; - retval = (((devfn >> 11) & 0x1F) + irq_num) & 3; - - return retval; + return (((devfn >> 11) & 0x1F) + irq_num) & 3; } static void pci_unin_set_irq(void *opaque, int irq_num, int level) diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c index 3d9b9c60f4..ae40db8fd2 100644 --- a/hw/ppc/spapr_vio.c +++ b/hw/ppc/spapr_vio.c @@ -57,12 +57,9 @@ static char *spapr_vio_get_dev_name(DeviceState *qdev) { VIOsPAPRDevice *dev = VIO_SPAPR_DEVICE(qdev); VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev); - char *name; /* Device tree style name device@reg */ - name = g_strdup_printf("%s@%x", pc->dt_name, dev->reg); - - return name; + return g_strdup_printf("%s@%x", pc->dt_name, dev->reg); } static void spapr_vio_bus_class_init(ObjectClass *klass, void *data) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index e257ca5ab0..52f079a884 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -180,10 +180,8 @@ static HotplugHandler *s390_get_hotplug_handler(MachineState *machine, static void s390_hot_add_cpu(const int64_t id, Error **errp) { MachineState *machine = MACHINE(qdev_get_machine()); - Error *err = NULL; - s390x_new_cpu(machine->cpu_model, id, &err); - error_propagate(errp, err); + s390x_new_cpu(machine->cpu_model, id, errp); } static void ccw_machine_class_init(ObjectClass *oc, void *data) diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index 2192be8774..1625e6b38b 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -884,15 +884,11 @@ static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp) DeviceState *qdev = DEVICE(ccw_dev); VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev); DeviceState *vdev = DEVICE(&dev->vdev); - Error *err = NULL; virtio_net_set_netclient_name(&dev->vdev, qdev->id, object_get_typename(OBJECT(qdev))); qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); - object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + object_property_set_bool(OBJECT(vdev), true, "realized", errp); } static void virtio_ccw_net_instance_init(Object *obj) @@ -909,13 +905,9 @@ static void virtio_ccw_blk_realize(VirtioCcwDevice *ccw_dev, Error **errp) { VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev); DeviceState *vdev = DEVICE(&dev->vdev); - Error *err = NULL; qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); - object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + object_property_set_bool(OBJECT(vdev), true, "realized", errp); } static void virtio_ccw_blk_instance_init(Object *obj) @@ -935,7 +927,6 @@ static void virtio_ccw_serial_realize(VirtioCcwDevice *ccw_dev, Error **errp) VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev); DeviceState *vdev = DEVICE(&dev->vdev); DeviceState *proxy = DEVICE(ccw_dev); - Error *err = NULL; char *bus_name; /* @@ -949,10 +940,7 @@ static void virtio_ccw_serial_realize(VirtioCcwDevice *ccw_dev, Error **errp) } qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); - object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + object_property_set_bool(OBJECT(vdev), true, "realized", errp); } @@ -968,13 +956,9 @@ static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp) { VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev); DeviceState *vdev = DEVICE(&dev->vdev); - Error *err = NULL; qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); - object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + object_property_set_bool(OBJECT(vdev), true, "realized", errp); } static void virtio_ccw_balloon_instance_init(Object *obj) @@ -995,7 +979,6 @@ static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp) VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev); DeviceState *vdev = DEVICE(&dev->vdev); DeviceState *qdev = DEVICE(ccw_dev); - Error *err = NULL; char *bus_name; /* @@ -1009,10 +992,7 @@ static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp) } qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); - object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + object_property_set_bool(OBJECT(vdev), true, "realized", errp); } static void virtio_ccw_scsi_instance_init(Object *obj) @@ -1030,13 +1010,9 @@ static void vhost_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp) { VHostSCSICcw *dev = VHOST_SCSI_CCW(ccw_dev); DeviceState *vdev = DEVICE(&dev->vdev); - Error *err = NULL; qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); - object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + object_property_set_bool(OBJECT(vdev), true, "realized", errp); } static void vhost_ccw_scsi_instance_init(Object *obj) @@ -1854,13 +1830,9 @@ static void virtio_ccw_9p_realize(VirtioCcwDevice *ccw_dev, Error **errp) { V9fsCCWState *dev = VIRTIO_9P_CCW(ccw_dev); DeviceState *vdev = DEVICE(&dev->vdev); - Error *err = NULL; qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); - object_property_set_bool(OBJECT(vdev), true, "realized", &err); - if (err) { - error_propagate(errp, err); - } + object_property_set_bool(OBJECT(vdev), true, "realized", errp); } static void virtio_ccw_9p_class_init(ObjectClass *klass, void *data) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index a9ffc32682..d1772183cf 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -410,17 +410,14 @@ static void megasas_encode_lba(uint8_t *cdb, uint64_t lba, static uint64_t megasas_fw_time(void) { struct tm curtime; - uint64_t bcd_time; qemu_get_timedate(&curtime, 0); - bcd_time = ((uint64_t)curtime.tm_sec & 0xff) << 48 | + return ((uint64_t)curtime.tm_sec & 0xff) << 48 | ((uint64_t)curtime.tm_min & 0xff) << 40 | ((uint64_t)curtime.tm_hour & 0xff) << 32 | ((uint64_t)curtime.tm_mday & 0xff) << 24 | ((uint64_t)curtime.tm_mon & 0xff) << 16 | ((uint64_t)(curtime.tm_year + 1900) & 0xffff); - - return bcd_time; } /* diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 71372a8383..6a2d89afba 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -579,10 +579,7 @@ const SCSIReqOps scsi_generic_req_ops = { static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun, uint8_t *buf, void *hba_private) { - SCSIRequest *req; - - req = scsi_req_alloc(&scsi_generic_req_ops, d, tag, lun, hba_private); - return req; + return scsi_req_alloc(&scsi_generic_req_ops, d, tag, lun, hba_private); } static Property scsi_generic_properties[] = { diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index c04ff02fad..1f2f0ed44a 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -18,7 +18,7 @@ * * * Specification available at: - * http://www.milkymist.org/socdoc/memcard.pdf + * http://milkymist.walle.cc/socdoc/memcard.pdf */ #include "qemu/osdep.h" diff --git a/hw/timer/lm32_timer.c b/hw/timer/lm32_timer.c index 3198355aa4..e45a65bb9d 100644 --- a/hw/timer/lm32_timer.c +++ b/hw/timer/lm32_timer.c @@ -176,21 +176,26 @@ static void timer_reset(DeviceState *d) ptimer_stop(s->ptimer); } -static int lm32_timer_init(SysBusDevice *dev) +static void lm32_timer_init(Object *obj) { - LM32TimerState *s = LM32_TIMER(dev); + LM32TimerState *s = LM32_TIMER(obj); + SysBusDevice *dev = SYS_BUS_DEVICE(obj); sysbus_init_irq(dev, &s->irq); s->bh = qemu_bh_new(timer_hit, s); s->ptimer = ptimer_init(s->bh); - ptimer_set_freq(s->ptimer, s->freq_hz); - memory_region_init_io(&s->iomem, OBJECT(s), &timer_ops, s, + memory_region_init_io(&s->iomem, obj, &timer_ops, s, "timer", R_MAX * 4); sysbus_init_mmio(dev, &s->iomem); +} - return 0; +static void lm32_timer_realize(DeviceState *dev, Error **errp) +{ + LM32TimerState *s = LM32_TIMER(dev); + + ptimer_set_freq(s->ptimer, s->freq_hz); } static const VMStateDescription vmstate_lm32_timer = { @@ -213,9 +218,8 @@ static Property lm32_timer_properties[] = { static void lm32_timer_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = lm32_timer_init; + dc->realize = lm32_timer_realize; dc->reset = timer_reset; dc->vmsd = &vmstate_lm32_timer; dc->props = lm32_timer_properties; @@ -225,6 +229,7 @@ static const TypeInfo lm32_timer_info = { .name = TYPE_LM32_TIMER, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(LM32TimerState), + .instance_init = lm32_timer_init, .class_init = lm32_timer_class_init, }; diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index a11b8b4b21..f4e333eb8f 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -105,12 +105,10 @@ static inline bool rtc_running(RTCState *s) static uint64_t get_guest_rtc_ns(RTCState *s) { - uint64_t guest_rtc; uint64_t guest_clock = qemu_clock_get_ns(rtc_clock); - guest_rtc = s->base_rtc * NANOSECONDS_PER_SECOND + + return s->base_rtc * NANOSECONDS_PER_SECOND + guest_clock - s->last_update + s->offset; - return guest_rtc; } #ifdef TARGET_I386 diff --git a/hw/timer/milkymist-sysctl.c b/hw/timer/milkymist-sysctl.c index 5f2948037a..21948328ce 100644 --- a/hw/timer/milkymist-sysctl.c +++ b/hw/timer/milkymist-sysctl.c @@ -18,7 +18,7 @@ * * * Specification available at: - * http://www.milkymist.org/socdoc/sysctl.pdf + * http://milkymist.walle.cc/socdoc/sysctl.pdf */ #include "qemu/osdep.h" @@ -270,9 +270,10 @@ static void milkymist_sysctl_reset(DeviceState *d) s->regs[R_GPIO_IN] = s->strappings; } -static int milkymist_sysctl_init(SysBusDevice *dev) +static void milkymist_sysctl_init(Object *obj) { - MilkymistSysctlState *s = MILKYMIST_SYSCTL(dev); + MilkymistSysctlState *s = MILKYMIST_SYSCTL(obj); + SysBusDevice *dev = SYS_BUS_DEVICE(obj); sysbus_init_irq(dev, &s->gpio_irq); sysbus_init_irq(dev, &s->timer0_irq); @@ -282,14 +283,18 @@ static int milkymist_sysctl_init(SysBusDevice *dev) s->bh1 = qemu_bh_new(timer1_hit, s); s->ptimer0 = ptimer_init(s->bh0); s->ptimer1 = ptimer_init(s->bh1); - ptimer_set_freq(s->ptimer0, s->freq_hz); - ptimer_set_freq(s->ptimer1, s->freq_hz); - memory_region_init_io(&s->regs_region, OBJECT(s), &sysctl_mmio_ops, s, + memory_region_init_io(&s->regs_region, obj, &sysctl_mmio_ops, s, "milkymist-sysctl", R_MAX * 4); sysbus_init_mmio(dev, &s->regs_region); +} - return 0; +static void milkymist_sysctl_realize(DeviceState *dev, Error **errp) +{ + MilkymistSysctlState *s = MILKYMIST_SYSCTL(dev); + + ptimer_set_freq(s->ptimer0, s->freq_hz); + ptimer_set_freq(s->ptimer1, s->freq_hz); } static const VMStateDescription vmstate_milkymist_sysctl = { @@ -319,9 +324,8 @@ static Property milkymist_sysctl_properties[] = { static void milkymist_sysctl_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = milkymist_sysctl_init; + dc->realize = milkymist_sysctl_realize; dc->reset = milkymist_sysctl_reset; dc->vmsd = &vmstate_milkymist_sysctl; dc->props = milkymist_sysctl_properties; @@ -331,6 +335,7 @@ static const TypeInfo milkymist_sysctl_info = { .name = TYPE_MILKYMIST_SYSCTL, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(MilkymistSysctlState), + .instance_init = milkymist_sysctl_init, .class_init = milkymist_sysctl_class_init, }; diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index 248a580457..9fd00dfffc 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -818,9 +818,7 @@ static void usb_msd_set_bootindex(Object *obj, Visitor *v, const char *name, } out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static const TypeInfo usb_storage_dev_type_info = { diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index bfedbbf17f..1a0278304b 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -761,9 +761,7 @@ static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy, VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); VirtQueue *vq = virtio_get_queue(vdev, queue_no); EventNotifier *n = virtio_queue_get_guest_notifier(vq); - int ret; - ret = kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq); - return ret; + return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq); } static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy, diff --git a/include/block/block_int.h b/include/block/block_int.h index 688c6be009..205715600b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -361,6 +361,7 @@ typedef struct BdrvAioNotifier { void (*detach_aio_context)(void *opaque); void *opaque; + bool deleted; QLIST_ENTRY(BdrvAioNotifier) list; } BdrvAioNotifier; @@ -427,6 +428,7 @@ struct BlockDriverState { * BDS may register themselves in this list to be notified of changes * regarding this BDS's context */ QLIST_HEAD(, BdrvAioNotifier) aio_notifiers; + bool walking_aio_notifiers; /* to make removal during iteration safe */ char filename[PATH_MAX]; char backing_file[PATH_MAX]; /* if non zero, the image is a diff of diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 00ac4184cc..7dc720c82b 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -70,6 +70,27 @@ typedef struct BlockJobDriver { * never both. */ void (*abort)(BlockJob *job); + + /** + * If the callback is not NULL, it will be invoked when the job transitions + * into the paused state. Paused jobs must not perform any asynchronous + * I/O or event loop activity. This callback is used to quiesce jobs. + */ + void coroutine_fn (*pause)(BlockJob *job); + + /** + * If the callback is not NULL, it will be invoked when the job transitions + * out of the paused state. Any asynchronous I/O or event loop activity + * should be restarted from this callback. + */ + void coroutine_fn (*resume)(BlockJob *job); + + /* + * If the callback is not NULL, it will be invoked before the job is + * resumed in a new AioContext. This is the place to move any resources + * besides job->blk to the new AioContext. + */ + void (*attached_aio_context)(BlockJob *job, AioContext *new_context); } BlockJobDriver; /** @@ -119,13 +140,19 @@ struct BlockJob { bool user_paused; /** - * Set to false by the job while it is in a quiescent state, where - * no I/O is pending and the job has yielded on any condition - * that is not detected by #aio_poll, such as a timer. + * Set to false by the job while the coroutine has yielded and may be + * re-entered by block_job_enter(). There may still be I/O or event loop + * activity pending. */ bool busy; /** + * Set to true by the job while it is in a quiescent state, where + * no I/O or event loop activity is pending. + */ + bool paused; + + /** * Set to true when the job is ready to be completed. */ bool ready; @@ -299,6 +326,15 @@ bool block_job_is_cancelled(BlockJob *job); BlockJobInfo *block_job_query(BlockJob *job); /** + * block_job_pause_point: + * @job: The job that is ready to pause. + * + * Pause now if block_job_pause() has been called. Block jobs that perform + * lots of I/O must call this between requests so that the job can be paused. + */ +void coroutine_fn block_job_pause_point(BlockJob *job); + +/** * block_job_pause: * @job: The job to be paused. * @@ -348,15 +384,6 @@ void block_job_event_completed(BlockJob *job, const char *msg); void block_job_event_ready(BlockJob *job); /** - * block_job_is_paused: - * @job: The job being queried. - * - * Returns whether the job is currently paused, or will pause - * as soon as it reaches a sleeping point. - */ -bool block_job_is_paused(BlockJob *job); - -/** * block_job_cancel_sync: * @job: The job to be canceled. * diff --git a/include/qemu/log.h b/include/qemu/log.h index 234fa81153..8bec6b4039 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -106,8 +106,8 @@ extern const QEMULogItem qemu_log_items[]; void qemu_set_log(int log_flags); void qemu_log_needs_buffers(void); -void qemu_set_log_filename(const char *filename); -void qemu_set_dfilter_ranges(const char *ranges); +void qemu_set_log_filename(const char *filename, Error **errp); +void qemu_set_dfilter_ranges(const char *ranges, Error **errp); bool qemu_log_in_addr_range(uint64_t addr); int qemu_str_to_log_mask(const char *str); diff --git a/linux-user/main.c b/linux-user/main.c index b9a4e0ea45..358ed01e96 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -21,6 +21,7 @@ #include <sys/syscall.h> #include <sys/resource.h> +#include "qapi/error.h" #include "qemu.h" #include "qemu/path.h" #include "qemu/cutils.h" @@ -3845,7 +3846,7 @@ static void handle_arg_log(const char *arg) static void handle_arg_log_filename(const char *arg) { - qemu_set_log_filename(arg); + qemu_set_log_filename(arg, &error_fatal); } static void handle_arg_set_env(const char *arg) diff --git a/linux-user/signal.c b/linux-user/signal.c index 61c1145446..1dadddf2dd 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -195,7 +195,6 @@ int block_signals(void) { TaskState *ts = (TaskState *)thread_cpu->opaque; sigset_t set; - int pending; /* It's OK to block everything including SIGSEGV, because we won't * run any further guest code before unblocking signals in @@ -204,9 +203,7 @@ int block_signals(void) sigfillset(&set); sigprocmask(SIG_SETMASK, &set, 0); - pending = atomic_xchg(&ts->signal_pending, 1); - - return pending; + return atomic_xchg(&ts->signal_pending, 1); } /* Wrapper for sigprocmask function @@ -3956,9 +3953,7 @@ static void setup_sigcontext(struct target_sigcontext *sc, static inline unsigned long align_sigframe(unsigned long sp) { - unsigned long i; - i = sp & ~3UL; - return i; + return sp & ~3UL; } static inline abi_ulong get_sigframe(struct target_sigaction *ka, @@ -4555,7 +4550,7 @@ static target_ulong get_sigframe(struct target_sigaction *ka, CPUPPCState *env, int frame_size) { - target_ulong oldsp, newsp; + target_ulong oldsp; oldsp = env->gpr[1]; @@ -4565,9 +4560,7 @@ static target_ulong get_sigframe(struct target_sigaction *ka, + target_sigaltstack_used.ss_size); } - newsp = (oldsp - frame_size) & ~0xFUL; - - return newsp; + return (oldsp - frame_size) & ~0xFUL; } static void save_user_regs(CPUPPCState *env, struct target_mcontext *frame) @@ -1111,7 +1111,12 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname, static void hmp_logfile(Monitor *mon, const QDict *qdict) { - qemu_set_log_filename(qdict_get_str(qdict, "filename")); + Error *err = NULL; + + qemu_set_log_filename(qdict_get_str(qdict, "filename"), &err); + if (err) { + error_report_err(err); + } } static void hmp_log(Monitor *mon, const QDict *qdict) diff --git a/page_cache.c b/page_cache.c index a2809db2f5..5f8578736e 100644 --- a/page_cache.c +++ b/page_cache.c @@ -111,11 +111,8 @@ void cache_fini(PageCache *cache) static size_t cache_get_cache_pos(const PageCache *cache, uint64_t address) { - size_t pos; - g_assert(cache->max_num_items); - pos = (address / cache->page_size) & (cache->max_num_items - 1); - return pos; + return (address / cache->page_size) & (cache->max_num_items - 1); } static CacheItem *cache_get_by_addr(const PageCache *cache, uint64_t addr) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index eaef7be42e..ea37c097cf 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -127,7 +127,6 @@ int64_t qmp_guest_get_time(Error **errp) { int ret; qemu_timeval tq; - int64_t time_ns; ret = qemu_gettimeofday(&tq); if (ret < 0) { @@ -135,8 +134,7 @@ int64_t qmp_guest_get_time(Error **errp) return -1; } - time_ns = tq.tv_sec * 1000000000LL + tq.tv_usec * 1000; - return time_ns; + return tq.tv_sec * 1000000000LL + tq.tv_usec * 1000; } void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index c1a8588206..9c9be12116 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -247,9 +247,7 @@ out: if (token) { CloseHandle(token); } - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque, @@ -882,9 +880,7 @@ static void check_suspend_mode(GuestSuspendMode mode, Error **errp) } out: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); } static DWORD WINAPI do_suspend(LPVOID opaque) @@ -1154,7 +1150,6 @@ out: int64_t qmp_guest_get_time(Error **errp) { SYSTEMTIME ts = {0}; - int64_t time_ns; FILETIME tf; GetSystemTime(&ts); @@ -1168,10 +1163,8 @@ int64_t qmp_guest_get_time(Error **errp) return -1; } - time_ns = ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime) + return ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime) - W32_FT_OFFSET) * 100; - - return time_ns; } void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) diff --git a/qobject/qlist.c b/qobject/qlist.c index 1ec74de2b3..86b60cb88c 100644 --- a/qobject/qlist.c +++ b/qobject/qlist.c @@ -100,7 +100,6 @@ QObject *qlist_pop(QList *qlist) QObject *qlist_peek(QList *qlist) { QListEntry *entry; - QObject *ret; if (qlist == NULL || QTAILQ_EMPTY(&qlist->head)) { return NULL; @@ -108,9 +107,7 @@ QObject *qlist_peek(QList *qlist) entry = QTAILQ_FIRST(&qlist->head); - ret = entry->value; - - return ret; + return entry->value; } int qlist_empty(const QList *qlist) diff --git a/qom/object.c b/qom/object.c index 0311414c0a..9743ea4708 100644 --- a/qom/object.c +++ b/qom/object.c @@ -549,9 +549,7 @@ Object *object_new_with_propv(const char *typename, return obj; error: - if (local_err) { - error_propagate(errp, local_err); - } + error_propagate(errp, local_err); object_unref(obj); return NULL; } diff --git a/scripts/coccinelle/error_propagate_null.cocci b/scripts/coccinelle/error_propagate_null.cocci new file mode 100644 index 0000000000..c23638007a --- /dev/null +++ b/scripts/coccinelle/error_propagate_null.cocci @@ -0,0 +1,10 @@ +// error_propagate() already ignores local_err==NULL, so there's +// no need to check it before calling. + +@@ +identifier L; +expression E; +@@ +-if (L) { + error_propagate(E, L); +-} diff --git a/scripts/coccinelle/remove_local_err.cocci b/scripts/coccinelle/remove_local_err.cocci new file mode 100644 index 0000000000..9261c99687 --- /dev/null +++ b/scripts/coccinelle/remove_local_err.cocci @@ -0,0 +1,29 @@ +// Replace unnecessary usage of local_err variable with +// direct usage of errp argument + +@@ +identifier F; +expression list ARGS; +expression F2; +identifier LOCAL_ERR; +identifier ERRP; +idexpression V; +typedef Error; +@@ + F(..., Error **ERRP) + { + ... +- Error *LOCAL_ERR; + ... when != LOCAL_ERR + when != ERRP +( +- F2(ARGS, &LOCAL_ERR); +- error_propagate(ERRP, LOCAL_ERR); ++ F2(ARGS, ERRP); +| +- V = F2(ARGS, &LOCAL_ERR); +- error_propagate(ERRP, LOCAL_ERR); ++ V = F2(ARGS, ERRP); +) + ... when != LOCAL_ERR + } diff --git a/scripts/coccinelle/return_directly.cocci b/scripts/coccinelle/return_directly.cocci new file mode 100644 index 0000000000..48680f2c2a --- /dev/null +++ b/scripts/coccinelle/return_directly.cocci @@ -0,0 +1,19 @@ +// replace 'R = X; return R;' with 'return R;' +@@ +identifier VAR; +expression E; +type T; +identifier F; +@@ + T F(...) + { + ... +- T VAR; + ... when != VAR + +- VAR = ++ return + E; +- return VAR; + ... when != VAR + } diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 3665fecb5f..3bd3cfc3ad 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1875,7 +1875,6 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, { uint32_t *array = (uint32_t *)opaque; FeatureWord w; - Error *err = NULL; X86CPUFeatureWordInfo word_infos[FEATURE_WORDS] = { }; X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS] = { }; X86CPUFeatureWordInfoList *list = NULL; @@ -1895,8 +1894,7 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, list = &list_entries[w]; } - visit_type_X86CPUFeatureWordInfoList(v, "feature-words", &list, &err); - error_propagate(errp, err); + visit_type_X86CPUFeatureWordInfoList(v, "feature-words", &list, errp); } static void x86_get_hv_spinlocks(Object *obj, Visitor *v, const char *name, diff --git a/target-i386/fpu_helper.c b/target-i386/fpu_helper.c index 206e60fdf5..929489bfc8 100644 --- a/target-i386/fpu_helper.c +++ b/target-i386/fpu_helper.c @@ -298,18 +298,12 @@ int32_t helper_fistt_ST0(CPUX86State *env) int32_t helper_fisttl_ST0(CPUX86State *env) { - int32_t val; - - val = floatx80_to_int32_round_to_zero(ST0, &env->fp_status); - return val; + return floatx80_to_int32_round_to_zero(ST0, &env->fp_status); } int64_t helper_fisttll_ST0(CPUX86State *env) { - int64_t val; - - val = floatx80_to_int64_round_to_zero(ST0, &env->fp_status); - return val; + return floatx80_to_int64_round_to_zero(ST0, &env->fp_status); } void helper_fldt_ST0(CPUX86State *env, target_ulong ptr) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index ff92b1d118..f3698f19b5 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1346,7 +1346,7 @@ static int kvm_put_xsave(X86CPU *cpu) CPUX86State *env = &cpu->env; X86XSaveArea *xsave = env->kvm_xsave_buf; uint16_t cwd, swd, twd; - int i, r; + int i; if (!has_xsave) { return kvm_put_fpu(cpu); @@ -1395,8 +1395,7 @@ static int kvm_put_xsave(X86CPU *cpu) 16 * sizeof env->xmm_regs[16]); memcpy(&xsave->pkru_state, &env->pkru, sizeof env->pkru); #endif - r = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_XSAVE, xsave); - return r; + return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_XSAVE, xsave); } static int kvm_put_xcrs(X86CPU *cpu) diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c index 7cf980748e..1ae1dda0af 100644 --- a/target-mips/op_helper.c +++ b/target-mips/op_helper.c @@ -133,10 +133,8 @@ static inline uint64_t get_HILO(CPUMIPSState *env) static inline target_ulong set_HIT0_LO(CPUMIPSState *env, uint64_t HILO) { - target_ulong tmp; env->active_tc.LO[0] = (int32_t)(HILO & 0xFFFFFFFF); - tmp = env->active_tc.HI[0] = (int32_t)(HILO >> 32); - return tmp; + return env->active_tc.HI[0] = (int32_t)(HILO >> 32); } static inline target_ulong set_HI_LOT0(CPUMIPSState *env, uint64_t HILO) diff --git a/target-s390x/helper.c b/target-s390x/helper.c index 9a744df6c8..54a5177345 100644 --- a/target-s390x/helper.c +++ b/target-s390x/helper.c @@ -70,11 +70,7 @@ void s390x_cpu_timer(void *opaque) S390CPU *cpu_s390x_create(const char *cpu_model, Error **errp) { - S390CPU *cpu; - - cpu = S390_CPU(object_new(TYPE_S390_CPU)); - - return cpu; + return S390_CPU(object_new(TYPE_S390_CPU)); } S390CPU *s390x_new_cpu(const char *cpu_model, int64_t id, Error **errp) diff --git a/target-sparc/cc_helper.c b/target-sparc/cc_helper.c index 44c4409346..a410a0b98f 100644 --- a/target-sparc/cc_helper.c +++ b/target-sparc/cc_helper.c @@ -200,10 +200,7 @@ static uint32_t compute_all_addx_xcc(CPUSPARCState *env) static uint32_t compute_C_addx_xcc(CPUSPARCState *env) { - uint32_t ret; - - ret = get_C_addx_xcc(CC_DST, CC_SRC, CC_SRC2); - return ret; + return get_C_addx_xcc(CC_DST, CC_SRC, CC_SRC2); } #endif @@ -219,10 +216,7 @@ static uint32_t compute_all_addx(CPUSPARCState *env) static uint32_t compute_C_addx(CPUSPARCState *env) { - uint32_t ret; - - ret = get_C_addx_icc(CC_DST, CC_SRC, CC_SRC2); - return ret; + return get_C_addx_icc(CC_DST, CC_SRC, CC_SRC2); } static inline uint32_t get_V_tag_icc(target_ulong src1, target_ulong src2) @@ -365,10 +359,7 @@ static uint32_t compute_all_subx_xcc(CPUSPARCState *env) static uint32_t compute_C_subx_xcc(CPUSPARCState *env) { - uint32_t ret; - - ret = get_C_subx_xcc(CC_DST, CC_SRC, CC_SRC2); - return ret; + return get_C_subx_xcc(CC_DST, CC_SRC, CC_SRC2); } #endif @@ -384,10 +375,7 @@ static uint32_t compute_all_subx(CPUSPARCState *env) static uint32_t compute_C_subx(CPUSPARCState *env) { - uint32_t ret; - - ret = get_C_subx_icc(CC_DST, CC_SRC, CC_SRC2); - return ret; + return get_C_subx_icc(CC_DST, CC_SRC, CC_SRC2); } static uint32_t compute_all_tsub(CPUSPARCState *env) @@ -479,8 +467,5 @@ void helper_compute_psr(CPUSPARCState *env) uint32_t helper_compute_C_icc(CPUSPARCState *env) { - uint32_t ret; - - ret = icc_table[CC_OP].compute_c(env) >> PSR_CARRY_SHIFT; - return ret; + return icc_table[CC_OP].compute_c(env) >> PSR_CARRY_SHIFT; } diff --git a/target-tricore/op_helper.c b/target-tricore/op_helper.c index a73ed530f6..3382a126bd 100644 --- a/target-tricore/op_helper.c +++ b/target-tricore/op_helper.c @@ -2117,7 +2117,7 @@ uint64_t helper_dvadj(uint64_t r1, uint32_t r2) int32_t eq_pos = x_sign & ((r1 >> 32) == r2); int32_t eq_neg = x_sign & ((r1 >> 32) == -r2); uint32_t quotient; - uint64_t ret, remainder; + uint64_t remainder; if ((q_sign & ~eq_neg) | eq_pos) { quotient = (r1 + 1) & 0xffffffff; @@ -2130,8 +2130,7 @@ uint64_t helper_dvadj(uint64_t r1, uint32_t r2) } else { remainder = (r1 & 0xffffffff00000000ull); } - ret = remainder|quotient; - return ret; + return remainder | quotient; } uint64_t helper_dvstep(uint64_t r1, uint32_t r2) @@ -2236,7 +2235,6 @@ uint64_t helper_divide_u(CPUTriCoreState *env, uint32_t r1, uint32_t r2) uint64_t helper_mul_h(uint32_t arg00, uint32_t arg01, uint32_t arg10, uint32_t arg11, uint32_t n) { - uint64_t ret; uint32_t result0, result1; int32_t sc1 = ((arg00 & 0xffff) == 0x8000) && @@ -2253,8 +2251,7 @@ uint64_t helper_mul_h(uint32_t arg00, uint32_t arg01, } else { result0 = (((uint32_t)(arg01 * arg11)) << n); } - ret = (((uint64_t)result1 << 32)) | result0; - return ret; + return (((uint64_t)result1 << 32)) | result0; } uint64_t helper_mulm_h(uint32_t arg00, uint32_t arg01, @@ -2308,11 +2305,9 @@ uint32_t helper_mulr_h(uint32_t arg00, uint32_t arg01, uint32_t helper_crc32(uint32_t arg0, uint32_t arg1) { uint8_t buf[4]; - uint32_t ret; stl_be_p(buf, arg0); - ret = crc32(arg1, buf, 4); - return ret; + return crc32(arg1, buf, 4); } /* context save area (CSA) related helpers */ diff --git a/tests/display-vga-test.c b/tests/display-vga-test.c index 06b244ed9a..91460215cc 100644 --- a/tests/display-vga-test.c +++ b/tests/display-vga-test.c @@ -50,8 +50,6 @@ static void pci_virtio_vga(void) int main(int argc, char **argv) { - int ret; - g_test_init(&argc, &argv, NULL); qtest_add_func("/display/pci/cirrus", pci_cirrus); @@ -62,7 +60,5 @@ int main(int argc, char **argv) #ifdef CONFIG_VIRTIO_VGA qtest_add_func("/display/pci/virtio-vga", pci_virtio_vga); #endif - ret = g_test_run(); - - return ret; + return g_test_run(); } diff --git a/tests/endianness-test.c b/tests/endianness-test.c index 2197972e55..b7a120e0a4 100644 --- a/tests/endianness-test.c +++ b/tests/endianness-test.c @@ -282,7 +282,6 @@ static void test_endianness_combine(gconstpointer data) int main(int argc, char **argv) { const char *arch = qtest_get_arch(); - int ret; int i; g_test_init(&argc, &argv, NULL); @@ -305,7 +304,5 @@ int main(int argc, char **argv) qtest_add_data_func(path, &test_cases[i], test_endianness_combine); } - ret = g_test_run(); - - return ret; + return g_test_run(); } diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c index c1d9b3eb9e..3542ad114e 100644 --- a/tests/i440fx-test.c +++ b/tests/i440fx-test.c @@ -394,7 +394,6 @@ static void request_pflash(FirmwareTestFixture *fixture, int main(int argc, char **argv) { TestData data; - int ret; g_test_init(&argc, &argv, NULL); @@ -405,6 +404,5 @@ int main(int argc, char **argv) add_firmware_test("i440fx/firmware/bios", request_bios); add_firmware_test("i440fx/firmware/pflash", request_pflash); - ret = g_test_run(); - return ret; + return g_test_run(); } diff --git a/tests/intel-hda-test.c b/tests/intel-hda-test.c index b0ca7e042a..b782b2e944 100644 --- a/tests/intel-hda-test.c +++ b/tests/intel-hda-test.c @@ -31,13 +31,9 @@ static void ich9_test(void) int main(int argc, char **argv) { - int ret; - g_test_init(&argc, &argv, NULL); qtest_add_func("/intel-hda/ich6", ich6_test); qtest_add_func("/intel-hda/ich9", ich9_test); - ret = g_test_run(); - - return ret; + return g_test_run(); } diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c index e15b480ab8..0cab38f296 100644 --- a/tests/libqos/virtio-mmio.c +++ b/tests/libqos/virtio-mmio.c @@ -13,6 +13,7 @@ #include "libqos/virtio-mmio.h" #include "libqos/malloc.h" #include "libqos/malloc-generic.h" +#include "standard-headers/linux/virtio_ring.h" static uint8_t qvirtio_mmio_config_readb(QVirtioDevice *d, uint64_t addr) { @@ -135,8 +136,8 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d, vq->free_head = 0; vq->num_free = vq->size; vq->align = dev->page_size; - vq->indirect = (dev->features & QVIRTIO_F_RING_INDIRECT_DESC) != 0; - vq->event = (dev->features & QVIRTIO_F_RING_EVENT_IDX) != 0; + vq->indirect = (dev->features & (1u << VIRTIO_RING_F_INDIRECT_DESC)) != 0; + vq->event = (dev->features & (1u << VIRTIO_RING_F_EVENT_IDX)) != 0; writel(dev->addr + QVIRTIO_MMIO_QUEUE_NUM, vq->size); @@ -153,6 +154,13 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d, return vq; } +static void qvirtio_mmio_virtqueue_cleanup(QVirtQueue *vq, + QGuestAllocator *alloc) +{ + guest_free(alloc, vq->desc); + g_free(vq); +} + static void qvirtio_mmio_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq) { QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d; @@ -175,6 +183,7 @@ const QVirtioBus qvirtio_mmio = { .get_queue_size = qvirtio_mmio_get_queue_size, .set_queue_address = qvirtio_mmio_set_queue_address, .virtqueue_setup = qvirtio_mmio_virtqueue_setup, + .virtqueue_cleanup = qvirtio_mmio_virtqueue_cleanup, .virtqueue_kick = qvirtio_mmio_virtqueue_kick, }; diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index 9d45e2028e..18b92b95dc 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -15,7 +15,10 @@ #include "libqos/pci-pc.h" #include "libqos/malloc.h" #include "libqos/malloc-pc.h" +#include "standard-headers/linux/virtio_ring.h" +#include "standard-headers/linux/virtio_pci.h" +#include "hw/pci/pci.h" #include "hw/pci/pci_regs.h" typedef struct QVirtioPCIForeachData { @@ -101,31 +104,31 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr) static uint32_t qvirtio_pci_get_features(QVirtioDevice *d) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; - return qpci_io_readl(dev->pdev, dev->addr + QVIRTIO_PCI_DEVICE_FEATURES); + return qpci_io_readl(dev->pdev, dev->addr + VIRTIO_PCI_HOST_FEATURES); } static void qvirtio_pci_set_features(QVirtioDevice *d, uint32_t features) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; - qpci_io_writel(dev->pdev, dev->addr + QVIRTIO_PCI_GUEST_FEATURES, features); + qpci_io_writel(dev->pdev, dev->addr + VIRTIO_PCI_GUEST_FEATURES, features); } static uint32_t qvirtio_pci_get_guest_features(QVirtioDevice *d) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; - return qpci_io_readl(dev->pdev, dev->addr + QVIRTIO_PCI_GUEST_FEATURES); + return qpci_io_readl(dev->pdev, dev->addr + VIRTIO_PCI_GUEST_FEATURES); } static uint8_t qvirtio_pci_get_status(QVirtioDevice *d) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; - return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_PCI_DEVICE_STATUS); + return qpci_io_readb(dev->pdev, dev->addr + VIRTIO_PCI_STATUS); } static void qvirtio_pci_set_status(QVirtioDevice *d, uint8_t status) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; - qpci_io_writeb(dev->pdev, dev->addr + QVIRTIO_PCI_DEVICE_STATUS, status); + qpci_io_writeb(dev->pdev, dev->addr + VIRTIO_PCI_STATUS, status); } static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq) @@ -149,7 +152,7 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq) } } } else { - return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_PCI_ISR_STATUS) & 1; + return qpci_io_readb(dev->pdev, dev->addr + VIRTIO_PCI_ISR) & 1; } } @@ -173,26 +176,26 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d) } } } else { - return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_PCI_ISR_STATUS) & 2; + return qpci_io_readb(dev->pdev, dev->addr + VIRTIO_PCI_ISR) & 2; } } static void qvirtio_pci_queue_select(QVirtioDevice *d, uint16_t index) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; - qpci_io_writeb(dev->pdev, dev->addr + QVIRTIO_PCI_QUEUE_SELECT, index); + qpci_io_writeb(dev->pdev, dev->addr + VIRTIO_PCI_QUEUE_SEL, index); } static uint16_t qvirtio_pci_get_queue_size(QVirtioDevice *d) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; - return qpci_io_readw(dev->pdev, dev->addr + QVIRTIO_PCI_QUEUE_SIZE); + return qpci_io_readw(dev->pdev, dev->addr + VIRTIO_PCI_QUEUE_NUM); } static void qvirtio_pci_set_queue_address(QVirtioDevice *d, uint32_t pfn) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; - qpci_io_writel(dev->pdev, dev->addr + QVIRTIO_PCI_QUEUE_ADDRESS, pfn); + qpci_io_writel(dev->pdev, dev->addr + VIRTIO_PCI_QUEUE_PFN, pfn); } static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, @@ -210,9 +213,9 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, vqpci->vq.size = qvirtio_pci_get_queue_size(d); vqpci->vq.free_head = 0; vqpci->vq.num_free = vqpci->vq.size; - vqpci->vq.align = QVIRTIO_PCI_ALIGN; - vqpci->vq.indirect = (feat & QVIRTIO_F_RING_INDIRECT_DESC) != 0; - vqpci->vq.event = (feat & QVIRTIO_F_RING_EVENT_IDX) != 0; + vqpci->vq.align = VIRTIO_PCI_VRING_ALIGN; + vqpci->vq.indirect = (feat & (1u << VIRTIO_RING_F_INDIRECT_DESC)) != 0; + vqpci->vq.event = (feat & (1u << VIRTIO_RING_F_EVENT_IDX)) != 0; vqpci->msix_entry = -1; vqpci->msix_addr = 0; @@ -224,17 +227,27 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d, /* Check power of 2 */ g_assert_cmpint(vqpci->vq.size & (vqpci->vq.size - 1), ==, 0); - addr = guest_alloc(alloc, qvring_size(vqpci->vq.size, QVIRTIO_PCI_ALIGN)); + addr = guest_alloc(alloc, qvring_size(vqpci->vq.size, + VIRTIO_PCI_VRING_ALIGN)); qvring_init(alloc, &vqpci->vq, addr); - qvirtio_pci_set_queue_address(d, vqpci->vq.desc / QVIRTIO_PCI_ALIGN); + qvirtio_pci_set_queue_address(d, vqpci->vq.desc / VIRTIO_PCI_VRING_ALIGN); return &vqpci->vq; } +static void qvirtio_pci_virtqueue_cleanup(QVirtQueue *vq, + QGuestAllocator *alloc) +{ + QVirtQueuePCI *vqpci = container_of(vq, QVirtQueuePCI, vq); + + guest_free(alloc, vq->desc); + g_free(vqpci); +} + static void qvirtio_pci_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; - qpci_io_writew(dev->pdev, dev->addr + QVIRTIO_PCI_QUEUE_NOTIFY, vq->index); + qpci_io_writew(dev->pdev, dev->addr + VIRTIO_PCI_QUEUE_NOTIFY, vq->index); } const QVirtioBus qvirtio_pci = { @@ -253,6 +266,7 @@ const QVirtioBus qvirtio_pci = { .get_queue_size = qvirtio_pci_get_queue_size, .set_queue_address = qvirtio_pci_set_queue_address, .virtqueue_setup = qvirtio_pci_virtqueue_setup, + .virtqueue_cleanup = qvirtio_pci_virtqueue_cleanup, .virtqueue_kick = qvirtio_pci_virtqueue_kick, }; @@ -263,7 +277,7 @@ void qvirtio_pci_foreach(QPCIBus *bus, uint16_t device_type, .device_type = device_type, .user_data = data }; - qpci_device_foreach(bus, QVIRTIO_VENDOR_ID, -1, + qpci_device_foreach(bus, PCI_VENDOR_ID_REDHAT_QUMRANET, -1, qvirtio_pci_foreach_callback, &d); } @@ -314,9 +328,9 @@ void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci, control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT); qvirtio_pci_queue_select(&d->vdev, vqpci->vq.index); - qpci_io_writew(d->pdev, d->addr + QVIRTIO_PCI_MSIX_QUEUE_VECTOR, entry); - vector = qpci_io_readw(d->pdev, d->addr + QVIRTIO_PCI_MSIX_QUEUE_VECTOR); - g_assert_cmphex(vector, !=, QVIRTIO_MSI_NO_VECTOR); + qpci_io_writew(d->pdev, d->addr + VIRTIO_MSI_QUEUE_VECTOR, entry); + vector = qpci_io_readw(d->pdev, d->addr + VIRTIO_MSI_QUEUE_VECTOR); + g_assert_cmphex(vector, !=, VIRTIO_MSI_NO_VECTOR); } void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d, @@ -346,7 +360,7 @@ void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d, qpci_io_writel(d->pdev, addr + PCI_MSIX_ENTRY_VECTOR_CTRL, control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT); - qpci_io_writew(d->pdev, d->addr + QVIRTIO_PCI_MSIX_CONF_VECTOR, entry); - vector = qpci_io_readw(d->pdev, d->addr + QVIRTIO_PCI_MSIX_CONF_VECTOR); - g_assert_cmphex(vector, !=, QVIRTIO_MSI_NO_VECTOR); + qpci_io_writew(d->pdev, d->addr + VIRTIO_MSI_CONFIG_VECTOR, entry); + vector = qpci_io_readw(d->pdev, d->addr + VIRTIO_MSI_CONFIG_VECTOR); + g_assert_cmphex(vector, !=, VIRTIO_MSI_NO_VECTOR); } diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 8f0e52ad47..efcac2d3de 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -13,23 +13,6 @@ #include "libqos/virtio.h" #include "libqos/pci.h" -#define QVIRTIO_PCI_DEVICE_FEATURES 0x00 -#define QVIRTIO_PCI_GUEST_FEATURES 0x04 -#define QVIRTIO_PCI_QUEUE_ADDRESS 0x08 -#define QVIRTIO_PCI_QUEUE_SIZE 0x0C -#define QVIRTIO_PCI_QUEUE_SELECT 0x0E -#define QVIRTIO_PCI_QUEUE_NOTIFY 0x10 -#define QVIRTIO_PCI_DEVICE_STATUS 0x12 -#define QVIRTIO_PCI_ISR_STATUS 0x13 -#define QVIRTIO_PCI_MSIX_CONF_VECTOR 0x14 -#define QVIRTIO_PCI_MSIX_QUEUE_VECTOR 0x16 -#define QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX 0x18 -#define QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX 0x14 - -#define QVIRTIO_PCI_ALIGN 4096 - -#define QVIRTIO_MSI_NO_VECTOR 0xFFFF - typedef struct QVirtioPCIDevice { QVirtioDevice vdev; QPCIDevice *pdev; diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index d792635340..d8c2970de7 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -10,6 +10,8 @@ #include "qemu/osdep.h" #include "libqtest.h" #include "libqos/virtio.h" +#include "standard-headers/linux/virtio_config.h" +#include "standard-headers/linux/virtio_ring.h" uint8_t qvirtio_config_readb(const QVirtioBus *bus, QVirtioDevice *d, uint64_t addr) @@ -52,30 +54,36 @@ QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d, return bus->virtqueue_setup(d, alloc, index); } +void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq, + QGuestAllocator *alloc) +{ + return bus->virtqueue_cleanup(vq, alloc); +} + void qvirtio_reset(const QVirtioBus *bus, QVirtioDevice *d) { - bus->set_status(d, QVIRTIO_RESET); - g_assert_cmphex(bus->get_status(d), ==, QVIRTIO_RESET); + bus->set_status(d, 0); + g_assert_cmphex(bus->get_status(d), ==, 0); } void qvirtio_set_acknowledge(const QVirtioBus *bus, QVirtioDevice *d) { - bus->set_status(d, bus->get_status(d) | QVIRTIO_ACKNOWLEDGE); - g_assert_cmphex(bus->get_status(d), ==, QVIRTIO_ACKNOWLEDGE); + bus->set_status(d, bus->get_status(d) | VIRTIO_CONFIG_S_ACKNOWLEDGE); + g_assert_cmphex(bus->get_status(d), ==, VIRTIO_CONFIG_S_ACKNOWLEDGE); } void qvirtio_set_driver(const QVirtioBus *bus, QVirtioDevice *d) { - bus->set_status(d, bus->get_status(d) | QVIRTIO_DRIVER); + bus->set_status(d, bus->get_status(d) | VIRTIO_CONFIG_S_DRIVER); g_assert_cmphex(bus->get_status(d), ==, - QVIRTIO_DRIVER | QVIRTIO_ACKNOWLEDGE); + VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_ACKNOWLEDGE); } void qvirtio_set_driver_ok(const QVirtioBus *bus, QVirtioDevice *d) { - bus->set_status(d, bus->get_status(d) | QVIRTIO_DRIVER_OK); - g_assert_cmphex(bus->get_status(d), ==, - QVIRTIO_DRIVER_OK | QVIRTIO_DRIVER | QVIRTIO_ACKNOWLEDGE); + bus->set_status(d, bus->get_status(d) | VIRTIO_CONFIG_S_DRIVER_OK); + g_assert_cmphex(bus->get_status(d), ==, VIRTIO_CONFIG_S_DRIVER_OK | + VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_ACKNOWLEDGE); } void qvirtio_wait_queue_isr(const QVirtioBus *bus, QVirtioDevice *d, @@ -133,7 +141,7 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr) int i; vq->desc = addr; - vq->avail = vq->desc + vq->size*sizeof(QVRingDesc); + vq->avail = vq->desc + vq->size * sizeof(struct vring_desc); vq->used = (uint64_t)((vq->avail + sizeof(uint16_t) * (3 + vq->size) + vq->align - 1) & ~(vq->align - 1)); @@ -154,7 +162,7 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr) /* vq->used->flags */ writew(vq->used, 0); /* vq->used->avail_event */ - writew(vq->used+2+(sizeof(struct QVRingUsedElem)*vq->size), 0); + writew(vq->used + 2 + sizeof(struct vring_used_elem) * vq->size, 0); } QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, @@ -165,13 +173,13 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, indirect->index = 0; indirect->elem = elem; - indirect->desc = guest_alloc(alloc, sizeof(QVRingDesc)*elem); + indirect->desc = guest_alloc(alloc, sizeof(struct vring_desc) * elem); for (i = 0; i < elem - 1; ++i) { /* indirect->desc[i].addr */ writeq(indirect->desc + (16 * i), 0); /* indirect->desc[i].flags */ - writew(indirect->desc + (16 * i) + 12, QVRING_DESC_F_NEXT); + writew(indirect->desc + (16 * i) + 12, VRING_DESC_F_NEXT); /* indirect->desc[i].next */ writew(indirect->desc + (16 * i) + 14, i + 1); } @@ -189,7 +197,7 @@ void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data, flags = readw(indirect->desc + (16 * indirect->index) + 12); if (write) { - flags |= QVRING_DESC_F_WRITE; + flags |= VRING_DESC_F_WRITE; } /* indirect->desc[indirect->index].addr */ @@ -209,11 +217,11 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write, vq->num_free--; if (write) { - flags |= QVRING_DESC_F_WRITE; + flags |= VRING_DESC_F_WRITE; } if (next) { - flags |= QVRING_DESC_F_NEXT; + flags |= VRING_DESC_F_NEXT; } /* vq->desc[vq->free_head].addr */ @@ -238,9 +246,9 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect) writeq(vq->desc + (16 * vq->free_head), indirect->desc); /* vq->desc[vq->free_head].len */ writel(vq->desc + (16 * vq->free_head) + 8, - sizeof(QVRingDesc) * indirect->elem); + sizeof(struct vring_desc) * indirect->elem); /* vq->desc[vq->free_head].flags */ - writew(vq->desc + (16 * vq->free_head) + 12, QVRING_DESC_F_INDIRECT); + writew(vq->desc + (16 * vq->free_head) + 12, VRING_DESC_F_INDIRECT); return vq->free_head++; /* Return and increase, in this order */ } @@ -263,10 +271,10 @@ void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq, /* Must read after idx is updated */ flags = readw(vq->avail); avail_event = readw(vq->used + 4 + - (sizeof(struct QVRingUsedElem) * vq->size)); + sizeof(struct vring_used_elem) * vq->size); /* < 1 because we add elements to avail queue one by one */ - if ((flags & QVRING_USED_F_NO_NOTIFY) == 0 && + if ((flags & VRING_USED_F_NO_NOTIFY) == 0 && (!vq->event || (uint16_t)(idx-avail_event) < 1)) { bus->virtqueue_kick(d, vq); } diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 01012787b8..0250842bf2 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -11,78 +11,19 @@ #define LIBQOS_VIRTIO_H #include "libqos/malloc.h" +#include "standard-headers/linux/virtio_ring.h" -#define QVIRTIO_VENDOR_ID 0x1AF4 - -#define QVIRTIO_RESET 0x0 -#define QVIRTIO_ACKNOWLEDGE 0x1 -#define QVIRTIO_DRIVER 0x2 -#define QVIRTIO_DRIVER_OK 0x4 - -#define QVIRTIO_NET_DEVICE_ID 0x1 -#define QVIRTIO_BLK_DEVICE_ID 0x2 -#define QVIRTIO_CONSOLE_DEVICE_ID 0x3 -#define QVIRTIO_RNG_DEVICE_ID 0x4 -#define QVIRTIO_BALLOON_DEVICE_ID 0x5 -#define QVIRTIO_RPMSG_DEVICE_ID 0x7 -#define QVIRTIO_SCSI_DEVICE_ID 0x8 -#define QVIRTIO_9P_DEVICE_ID 0x9 - -#define QVIRTIO_F_NOTIFY_ON_EMPTY 0x01000000 -#define QVIRTIO_F_ANY_LAYOUT 0x08000000 -#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000 -#define QVIRTIO_F_RING_EVENT_IDX 0x20000000 #define QVIRTIO_F_BAD_FEATURE 0x40000000 -#define QVRING_DESC_F_NEXT 0x1 -#define QVRING_DESC_F_WRITE 0x2 -#define QVRING_DESC_F_INDIRECT 0x4 - -#define QVIRTIO_F_NOTIFY_ON_EMPTY 0x01000000 -#define QVIRTIO_F_ANY_LAYOUT 0x08000000 -#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000 -#define QVIRTIO_F_RING_EVENT_IDX 0x20000000 -#define QVIRTIO_F_BAD_FEATURE 0x40000000 - -#define QVRING_AVAIL_F_NO_INTERRUPT 1 - -#define QVRING_USED_F_NO_NOTIFY 1 - typedef struct QVirtioDevice { /* Device type */ uint16_t device_type; } QVirtioDevice; -typedef struct QVRingDesc { - uint64_t addr; - uint32_t len; - uint16_t flags; - uint16_t next; -} QVRingDesc; - -typedef struct QVRingAvail { - uint16_t flags; - uint16_t idx; - uint16_t ring[0]; /* This is an array of uint16_t */ - uint16_t used_event; -} QVRingAvail; - -typedef struct QVRingUsedElem { - uint32_t id; - uint32_t len; -} QVRingUsedElem; - -typedef struct QVRingUsed { - uint16_t flags; - uint16_t idx; - QVRingUsedElem ring[0]; /* This is an array of QVRingUsedElem structs */ - uint16_t avail_event; -} QVRingUsed; - typedef struct QVirtQueue { - uint64_t desc; /* This points to an array of QVRingDesc */ - uint64_t avail; /* This points to a QVRingAvail */ - uint64_t used; /* This points to a QVRingDesc */ + uint64_t desc; /* This points to an array of struct vring_desc */ + uint64_t avail; /* This points to a struct vring_avail */ + uint64_t used; /* This points to a struct vring_desc */ uint16_t index; uint32_t size; uint32_t free_head; @@ -93,7 +34,7 @@ typedef struct QVirtQueue { } QVirtQueue; typedef struct QVRingIndirectDesc { - uint64_t desc; /* This points to an array fo QVRingDesc */ + uint64_t desc; /* This points to an array fo struct vring_desc */ uint16_t index; uint16_t elem; } QVRingIndirectDesc; @@ -138,15 +79,18 @@ typedef struct QVirtioBus { QVirtQueue *(*virtqueue_setup)(QVirtioDevice *d, QGuestAllocator *alloc, uint16_t index); + /* Free virtqueue resources */ + void (*virtqueue_cleanup)(QVirtQueue *vq, QGuestAllocator *alloc); + /* Notify changes in virtqueue */ void (*virtqueue_kick)(QVirtioDevice *d, QVirtQueue *vq); } QVirtioBus; static inline uint32_t qvring_size(uint32_t num, uint32_t align) { - return ((sizeof(struct QVRingDesc) * num + sizeof(uint16_t) * (3 + num) + return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num) + align - 1) & ~(align - 1)) - + sizeof(uint16_t) * 3 + sizeof(struct QVRingUsedElem) * num; + + sizeof(uint16_t) * 3 + sizeof(struct vring_used_elem) * num; } uint8_t qvirtio_config_readb(const QVirtioBus *bus, QVirtioDevice *d, @@ -177,6 +121,8 @@ void qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d, gint64 timeout_us); QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d, QGuestAllocator *alloc, uint16_t index); +void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq, + QGuestAllocator *alloc); void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr); QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d, diff --git a/tests/test-filter-redirector.c b/tests/test-filter-redirector.c index 280e4b68ab..c63b68f03a 100644 --- a/tests/test-filter-redirector.c +++ b/tests/test-filter-redirector.c @@ -209,12 +209,8 @@ static void test_redirector_rx(void) int main(int argc, char **argv) { - int ret; - g_test_init(&argc, &argv, NULL); qtest_add_func("/netfilter/redirector_tx", test_redirector_tx); qtest_add_func("/netfilter/redirector_rx", test_redirector_rx); - ret = g_test_run(); - - return ret; + return g_test_run(); } diff --git a/tests/test-logging.c b/tests/test-logging.c index 5ef5bb887d..440e75f5db 100644 --- a/tests/test-logging.c +++ b/tests/test-logging.c @@ -27,11 +27,14 @@ #include "qemu/osdep.h" #include "qemu-common.h" -#include "include/qemu/log.h" +#include "qapi/error.h" +#include "qemu/log.h" static void test_parse_range(void) { - qemu_set_dfilter_ranges("0x1000+0x100"); + Error *err = NULL; + + qemu_set_dfilter_ranges("0x1000+0x100", &error_abort); g_assert_false(qemu_log_in_addr_range(0xfff)); g_assert(qemu_log_in_addr_range(0x1000)); @@ -39,102 +42,57 @@ static void test_parse_range(void) g_assert(qemu_log_in_addr_range(0x10ff)); g_assert_false(qemu_log_in_addr_range(0x1100)); - qemu_set_dfilter_ranges("0x1000-0x100"); + qemu_set_dfilter_ranges("0x1000-0x100", &error_abort); g_assert_false(qemu_log_in_addr_range(0x1001)); g_assert(qemu_log_in_addr_range(0x1000)); g_assert(qemu_log_in_addr_range(0x0f01)); g_assert_false(qemu_log_in_addr_range(0x0f00)); - qemu_set_dfilter_ranges("0x1000..0x1100"); + qemu_set_dfilter_ranges("0x1000..0x1100", &error_abort); g_assert_false(qemu_log_in_addr_range(0xfff)); g_assert(qemu_log_in_addr_range(0x1000)); g_assert(qemu_log_in_addr_range(0x1100)); g_assert_false(qemu_log_in_addr_range(0x1101)); - qemu_set_dfilter_ranges("0x1000..0x1000"); + qemu_set_dfilter_ranges("0x1000..0x1000", &error_abort); g_assert_false(qemu_log_in_addr_range(0xfff)); g_assert(qemu_log_in_addr_range(0x1000)); g_assert_false(qemu_log_in_addr_range(0x1001)); - qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100"); + qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100", + &error_abort); g_assert(qemu_log_in_addr_range(0x1050)); g_assert(qemu_log_in_addr_range(0x2050)); g_assert(qemu_log_in_addr_range(0x3050)); -} -#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS -static void test_parse_invalid_range_subprocess(void) -{ - qemu_set_dfilter_ranges("0x1000+onehundred"); -} -static void test_parse_invalid_range(void) -{ - g_test_trap_subprocess("/logging/parse_invalid_range/subprocess", 0, 0); - g_test_trap_assert_failed(); - g_test_trap_assert_stdout(""); - g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+onehundred\n"); -} -static void test_parse_zero_range_subprocess(void) -{ - qemu_set_dfilter_ranges("0x1000+0"); -} -static void test_parse_zero_range(void) -{ - g_test_trap_subprocess("/logging/parse_zero_range/subprocess", 0, 0); - g_test_trap_assert_failed(); - g_test_trap_assert_stdout(""); - g_test_trap_assert_stderr("*Failed to parse range in: 0x1000+0\n"); -} + qemu_set_dfilter_ranges("0x1000+onehundred", &err); + error_free_or_abort(&err); -/* As the only real failure from a bad log filename path spec is - * reporting to the user we have to use the g_test_trap_subprocess - * mechanism and check no errors reported on stderr. - */ -static void test_parse_path_subprocess(void) -{ - /* All these should work without issue */ - qemu_set_log_filename("/tmp/qemu.log"); - qemu_set_log_filename("/tmp/qemu-%d.log"); - qemu_set_log_filename("/tmp/qemu.log.%d"); + qemu_set_dfilter_ranges("0x1000+0", &err); + error_free_or_abort(&err); } + static void test_parse_path(void) { - g_test_trap_subprocess ("/logging/parse_path/subprocess", 0, 0); - g_test_trap_assert_passed(); - g_test_trap_assert_stdout(""); - g_test_trap_assert_stderr(""); -} -static void test_parse_invalid_path_subprocess(void) -{ - qemu_set_log_filename("/tmp/qemu-%d%d.log"); -} -static void test_parse_invalid_path(void) -{ - g_test_trap_subprocess ("/logging/parse_invalid_path/subprocess", 0, 0); - g_test_trap_assert_passed(); - g_test_trap_assert_stdout(""); - g_test_trap_assert_stderr("Bad logfile format: /tmp/qemu-%d%d.log\n"); + Error *err = NULL; + + qemu_set_log_filename("/tmp/qemu.log", &error_abort); + qemu_set_log_filename("/tmp/qemu-%d.log", &error_abort); + qemu_set_log_filename("/tmp/qemu.log.%d", &error_abort); + + qemu_set_log_filename("/tmp/qemu-%d%d.log", &err); + error_free_or_abort(&err); } -#endif /* CONFIG_HAS_GLIB_SUBPROCESS_TESTS */ int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/logging/parse_range", test_parse_range); -#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS - g_test_add_func("/logging/parse_invalid_range/subprocess", test_parse_invalid_range_subprocess); - g_test_add_func("/logging/parse_invalid_range", test_parse_invalid_range); - g_test_add_func("/logging/parse_zero_range/subprocess", test_parse_zero_range_subprocess); - g_test_add_func("/logging/parse_zero_range", test_parse_zero_range); g_test_add_func("/logging/parse_path", test_parse_path); - g_test_add_func("/logging/parse_path/subprocess", test_parse_path_subprocess); - g_test_add_func("/logging/parse_invalid_path", test_parse_invalid_path); - g_test_add_func("/logging/parse_invalid_path/subprocess", test_parse_invalid_path_subprocess); -#endif return g_test_run(); } diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index 8272ba8c42..811cf756c8 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -18,25 +18,11 @@ #include "libqos/malloc-pc.h" #include "libqos/malloc-generic.h" #include "qemu/bswap.h" - -#define QVIRTIO_BLK_F_BARRIER 0x00000001 -#define QVIRTIO_BLK_F_SIZE_MAX 0x00000002 -#define QVIRTIO_BLK_F_SEG_MAX 0x00000004 -#define QVIRTIO_BLK_F_GEOMETRY 0x00000010 -#define QVIRTIO_BLK_F_RO 0x00000020 -#define QVIRTIO_BLK_F_BLK_SIZE 0x00000040 -#define QVIRTIO_BLK_F_SCSI 0x00000080 -#define QVIRTIO_BLK_F_WCE 0x00000200 -#define QVIRTIO_BLK_F_TOPOLOGY 0x00000400 -#define QVIRTIO_BLK_F_CONFIG_WCE 0x00000800 - -#define QVIRTIO_BLK_T_IN 0 -#define QVIRTIO_BLK_T_OUT 1 -#define QVIRTIO_BLK_T_SCSI_CMD 2 -#define QVIRTIO_BLK_T_SCSI_CMD_OUT 3 -#define QVIRTIO_BLK_T_FLUSH 4 -#define QVIRTIO_BLK_T_FLUSH_OUT 5 -#define QVIRTIO_BLK_T_GET_ID 8 +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_config.h" +#include "standard-headers/linux/virtio_ring.h" +#include "standard-headers/linux/virtio_blk.h" +#include "standard-headers/linux/virtio_pci.h" #define TEST_IMAGE_SIZE (64 * 1024 * 1024) #define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000) @@ -118,9 +104,9 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot) { QVirtioPCIDevice *dev; - dev = qvirtio_pci_device_find(bus, QVIRTIO_BLK_DEVICE_ID); + dev = qvirtio_pci_device_find(bus, VIRTIO_ID_BLOCK); g_assert(dev != NULL); - g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_BLK_DEVICE_ID); + g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); g_assert_cmphex(dev->pdev->devfn, ==, ((slot << 3) | PCI_FN)); qvirtio_pci_device_enable(dev); @@ -181,15 +167,16 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, features = qvirtio_get_features(bus, dev); features = features & ~(QVIRTIO_F_BAD_FEATURE | - QVIRTIO_F_RING_INDIRECT_DESC | QVIRTIO_F_RING_EVENT_IDX | - QVIRTIO_BLK_F_SCSI); + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_RING_F_EVENT_IDX) | + (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(bus, dev, features); qvirtio_set_driver_ok(bus, dev); /* Write and read with 3 descriptor layout */ /* Write request */ - req.type = QVIRTIO_BLK_T_OUT; + req.type = VIRTIO_BLK_T_OUT; req.ioprio = 1; req.sector = 0; req.data = g_malloc0(512); @@ -212,7 +199,7 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, guest_free(alloc, req_addr); /* Read request */ - req.type = QVIRTIO_BLK_T_IN; + req.type = VIRTIO_BLK_T_IN; req.ioprio = 1; req.sector = 0; req.data = g_malloc0(512); @@ -238,10 +225,10 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, guest_free(alloc, req_addr); - if (features & QVIRTIO_F_ANY_LAYOUT) { + if (features & (1u << VIRTIO_F_ANY_LAYOUT)) { /* Write and read with 2 descriptor layout */ /* Write request */ - req.type = QVIRTIO_BLK_T_OUT; + req.type = VIRTIO_BLK_T_OUT; req.ioprio = 1; req.sector = 1; req.data = g_malloc0(512); @@ -262,7 +249,7 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev, guest_free(alloc, req_addr); /* Read request */ - req.type = QVIRTIO_BLK_T_IN; + req.type = VIRTIO_BLK_T_IN; req.ioprio = 1; req.sector = 1; req.data = g_malloc0(512); @@ -305,13 +292,13 @@ static void pci_basic(void) alloc, 0); /* MSI-X is not enabled */ - addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX; + addr = dev->addr + VIRTIO_PCI_CONFIG_OFF(false); test_basic(&qvirtio_pci, &dev->vdev, alloc, &vqpci->vq, (uint64_t)(uintptr_t)addr); /* End test */ - guest_free(alloc, vqpci->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc); pc_alloc_uninit(alloc); qvirtio_pci_device_disable(dev); g_free(dev); @@ -340,16 +327,17 @@ static void pci_indirect(void) dev = virtio_blk_pci_init(bus, PCI_SLOT); /* MSI-X is not enabled */ - addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX; + addr = dev->addr + VIRTIO_PCI_CONFIG_OFF(false); capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)(uintptr_t)addr); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); features = qvirtio_get_features(&qvirtio_pci, &dev->vdev); - g_assert_cmphex(features & QVIRTIO_F_RING_INDIRECT_DESC, !=, 0); - features = features & ~(QVIRTIO_F_BAD_FEATURE | QVIRTIO_F_RING_EVENT_IDX | - QVIRTIO_BLK_F_SCSI); + g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=, 0); + features = features & ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_EVENT_IDX) | + (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(&qvirtio_pci, &dev->vdev, features); alloc = pc_alloc_init(); @@ -358,7 +346,7 @@ static void pci_indirect(void) qvirtio_set_driver_ok(&qvirtio_pci, &dev->vdev); /* Write request */ - req.type = QVIRTIO_BLK_T_OUT; + req.type = VIRTIO_BLK_T_OUT; req.ioprio = 1; req.sector = 0; req.data = g_malloc0(512); @@ -383,7 +371,7 @@ static void pci_indirect(void) guest_free(alloc, req_addr); /* Read request */ - req.type = QVIRTIO_BLK_T_IN; + req.type = VIRTIO_BLK_T_IN; req.ioprio = 1; req.sector = 0; req.data = g_malloc0(512); @@ -413,7 +401,7 @@ static void pci_indirect(void) guest_free(alloc, req_addr); /* End test */ - guest_free(alloc, vqpci->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc); pc_alloc_uninit(alloc); qvirtio_pci_device_disable(dev); g_free(dev); @@ -434,7 +422,7 @@ static void pci_config(void) dev = virtio_blk_pci_init(bus, PCI_SLOT); /* MSI-X is not enabled */ - addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX; + addr = dev->addr + VIRTIO_PCI_CONFIG_OFF(false); capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)(uintptr_t)addr); @@ -481,7 +469,7 @@ static void pci_msix(void) qvirtio_pci_set_msix_configuration_vector(dev, alloc, 0); /* MSI-X is enabled */ - addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX; + addr = dev->addr + VIRTIO_PCI_CONFIG_OFF(true); capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)(uintptr_t)addr); @@ -489,8 +477,9 @@ static void pci_msix(void) features = qvirtio_get_features(&qvirtio_pci, &dev->vdev); features = features & ~(QVIRTIO_F_BAD_FEATURE | - QVIRTIO_F_RING_INDIRECT_DESC | - QVIRTIO_F_RING_EVENT_IDX | QVIRTIO_BLK_F_SCSI); + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_RING_F_EVENT_IDX) | + (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(&qvirtio_pci, &dev->vdev, features); vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev, @@ -509,7 +498,7 @@ static void pci_msix(void) g_assert_cmpint(capacity, ==, n_size / 512); /* Write request */ - req.type = QVIRTIO_BLK_T_OUT; + req.type = VIRTIO_BLK_T_OUT; req.ioprio = 1; req.sector = 0; req.data = g_malloc0(512); @@ -533,7 +522,7 @@ static void pci_msix(void) guest_free(alloc, req_addr); /* Read request */ - req.type = QVIRTIO_BLK_T_IN; + req.type = VIRTIO_BLK_T_IN; req.ioprio = 1; req.sector = 0; req.data = g_malloc0(512); @@ -563,7 +552,7 @@ static void pci_msix(void) guest_free(alloc, req_addr); /* End test */ - guest_free(alloc, vqpci->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc); pc_alloc_uninit(alloc); qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); @@ -596,7 +585,7 @@ static void pci_idx(void) qvirtio_pci_set_msix_configuration_vector(dev, alloc, 0); /* MSI-X is enabled */ - addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX; + addr = dev->addr + VIRTIO_PCI_CONFIG_OFF(true); capacity = qvirtio_config_readq(&qvirtio_pci, &dev->vdev, (uint64_t)(uintptr_t)addr); @@ -604,8 +593,9 @@ static void pci_idx(void) features = qvirtio_get_features(&qvirtio_pci, &dev->vdev); features = features & ~(QVIRTIO_F_BAD_FEATURE | - QVIRTIO_F_RING_INDIRECT_DESC | - QVIRTIO_F_NOTIFY_ON_EMPTY | QVIRTIO_BLK_F_SCSI); + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_F_NOTIFY_ON_EMPTY) | + (1u << VIRTIO_BLK_F_SCSI)); qvirtio_set_features(&qvirtio_pci, &dev->vdev, features); vqpci = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev, @@ -615,7 +605,7 @@ static void pci_idx(void) qvirtio_set_driver_ok(&qvirtio_pci, &dev->vdev); /* Write request */ - req.type = QVIRTIO_BLK_T_OUT; + req.type = VIRTIO_BLK_T_OUT; req.ioprio = 1; req.sector = 0; req.data = g_malloc0(512); @@ -634,7 +624,7 @@ static void pci_idx(void) QVIRTIO_BLK_TIMEOUT_US); /* Write request */ - req.type = QVIRTIO_BLK_T_OUT; + req.type = VIRTIO_BLK_T_OUT; req.ioprio = 1; req.sector = 1; req.data = g_malloc0(512); @@ -660,7 +650,7 @@ static void pci_idx(void) guest_free(alloc, req_addr); /* Read request */ - req.type = QVIRTIO_BLK_T_IN; + req.type = VIRTIO_BLK_T_IN; req.ioprio = 1; req.sector = 1; req.data = g_malloc0(512); @@ -689,7 +679,7 @@ static void pci_idx(void) guest_free(alloc, req_addr); /* End test */ - guest_free(alloc, vqpci->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc); pc_alloc_uninit(alloc); qpci_msix_disable(dev->pdev); qvirtio_pci_device_disable(dev); @@ -732,7 +722,7 @@ static void mmio_basic(void) dev = qvirtio_mmio_init_device(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE); g_assert(dev != NULL); - g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_BLK_DEVICE_ID); + g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); qvirtio_reset(&qvirtio_mmio, &dev->vdev); qvirtio_set_acknowledge(&qvirtio_mmio, &dev->vdev); @@ -755,7 +745,7 @@ static void mmio_basic(void) g_assert_cmpint(capacity, ==, n_size / 512); /* End test */ - guest_free(alloc, vq->desc); + qvirtqueue_cleanup(&qvirtio_mmio, vq, alloc); generic_alloc_uninit(alloc); g_free(dev); test_end(); @@ -763,7 +753,6 @@ static void mmio_basic(void) int main(int argc, char **argv) { - int ret; const char *arch = qtest_get_arch(); g_test_init(&argc, &argv, NULL); @@ -779,7 +768,5 @@ int main(int argc, char **argv) qtest_add_func("/virtio/blk/mmio/basic", mmio_basic); } - ret = g_test_run(); - - return ret; + return g_test_run(); } diff --git a/tests/virtio-console-test.c b/tests/virtio-console-test.c index 6d6414dc8e..1c3de072f4 100644 --- a/tests/virtio-console-test.c +++ b/tests/virtio-console-test.c @@ -27,13 +27,9 @@ static void serialport_pci_nop(void) int main(int argc, char **argv) { - int ret; - g_test_init(&argc, &argv, NULL); qtest_add_func("/virtio/console/pci/nop", console_pci_nop); qtest_add_func("/virtio/serialport/pci/nop", serialport_pci_nop); - ret = g_test_run(); - - return ret; + return g_test_run(); } diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c index e5c144818e..a34a9392e3 100644 --- a/tests/virtio-net-test.c +++ b/tests/virtio-net-test.c @@ -20,6 +20,8 @@ #include "libqos/malloc-generic.h" #include "qemu/bswap.h" #include "hw/virtio/virtio-net.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_ring.h" #define PCI_SLOT_HP 0x06 #define PCI_SLOT 0x04 @@ -39,9 +41,9 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot) { QVirtioPCIDevice *dev; - dev = qvirtio_pci_device_find(bus, QVIRTIO_NET_DEVICE_ID); + dev = qvirtio_pci_device_find(bus, VIRTIO_ID_NET); g_assert(dev != NULL); - g_assert_cmphex(dev->vdev.device_type, ==, QVIRTIO_NET_DEVICE_ID); + g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_NET); qvirtio_pci_device_enable(dev); qvirtio_reset(&qvirtio_pci, &dev->vdev); @@ -69,8 +71,8 @@ static void driver_init(const QVirtioBus *bus, QVirtioDevice *dev) features = qvirtio_get_features(bus, dev); features = features & ~(QVIRTIO_F_BAD_FEATURE | - QVIRTIO_F_RING_INDIRECT_DESC | - QVIRTIO_F_RING_EVENT_IDX); + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_RING_F_EVENT_IDX)); qvirtio_set_features(bus, dev, features); qvirtio_set_driver_ok(bus, dev); @@ -227,7 +229,7 @@ static void pci_basic(gconstpointer data) /* End test */ close(sv[0]); - guest_free(alloc, tx->vq.desc); + qvirtqueue_cleanup(&qvirtio_pci, &tx->vq, alloc); pc_alloc_uninit(alloc); qvirtio_pci_device_disable(dev); g_free(dev); @@ -248,8 +250,6 @@ static void hotplug(void) int main(int argc, char **argv) { - int ret; - g_test_init(&argc, &argv, NULL); #ifndef _WIN32 qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic); @@ -258,7 +258,5 @@ int main(int argc, char **argv) #endif qtest_add_func("/virtio/net/pci/hotplug", hotplug); - ret = g_test_run(); - - return ret; + return g_test_run(); } diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 5f1a8aefeb..f1489e68a0 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -17,11 +17,13 @@ #include "libqos/malloc.h" #include "libqos/malloc-pc.h" #include "libqos/malloc-generic.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_pci.h" +#include "standard-headers/linux/virtio_scsi.h" #define PCI_SLOT 0x02 #define PCI_FN 0x00 #define QVIRTIO_SCSI_TIMEOUT_US (1 * 1000 * 1000) -#define CDB_SIZE 32 #define MAX_NUM_QUEUES 64 @@ -33,24 +35,6 @@ typedef struct { QVirtQueue *vq[MAX_NUM_QUEUES + 2]; } QVirtIOSCSI; -typedef struct { - uint8_t lun[8]; - int64_t tag; - uint8_t task_attr; - uint8_t prio; - uint8_t crn; - uint8_t cdb[CDB_SIZE]; -} QEMU_PACKED QVirtIOSCSICmdReq; - -typedef struct { - uint32_t sense_len; - uint32_t resid; - uint16_t status_qualifier; - uint8_t status; - uint8_t response; - uint8_t sense[96]; -} QEMU_PACKED QVirtIOSCSICmdResp; - static void qvirtio_scsi_start(const char *extra_opts) { char *cmdline; @@ -74,7 +58,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs) int i; for (i = 0; i < vs->num_queues + 2; i++) { - guest_free(vs->alloc, vs->vq[i]->desc); + qvirtqueue_cleanup(&qvirtio_pci, vs->vq[i], vs->alloc); } pc_alloc_uninit(vs->alloc); qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev)); @@ -99,11 +83,11 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, const uint8_t *data_in, size_t data_in_len, uint8_t *data_out, size_t data_out_len, - QVirtIOSCSICmdResp *resp_out) + struct virtio_scsi_cmd_resp *resp_out) { QVirtQueue *vq; - QVirtIOSCSICmdReq req = { { 0 } }; - QVirtIOSCSICmdResp resp = { .response = 0xff, .status = 0xff }; + struct virtio_scsi_cmd_req req = { { 0 } }; + struct virtio_scsi_cmd_resp resp = { .response = 0xff, .status = 0xff }; uint64_t req_addr, resp_addr, data_in_addr = 0, data_out_addr = 0; uint8_t response; uint32_t free_head; @@ -112,7 +96,7 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, req.lun[0] = 1; /* Select LUN */ req.lun[1] = 1; /* Select target 1 */ - memcpy(req.cdb, cdb, CDB_SIZE); + memcpy(req.cdb, cdb, VIRTIO_SCSI_CDB_SIZE); /* XXX: Fix endian if any multi-byte field in req/resp is used */ @@ -137,7 +121,8 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, qvirtqueue_kick(&qvirtio_pci, vs->dev, vq, free_head); qvirtio_wait_queue_isr(&qvirtio_pci, vs->dev, vq, QVIRTIO_SCSI_TIMEOUT_US); - response = readb(resp_addr + offsetof(QVirtIOSCSICmdResp, response)); + response = readb(resp_addr + + offsetof(struct virtio_scsi_cmd_resp, response)); if (resp_out) { memread(resp_addr, resp_out, sizeof(*resp_out)); @@ -152,10 +137,10 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb, static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot) { - const uint8_t test_unit_ready_cdb[CDB_SIZE] = {}; + const uint8_t test_unit_ready_cdb[VIRTIO_SCSI_CDB_SIZE] = {}; QVirtIOSCSI *vs; QVirtioPCIDevice *dev; - QVirtIOSCSICmdResp resp; + struct virtio_scsi_cmd_resp resp; void *addr; int i; @@ -163,17 +148,17 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot) vs->alloc = pc_alloc_init(); vs->bus = qpci_init_pc(); - dev = qvirtio_pci_device_find(vs->bus, QVIRTIO_SCSI_DEVICE_ID); + dev = qvirtio_pci_device_find(vs->bus, VIRTIO_ID_SCSI); vs->dev = (QVirtioDevice *)dev; g_assert(dev != NULL); - g_assert_cmphex(vs->dev->device_type, ==, QVIRTIO_SCSI_DEVICE_ID); + g_assert_cmphex(vs->dev->device_type, ==, VIRTIO_ID_SCSI); qvirtio_pci_device_enable(dev); qvirtio_reset(&qvirtio_pci, vs->dev); qvirtio_set_acknowledge(&qvirtio_pci, vs->dev); qvirtio_set_driver(&qvirtio_pci, vs->dev); - addr = dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX; + addr = dev->addr + VIRTIO_PCI_CONFIG_OFF(false); vs->num_queues = qvirtio_config_readl(&qvirtio_pci, vs->dev, (uint64_t)(uintptr_t)addr); @@ -238,10 +223,12 @@ static void test_unaligned_write_same(void) QVirtIOSCSI *vs; uint8_t buf1[512] = { 0 }; uint8_t buf2[512] = { 1 }; - const uint8_t write_same_cdb_1[CDB_SIZE] = { 0x41, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x02, 0x00 }; - const uint8_t write_same_cdb_2[CDB_SIZE] = { 0x41, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x33, 0x00, 0x00 }; + const uint8_t write_same_cdb_1[VIRTIO_SCSI_CDB_SIZE] = { + 0x41, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00 + }; + const uint8_t write_same_cdb_2[VIRTIO_SCSI_CDB_SIZE] = { + 0x41, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x33, 0x00, 0x00 + }; qvirtio_scsi_start("-drive file=blkdebug::null-co://,if=none,id=dr1" ",format=raw,file.align=4k " @@ -260,15 +247,11 @@ static void test_unaligned_write_same(void) int main(int argc, char **argv) { - int ret; - g_test_init(&argc, &argv, NULL); qtest_add_func("/virtio/scsi/pci/nop", pci_nop); qtest_add_func("/virtio/scsi/pci/hotplug", hotplug); qtest_add_func("/virtio/scsi/pci/scsi-disk/unaligned-write-same", test_unaligned_write_same); - ret = g_test_run(); - - return ret; + return g_test_run(); } diff --git a/tests/wdt_ib700-test.c b/tests/wdt_ib700-test.c index 9c1d78b1bc..49f4f0c221 100644 --- a/tests/wdt_ib700-test.c +++ b/tests/wdt_ib700-test.c @@ -117,15 +117,11 @@ static void ib700_none(void) int main(int argc, char **argv) { - int ret; - g_test_init(&argc, &argv, NULL); qtest_add_func("/wdt_ib700/pause", ib700_pause); qtest_add_func("/wdt_ib700/reset", ib700_reset); qtest_add_func("/wdt_ib700/shutdown", ib700_shutdown); qtest_add_func("/wdt_ib700/none", ib700_none); - ret = g_test_run(); - - return ret; + return g_test_run(); } diff --git a/trace/control.c b/trace/control.c index d099f735d5..e1556a3570 100644 --- a/trace/control.c +++ b/trace/control.c @@ -19,6 +19,7 @@ #ifdef CONFIG_TRACE_LOG #include "qemu/log.h" #endif +#include "qapi/error.h" #include "qemu/error-report.h" #include "monitor/monitor.h" @@ -187,7 +188,7 @@ void trace_init_file(const char *file) * only applies to the simple backend; use "-D" for the log backend. */ if (file) { - qemu_set_log_filename(file); + qemu_set_log_filename(file, &error_fatal); } #else if (file) { diff --git a/ui/cursor.c b/ui/cursor.c index a276e01f1c..5155b392e8 100644 --- a/ui/cursor.c +++ b/ui/cursor.c @@ -81,18 +81,12 @@ void cursor_print_ascii_art(QEMUCursor *c, const char *prefix) QEMUCursor *cursor_builtin_hidden(void) { - QEMUCursor *c; - - c = cursor_parse_xpm(cursor_hidden_xpm); - return c; + return cursor_parse_xpm(cursor_hidden_xpm); } QEMUCursor *cursor_builtin_left_ptr(void) { - QEMUCursor *c; - - c = cursor_parse_xpm(cursor_left_ptr_xpm); - return c; + return cursor_parse_xpm(cursor_left_ptr_xpm); } QEMUCursor *cursor_alloc(int width, int height) diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c index c9f8dce7f4..6e8b83add6 100644 --- a/ui/qemu-pixman.c +++ b/ui/qemu-pixman.c @@ -180,14 +180,11 @@ void qemu_pixman_linebuf_copy(pixman_image_t *fb, int width, int x, int y, pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format, pixman_image_t *image) { - pixman_image_t *mirror; - - mirror = pixman_image_create_bits(format, - pixman_image_get_width(image), - pixman_image_get_height(image), - NULL, - pixman_image_get_stride(image)); - return mirror; + return pixman_image_create_bits(format, + pixman_image_get_width(image), + pixman_image_get_height(image), + NULL, + pixman_image_get_stride(image)); } void qemu_pixman_image_unref(pixman_image_t *image) diff --git a/util/log.c b/util/log.c index 5ad72c197f..32e416051c 100644 --- a/util/log.c +++ b/util/log.c @@ -22,6 +22,7 @@ #include "qemu/log.h" #include "qemu/range.h" #include "qemu/error-report.h" +#include "qapi/error.h" #include "qemu/cutils.h" #include "trace/control.h" @@ -102,7 +103,7 @@ void qemu_log_needs_buffers(void) * substituted with the current PID. This is useful for debugging many * nested linux-user tasks but will result in lots of logs. */ -void qemu_set_log_filename(const char *filename) +void qemu_set_log_filename(const char *filename, Error **errp) { char *pidstr; g_free(logfilename); @@ -111,8 +112,8 @@ void qemu_set_log_filename(const char *filename) if (pidstr) { /* We only accept one %d, no other format strings */ if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) { - error_report("Bad logfile format: %s", filename); - logfilename = NULL; + error_setg(errp, "Bad logfile format: %s", filename); + return; } else { logfilename = g_strdup_printf(filename, getpid()); } @@ -142,68 +143,75 @@ bool qemu_log_in_addr_range(uint64_t addr) } -void qemu_set_dfilter_ranges(const char *filter_spec) +void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp) { gchar **ranges = g_strsplit(filter_spec, ",", 0); - if (ranges) { - gchar **next = ranges; - gchar *r = *next++; - debug_regions = g_array_sized_new(FALSE, FALSE, - sizeof(Range), g_strv_length(ranges)); - while (r) { - char *range_op = strstr(r, "-"); - char *r2 = range_op ? range_op + 1 : NULL; - if (!range_op) { - range_op = strstr(r, "+"); - r2 = range_op ? range_op + 1 : NULL; - } - if (!range_op) { - range_op = strstr(r, ".."); - r2 = range_op ? range_op + 2 : NULL; - } - if (range_op) { - const char *e = NULL; - uint64_t r1val, r2val; + int i; - if ((qemu_strtoull(r, &e, 0, &r1val) == 0) && - (qemu_strtoull(r2, NULL, 0, &r2val) == 0) && - r2val > 0) { - struct Range range; + if (debug_regions) { + g_array_unref(debug_regions); + debug_regions = NULL; + } - g_assert(e == range_op); + debug_regions = g_array_sized_new(FALSE, FALSE, + sizeof(Range), g_strv_length(ranges)); + for (i = 0; ranges[i]; i++) { + const char *r = ranges[i]; + const char *range_op, *r2, *e; + uint64_t r1val, r2val; + struct Range range; - switch (*range_op) { - case '+': - { - range.begin = r1val; - range.end = r1val + (r2val - 1); - break; - } - case '-': - { - range.end = r1val; - range.begin = r1val - (r2val - 1); - break; - } - case '.': - range.begin = r1val; - range.end = r2val; - break; - default: - g_assert_not_reached(); - } - g_array_append_val(debug_regions, range); + range_op = strstr(r, "-"); + r2 = range_op ? range_op + 1 : NULL; + if (!range_op) { + range_op = strstr(r, "+"); + r2 = range_op ? range_op + 1 : NULL; + } + if (!range_op) { + range_op = strstr(r, ".."); + r2 = range_op ? range_op + 2 : NULL; + } + if (!range_op) { + error_setg(errp, "Bad range specifier"); + goto out; + } - } else { - g_error("Failed to parse range in: %s", r); - } - } else { - g_error("Bad range specifier in: %s", r); - } - r = *next++; + if (qemu_strtoull(r, &e, 0, &r1val) + || e != range_op) { + error_setg(errp, "Invalid number to the left of %.*s", + (int)(r2 - range_op), range_op); + goto out; + } + if (qemu_strtoull(r2, NULL, 0, &r2val)) { + error_setg(errp, "Invalid number to the right of %.*s", + (int)(r2 - range_op), range_op); + goto out; + } + if (r2val == 0) { + error_setg(errp, "Invalid range"); + goto out; + } + + switch (*range_op) { + case '+': + range.begin = r1val; + range.end = r1val + (r2val - 1); + break; + case '-': + range.end = r1val; + range.begin = r1val - (r2val - 1); + break; + case '.': + range.begin = r1val; + range.end = r2val; + break; + default: + g_assert_not_reached(); } - g_strfreev(ranges); + g_array_append_val(debug_regions, range); } +out: + g_strfreev(ranges); } /* fflush() the log file */ diff --git a/util/module.c b/util/module.c index ce058aef6f..86e3f7aba0 100644 --- a/util/module.c +++ b/util/module.c @@ -55,13 +55,9 @@ static void init_lists(void) static ModuleTypeList *find_type(module_init_type type) { - ModuleTypeList *l; - init_lists(); - l = &init_type_list[type]; - - return l; + return &init_type_list[type]; } void register_module_init(void (*fn)(void), module_init_type type) @@ -2352,10 +2352,7 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) #ifdef CONFIG_VIRTFS static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) { - int ret; - ret = qemu_fsdev_add(opts); - - return ret; + return qemu_fsdev_add(opts); } #endif @@ -3068,7 +3065,7 @@ int main(int argc, char **argv, char **envp) popt = lookup_opt(argc, argv, &optarg, &optind); if (!(popt->arch_mask & arch_type)) { - printf("Option %s not supported for this target\n", popt->name); + error_report("Option not supported for this target"); exit(1); } switch(popt->index) { @@ -3342,7 +3339,7 @@ int main(int argc, char **argv, char **envp) log_file = optarg; break; case QEMU_OPTION_DFILTER: - qemu_set_dfilter_ranges(optarg); + qemu_set_dfilter_ranges(optarg, &error_fatal); break; case QEMU_OPTION_s: add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); @@ -3846,21 +3843,21 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_xen_domid: if (!(xen_available())) { - printf("Option %s not supported for this target\n", popt->name); + error_report("Option not supported for this target"); exit(1); } xen_domid = atoi(optarg); break; case QEMU_OPTION_xen_create: if (!(xen_available())) { - printf("Option %s not supported for this target\n", popt->name); + error_report("Option not supported for this target"); exit(1); } xen_mode = XEN_CREATE; break; case QEMU_OPTION_xen_attach: if (!(xen_available())) { - printf("Option %s not supported for this target\n", popt->name); + error_report("Option not supported for this target"); exit(1); } xen_mode = XEN_ATTACH; @@ -4057,7 +4054,7 @@ int main(int argc, char **argv, char **envp) /* Open the logfile at this point and set the log mask if necessary. */ if (log_file) { - qemu_set_log_filename(log_file); + qemu_set_log_filename(log_file, &error_fatal); } if (log_mask) { |