Skip to content

Commit

Permalink
qtail: clean up direct access to tqe_prev field
Browse files Browse the repository at this point in the history
instead of accessing tqe_prev field dircetly outside
of queue.h use macros to check if element is in list
and make sure that afer element is removed from list
tqe_prev field could be used to do the same check.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Message-Id: <1469450832-84343-1-git-send-email-imammedo@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Igor Mammedov authored and bonzini committed Sep 13, 2016
1 parent fa97012 commit 3b8c176
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -3907,7 +3907,7 @@ void qmp_x_blockdev_del(bool has_id, const char *id,
goto out;
}

if (!blk && !bs->monitor_list.tqe_prev) {
if (!blk && !QTAILQ_IN_USE(bs, monitor_list)) {
error_setg(errp, "Node %s is not owned by the monitor",
bs->node_name);
goto out;
Expand Down
3 changes: 1 addition & 2 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ void cpu_exec_exit(CPUState *cpu)
CPUClass *cc = CPU_GET_CLASS(cpu);

cpu_list_lock();
if (cpu->node.tqe_prev == NULL) {
if (!QTAILQ_IN_USE(cpu, node)) {
/* there is nothing to undo since cpu_exec_init() hasn't been called */
cpu_list_unlock();
return;
Expand All @@ -626,7 +626,6 @@ void cpu_exec_exit(CPUState *cpu)
assert(!(cpu_index_auto_assigned && cpu != QTAILQ_LAST(&cpus, CPUTailQ)));

QTAILQ_REMOVE(&cpus, cpu, node);
cpu->node.tqe_prev = NULL;
cpu->cpu_index = UNASSIGNED_CPU_INDEX;
cpu_list_unlock();

Expand Down
2 changes: 2 additions & 0 deletions include/qemu/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ struct { \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
(elm)->field.tqe_prev = NULL; \
} while (/*CONSTCOND*/0)

#define QTAILQ_FOREACH(var, head, field) \
Expand All @@ -430,6 +431,7 @@ struct { \
#define QTAILQ_EMPTY(head) ((head)->tqh_first == NULL)
#define QTAILQ_FIRST(head) ((head)->tqh_first)
#define QTAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#define QTAILQ_IN_USE(elm, field) ((elm)->field.tqe_prev != NULL)

#define QTAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))
Expand Down
2 changes: 1 addition & 1 deletion net/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static void netfilter_finalize(Object *obj)
}

if (nf->netdev && !QTAILQ_EMPTY(&nf->netdev->filters) &&
nf->next.tqe_prev) {
QTAILQ_IN_USE(nf, next)) {
QTAILQ_REMOVE(&nf->netdev->filters, nf, next);
}
g_free(nf->netdev_id);
Expand Down

0 comments on commit 3b8c176

Please sign in to comment.