Skip to contentSkip to conversation

qtail: clean up direct access to tqe_prev field

PATCH In review Igor Mammedov 2 participants 2 messages Jul 25, 2016 – Aug 1, 2016 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qtail: clean up direct access to tqe_prev field

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.

---
The patch is split from as cleanup is not urgent
[PATCH 0/6] Fix migration issues with arbitrary cpu-hot(un)plug
and made on top of
[PATCH v2 0/6] Fix migration issues with arbitrary cpu-hot(un)plug

posting it to list so that it won't be forgotten or lost and affected people could review it at there leisure time.

---
 include/qemu/queue.h | 2 ++
 blockdev.c           | 2 +-
 exec.c               | 3 +--
 net/filter.c         | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)
include/qemu/queue.h +2 -0
index c2b6c81..342073f 100644
@@ -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)                                \
@@ -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))
blockdev.c +1 -1
index eafeba9..0b73158 100644
@@ -4031,7 +4031,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;
exec.c +1 -2
index 50e3ee2..8e8416b 100644
@@ -614,14 +614,13 @@ 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;
     }
 
     QTAILQ_REMOVE(&cpus, cpu, node);
-    cpu->node.tqe_prev = NULL;
     cpu->cpu_index = UNASSIGNED_CPU_INDEX;
     cpu_list_unlock();
 
net/filter.c +1 -1
index 888fe6d..1dfd2ca 100644
@@ -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);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 81 lines · Igor Mammedov

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.

---
The patch is split from as cleanup is not urgent
[PATCH 0/6] Fix migration issues with arbitrary cpu-hot(un)plug
and made on top of
[PATCH v2 0/6] Fix migration issues with arbitrary cpu-hot(un)plug

posting it to list so that it won't be forgotten or lost and affected people could review it at there leisure time.

---
 include/qemu/queue.h | 2 ++
 blockdev.c           | 2 +-
 exec.c               | 3 +--
 net/filter.c         | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)
include/qemu/queue.h +2 -0
index c2b6c81..342073f 100644
@@ -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)                                \
@@ -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))
blockdev.c +1 -1
index eafeba9..0b73158 100644
@@ -4031,7 +4031,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;
exec.c +1 -2
index 50e3ee2..8e8416b 100644
@@ -614,14 +614,13 @@ 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;
     }
 
     QTAILQ_REMOVE(&cpus, cpu, node);
-    cpu->node.tqe_prev = NULL;
     cpu->cpu_index = UNASSIGNED_CPU_INDEX;
     cpu_list_unlock();
 
net/filter.c +0 -0
index 888fe6d..1dfd2ca 100644

net/filter.c static void netfilter_finalize(Object *obj) · line 245

Quoted 8 lines
net/filter.c +1 -1
@@ -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);

Looks good, thanks!

Paolo