qemu/atomic.h: rename atomic_ to qatomic_
clang's C11 atomic_fetch_*() functions only take a C11 atomic type
pointer argument. QEMU uses direct types (int, etc) and this causes a
compiler error when a QEMU code calls these functions in a source file
that also included <stdatomic.h> via a system header file:
$ CC=clang CXX=clang++ ./configure ... && make
../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)
Avoid using atomic_*() names in QEMU's atomic.h since that namespace is
used by <stdatomic.h>. Prefix QEMU's APIs with 'q' so that atomic.h
and <stdatomic.h> can co-exist. I checked /usr/include on my machine and
searched GitHub for existing "qatomic_" users but there seem to be none.
This patch was generated using:
$ git grep -h -o '\<atomic\(64\)\?_[a-z0-9_]\+' include/qemu/atomic.h | \
sort -u >/tmp/changed_identifiers
$ for identifier in $(</tmp/changed_identifiers); do
sed -i "s%\<$identifier\>%q$identifier%g" \
$(git grep -I -l "\<$identifier\>")
done
I manually fixed line-wrap issues and misaligned rST tables.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200923105646.47864-1-stefanha@redhat.com>
diff --git a/block/block-backend.c b/block/block-backend.c
index 24dd067..ce78d30 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1353,12 +1353,12 @@
void blk_inc_in_flight(BlockBackend *blk)
{
- atomic_inc(&blk->in_flight);
+ qatomic_inc(&blk->in_flight);
}
void blk_dec_in_flight(BlockBackend *blk)
{
- atomic_dec(&blk->in_flight);
+ qatomic_dec(&blk->in_flight);
aio_wait_kick();
}
@@ -1720,7 +1720,7 @@
/* We may have -ENOMEDIUM completions in flight */
AIO_WAIT_WHILE(blk_get_aio_context(blk),
- atomic_mb_read(&blk->in_flight) > 0);
+ qatomic_mb_read(&blk->in_flight) > 0);
if (bs) {
bdrv_drained_end(bs);
@@ -1739,7 +1739,7 @@
aio_context_acquire(ctx);
/* We may have -ENOMEDIUM completions in flight */
- AIO_WAIT_WHILE(ctx, atomic_mb_read(&blk->in_flight) > 0);
+ AIO_WAIT_WHILE(ctx, qatomic_mb_read(&blk->in_flight) > 0);
aio_context_release(ctx);
}
@@ -2346,6 +2346,7 @@
static void blk_root_drained_begin(BdrvChild *child)
{
BlockBackend *blk = child->opaque;
+ ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
if (++blk->quiesce_counter == 1) {
if (blk->dev_ops && blk->dev_ops->drained_begin) {
@@ -2356,8 +2357,8 @@
/* Note that blk->root may not be accessible here yet if we are just
* attaching to a BlockDriverState that is drained. Use child instead. */
- if (atomic_fetch_inc(&blk->public.throttle_group_member.io_limits_disabled) == 0) {
- throttle_group_restart_tgm(&blk->public.throttle_group_member);
+ if (qatomic_fetch_inc(&tgm->io_limits_disabled) == 0) {
+ throttle_group_restart_tgm(tgm);
}
}
@@ -2374,7 +2375,7 @@
assert(blk->quiesce_counter);
assert(blk->public.throttle_group_member.io_limits_disabled);
- atomic_dec(&blk->public.throttle_group_member.io_limits_disabled);
+ qatomic_dec(&blk->public.throttle_group_member.io_limits_disabled);
if (--blk->quiesce_counter == 0) {
if (blk->dev_ops && blk->dev_ops->drained_end) {
diff --git a/block/io.c b/block/io.c
index a2389bb..11df188 100644
--- a/block/io.c
+++ b/block/io.c
@@ -69,7 +69,7 @@
{
int drained_end_counter = 0;
bdrv_parent_drained_end_single_no_poll(c, &drained_end_counter);
- BDRV_POLL_WHILE(c->bs, atomic_read(&drained_end_counter) > 0);
+ BDRV_POLL_WHILE(c->bs, qatomic_read(&drained_end_counter) > 0);
}
static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore,
@@ -186,12 +186,12 @@
*/
void bdrv_enable_copy_on_read(BlockDriverState *bs)
{
- atomic_inc(&bs->copy_on_read);
+ qatomic_inc(&bs->copy_on_read);
}
void bdrv_disable_copy_on_read(BlockDriverState *bs)
{
- int old = atomic_fetch_dec(&bs->copy_on_read);
+ int old = qatomic_fetch_dec(&bs->copy_on_read);
assert(old >= 1);
}
@@ -219,9 +219,9 @@
}
/* Set data->done and decrement drained_end_counter before bdrv_wakeup() */
- atomic_mb_set(&data->done, true);
+ qatomic_mb_set(&data->done, true);
if (!data->begin) {
- atomic_dec(data->drained_end_counter);
+ qatomic_dec(data->drained_end_counter);
}
bdrv_dec_in_flight(bs);
@@ -248,7 +248,7 @@
};
if (!begin) {
- atomic_inc(drained_end_counter);
+ qatomic_inc(drained_end_counter);
}
/* Make sure the driver callback completes during the polling phase for
@@ -268,7 +268,7 @@
return true;
}
- if (atomic_read(&bs->in_flight)) {
+ if (qatomic_read(&bs->in_flight)) {
return true;
}
@@ -382,7 +382,7 @@
assert(!qemu_in_coroutine());
/* Stop things in parent-to-child order */
- if (atomic_fetch_inc(&bs->quiesce_counter) == 0) {
+ if (qatomic_fetch_inc(&bs->quiesce_counter) == 0) {
aio_disable_external(bdrv_get_aio_context(bs));
}
@@ -473,7 +473,7 @@
bdrv_parent_drained_end(bs, parent, ignore_bds_parents,
drained_end_counter);
- old_quiesce_counter = atomic_fetch_dec(&bs->quiesce_counter);
+ old_quiesce_counter = qatomic_fetch_dec(&bs->quiesce_counter);
if (old_quiesce_counter == 1) {
aio_enable_external(bdrv_get_aio_context(bs));
}
@@ -492,7 +492,7 @@
{
int drained_end_counter = 0;
bdrv_do_drained_end(bs, false, NULL, false, &drained_end_counter);
- BDRV_POLL_WHILE(bs, atomic_read(&drained_end_counter) > 0);
+ BDRV_POLL_WHILE(bs, qatomic_read(&drained_end_counter) > 0);
}
void bdrv_drained_end_no_poll(BlockDriverState *bs, int *drained_end_counter)
@@ -504,7 +504,7 @@
{
int drained_end_counter = 0;
bdrv_do_drained_end(bs, true, NULL, false, &drained_end_counter);
- BDRV_POLL_WHILE(bs, atomic_read(&drained_end_counter) > 0);
+ BDRV_POLL_WHILE(bs, qatomic_read(&drained_end_counter) > 0);
}
void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_parent)
@@ -526,7 +526,7 @@
&drained_end_counter);
}
- BDRV_POLL_WHILE(child->bs, atomic_read(&drained_end_counter) > 0);
+ BDRV_POLL_WHILE(child->bs, qatomic_read(&drained_end_counter) > 0);
}
/*
@@ -553,7 +553,7 @@
{
BdrvChild *child, *next;
- assert(atomic_read(&bs->in_flight) == 0);
+ assert(qatomic_read(&bs->in_flight) == 0);
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
bdrv_drain_assert_idle(child->bs);
}
@@ -655,7 +655,7 @@
}
assert(qemu_get_current_aio_context() == qemu_get_aio_context());
- AIO_WAIT_WHILE(NULL, atomic_read(&drained_end_counter) > 0);
+ AIO_WAIT_WHILE(NULL, qatomic_read(&drained_end_counter) > 0);
assert(bdrv_drain_all_count > 0);
bdrv_drain_all_count--;
@@ -675,7 +675,7 @@
static void tracked_request_end(BdrvTrackedRequest *req)
{
if (req->serialising) {
- atomic_dec(&req->bs->serialising_in_flight);
+ qatomic_dec(&req->bs->serialising_in_flight);
}
qemu_co_mutex_lock(&req->bs->reqs_lock);
@@ -777,7 +777,7 @@
qemu_co_mutex_lock(&bs->reqs_lock);
if (!req->serialising) {
- atomic_inc(&req->bs->serialising_in_flight);
+ qatomic_inc(&req->bs->serialising_in_flight);
req->serialising = true;
}
@@ -841,7 +841,7 @@
void bdrv_inc_in_flight(BlockDriverState *bs)
{
- atomic_inc(&bs->in_flight);
+ qatomic_inc(&bs->in_flight);
}
void bdrv_wakeup(BlockDriverState *bs)
@@ -851,7 +851,7 @@
void bdrv_dec_in_flight(BlockDriverState *bs)
{
- atomic_dec(&bs->in_flight);
+ qatomic_dec(&bs->in_flight);
bdrv_wakeup(bs);
}
@@ -860,7 +860,7 @@
BlockDriverState *bs = self->bs;
bool waited = false;
- if (!atomic_read(&bs->serialising_in_flight)) {
+ if (!qatomic_read(&bs->serialising_in_flight)) {
return false;
}
@@ -1747,7 +1747,7 @@
bdrv_inc_in_flight(bs);
/* Don't do copy-on-read if we read data before write operation */
- if (atomic_read(&bs->copy_on_read)) {
+ if (qatomic_read(&bs->copy_on_read)) {
flags |= BDRV_REQ_COPY_ON_READ;
}
@@ -1935,7 +1935,7 @@
int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE);
BlockDriverState *bs = child->bs;
- atomic_inc(&bs->write_gen);
+ qatomic_inc(&bs->write_gen);
/*
* Discard cannot extend the image, but in error handling cases, such as
@@ -2768,7 +2768,7 @@
}
qemu_co_mutex_lock(&bs->reqs_lock);
- current_gen = atomic_read(&bs->write_gen);
+ current_gen = qatomic_read(&bs->write_gen);
/* Wait until any previous flushes are completed */
while (bs->active_flush_req) {
@@ -3116,7 +3116,7 @@
bdrv_io_plug(child->bs);
}
- if (atomic_fetch_inc(&bs->io_plugged) == 0) {
+ if (qatomic_fetch_inc(&bs->io_plugged) == 0) {
BlockDriver *drv = bs->drv;
if (drv && drv->bdrv_io_plug) {
drv->bdrv_io_plug(bs);
@@ -3129,7 +3129,7 @@
BdrvChild *child;
assert(bs->io_plugged);
- if (atomic_fetch_dec(&bs->io_plugged) == 1) {
+ if (qatomic_fetch_dec(&bs->io_plugged) == 1) {
BlockDriver *drv = bs->drv;
if (drv && drv->bdrv_io_unplug) {
drv->bdrv_io_unplug(bs);
diff --git a/block/nfs.c b/block/nfs.c
index 61a249a..f86e660 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -721,7 +721,7 @@
}
/* Set task->complete before reading bs->wakeup. */
- atomic_mb_set(&task->complete, 1);
+ qatomic_mb_set(&task->complete, 1);
bdrv_wakeup(task->bs);
}
diff --git a/block/sheepdog.c b/block/sheepdog.c
index cbbebc1..2f5c0eb 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -665,7 +665,7 @@
srco->co = NULL;
srco->ret = ret;
/* Set srco->finished before reading bs->wakeup. */
- atomic_mb_set(&srco->finished, true);
+ qatomic_mb_set(&srco->finished, true);
if (srco->bs) {
bdrv_wakeup(srco->bs);
}
diff --git a/block/throttle-groups.c b/block/throttle-groups.c
index 4e28365..e2f2813 100644
--- a/block/throttle-groups.c
+++ b/block/throttle-groups.c
@@ -228,7 +228,7 @@
* immediately if it has pending requests. Otherwise we could be
* forcing it to wait for other member's throttled requests. */
if (tgm_has_pending_reqs(tgm, is_write) &&
- atomic_read(&tgm->io_limits_disabled)) {
+ qatomic_read(&tgm->io_limits_disabled)) {
return tgm;
}
@@ -272,7 +272,7 @@
ThrottleTimers *tt = &tgm->throttle_timers;
bool must_wait;
- if (atomic_read(&tgm->io_limits_disabled)) {
+ if (qatomic_read(&tgm->io_limits_disabled)) {
return false;
}
@@ -417,7 +417,7 @@
g_free(data);
- atomic_dec(&tgm->restart_pending);
+ qatomic_dec(&tgm->restart_pending);
aio_wait_kick();
}
@@ -434,7 +434,7 @@
* be no timer pending on this tgm at this point */
assert(!timer_pending(tgm->throttle_timers.timers[is_write]));
- atomic_inc(&tgm->restart_pending);
+ qatomic_inc(&tgm->restart_pending);
co = qemu_coroutine_create(throttle_group_restart_queue_entry, rd);
aio_co_enter(tgm->aio_context, co);
@@ -544,7 +544,7 @@
tgm->throttle_state = ts;
tgm->aio_context = ctx;
- atomic_set(&tgm->restart_pending, 0);
+ qatomic_set(&tgm->restart_pending, 0);
qemu_mutex_lock(&tg->lock);
/* If the ThrottleGroup is new set this ThrottleGroupMember as the token */
@@ -592,7 +592,7 @@
}
/* Wait for throttle_group_restart_queue_entry() coroutines to finish */
- AIO_WAIT_WHILE(tgm->aio_context, atomic_read(&tgm->restart_pending) > 0);
+ AIO_WAIT_WHILE(tgm->aio_context, qatomic_read(&tgm->restart_pending) > 0);
qemu_mutex_lock(&tg->lock);
for (i = 0; i < 2; i++) {
diff --git a/block/throttle.c b/block/throttle.c
index 9a0f381..b685166 100644
--- a/block/throttle.c
+++ b/block/throttle.c
@@ -217,7 +217,7 @@
static void coroutine_fn throttle_co_drain_begin(BlockDriverState *bs)
{
ThrottleGroupMember *tgm = bs->opaque;
- if (atomic_fetch_inc(&tgm->io_limits_disabled) == 0) {
+ if (qatomic_fetch_inc(&tgm->io_limits_disabled) == 0) {
throttle_group_restart_tgm(tgm);
}
}
@@ -226,7 +226,7 @@
{
ThrottleGroupMember *tgm = bs->opaque;
assert(tgm->io_limits_disabled);
- atomic_dec(&tgm->io_limits_disabled);
+ qatomic_dec(&tgm->io_limits_disabled);
}
static const char *const throttle_strong_runtime_opts[] = {