Blame SOURCES/kvm-qobject-Modify-qobject_ref-to-return-obj.patch

357786
From 2b24bd311f6a7a416432078f9e76f772759c7ea2 Mon Sep 17 00:00:00 2001
357786
From: Markus Armbruster <armbru@redhat.com>
357786
Date: Mon, 18 Jun 2018 08:43:12 +0200
357786
Subject: [PATCH 05/54] qobject: Modify qobject_ref() to return obj
357786
MIME-Version: 1.0
357786
Content-Type: text/plain; charset=UTF-8
357786
Content-Transfer-Encoding: 8bit
357786
357786
RH-Author: Markus Armbruster <armbru@redhat.com>
357786
Message-id: <20180618084330.30009-6-armbru@redhat.com>
357786
Patchwork-id: 80738
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 05/23] qobject: Modify qobject_ref() to return obj
357786
Bugzilla: 1557995
357786
RH-Acked-by: Max Reitz <mreitz@redhat.com>
357786
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
357786
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
357786
357786
From: Marc-André Lureau <marcandre.lureau@redhat.com>
357786
357786
For convenience and clarity, make it possible to call qobject_ref() at
357786
the time when the reference is associated with a variable, or
357786
argument, by making qobject_ref() return the same pointer as given.
357786
Use that to simplify the callers.
357786
357786
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
357786
Reviewed-by: Eric Blake <eblake@redhat.com>
357786
Message-Id: <20180419150145.24795-5-marcandre.lureau@redhat.com>
357786
Reviewed-by: Markus Armbruster <armbru@redhat.com>
357786
[Useless change to qobject_ref_impl() dropped, commit message improved
357786
slightly]
357786
Signed-off-by: Markus Armbruster <armbru@redhat.com>
357786
(cherry picked from commit f5a74a5a50387c6f980b2e2f94f062487a1826da)
357786
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 block.c                       |  8 ++++----
357786
 block/blkdebug.c              |  7 +++----
357786
 block/blkverify.c             |  8 ++++----
357786
 block/null.c                  |  3 +--
357786
 block/nvme.c                  |  3 +--
357786
 block/quorum.c                |  4 ++--
357786
 include/qapi/qmp/qnull.h      |  3 +--
357786
 include/qapi/qmp/qobject.h    |  9 ++++++++-
357786
 monitor.c                     | 20 +++++++-------------
357786
 qapi/qobject-input-visitor.c  |  6 ++----
357786
 qapi/qobject-output-visitor.c |  7 +++----
357786
 qobject/qdict.c               | 33 +++++++++++----------------------
357786
 12 files changed, 47 insertions(+), 64 deletions(-)
357786
357786
diff --git a/block.c b/block.c
357786
index 55a7984..676e57f 100644
357786
--- a/block.c
357786
+++ b/block.c
357786
@@ -5134,8 +5134,8 @@ static bool append_open_options(QDict *d, BlockDriverState *bs)
357786
             continue;
357786
         }
357786
 
357786
-        qobject_ref(qdict_entry_value(entry));
357786
-        qdict_put_obj(d, qdict_entry_key(entry), qdict_entry_value(entry));
357786
+        qdict_put_obj(d, qdict_entry_key(entry),
357786
+                      qobject_ref(qdict_entry_value(entry)));
357786
         found_any = true;
357786
     }
357786
 
357786
@@ -5207,8 +5207,8 @@ void bdrv_refresh_filename(BlockDriverState *bs)
357786
          * suffices without querying the (exact_)filename of this BDS. */
357786
         if (bs->file->bs->full_open_options) {
357786
             qdict_put_str(opts, "driver", drv->format_name);
357786
-            qobject_ref(bs->file->bs->full_open_options);
357786
-            qdict_put(opts, "file", bs->file->bs->full_open_options);
357786
+            qdict_put(opts, "file",
357786
+                      qobject_ref(bs->file->bs->full_open_options));
357786
 
357786
             bs->full_open_options = opts;
357786
         } else {
357786
diff --git a/block/blkdebug.c b/block/blkdebug.c
357786
index 689703d..053372c 100644
357786
--- a/block/blkdebug.c
357786
+++ b/block/blkdebug.c
357786
@@ -845,13 +845,12 @@ static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
357786
     opts = qdict_new();
357786
     qdict_put_str(opts, "driver", "blkdebug");
357786
 
357786
-    qobject_ref(bs->file->bs->full_open_options);
357786
-    qdict_put(opts, "image", bs->file->bs->full_open_options);
357786
+    qdict_put(opts, "image", qobject_ref(bs->file->bs->full_open_options));
357786
 
357786
     for (e = qdict_first(options); e; e = qdict_next(options, e)) {
357786
         if (strcmp(qdict_entry_key(e), "x-image")) {
357786
-            qobject_ref(qdict_entry_value(e));
357786
-            qdict_put_obj(opts, qdict_entry_key(e), qdict_entry_value(e));
357786
+            qdict_put_obj(opts, qdict_entry_key(e),
357786
+                          qobject_ref(qdict_entry_value(e)));
357786
         }
357786
     }
357786
 
357786
diff --git a/block/blkverify.c b/block/blkverify.c
357786
index 3cffcb1..754cc9e 100644
357786
--- a/block/blkverify.c
357786
+++ b/block/blkverify.c
357786
@@ -291,10 +291,10 @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options)
357786
         QDict *opts = qdict_new();
357786
         qdict_put_str(opts, "driver", "blkverify");
357786
 
357786
-        qobject_ref(bs->file->bs->full_open_options);
357786
-        qdict_put(opts, "raw", bs->file->bs->full_open_options);
357786
-        qobject_ref(s->test_file->bs->full_open_options);
357786
-        qdict_put(opts, "test", s->test_file->bs->full_open_options);
357786
+        qdict_put(opts, "raw",
357786
+                  qobject_ref(bs->file->bs->full_open_options));
357786
+        qdict_put(opts, "test",
357786
+                  qobject_ref(s->test_file->bs->full_open_options));
357786
 
357786
         bs->full_open_options = opts;
357786
     }
357786
diff --git a/block/null.c b/block/null.c
357786
index 700a2d0..3944550 100644
357786
--- a/block/null.c
357786
+++ b/block/null.c
357786
@@ -244,7 +244,6 @@ static int coroutine_fn null_co_block_status(BlockDriverState *bs,
357786
 
357786
 static void null_refresh_filename(BlockDriverState *bs, QDict *opts)
357786
 {
357786
-    qobject_ref(opts);
357786
     qdict_del(opts, "filename");
357786
 
357786
     if (!qdict_size(opts)) {
357786
@@ -253,7 +252,7 @@ static void null_refresh_filename(BlockDriverState *bs, QDict *opts)
357786
     }
357786
 
357786
     qdict_put_str(opts, "driver", bs->drv->format_name);
357786
-    bs->full_open_options = opts;
357786
+    bs->full_open_options = qobject_ref(opts);
357786
 }
357786
 
357786
 static BlockDriver bdrv_null_co = {
357786
diff --git a/block/nvme.c b/block/nvme.c
357786
index e192da9..6f71122 100644
357786
--- a/block/nvme.c
357786
+++ b/block/nvme.c
357786
@@ -1073,7 +1073,6 @@ static int nvme_reopen_prepare(BDRVReopenState *reopen_state,
357786
 
357786
 static void nvme_refresh_filename(BlockDriverState *bs, QDict *opts)
357786
 {
357786
-    qobject_ref(opts);
357786
     qdict_del(opts, "filename");
357786
 
357786
     if (!qdict_size(opts)) {
357786
@@ -1082,7 +1081,7 @@ static void nvme_refresh_filename(BlockDriverState *bs, QDict *opts)
357786
     }
357786
 
357786
     qdict_put_str(opts, "driver", bs->drv->format_name);
357786
-    bs->full_open_options = opts;
357786
+    bs->full_open_options = qobject_ref(opts);
357786
 }
357786
 
357786
 static void nvme_refresh_limits(BlockDriverState *bs, Error **errp)
357786
diff --git a/block/quorum.c b/block/quorum.c
357786
index 862cea3..a5051da 100644
357786
--- a/block/quorum.c
357786
+++ b/block/quorum.c
357786
@@ -1082,8 +1082,8 @@ static void quorum_refresh_filename(BlockDriverState *bs, QDict *options)
357786
 
357786
     children = qlist_new();
357786
     for (i = 0; i < s->num_children; i++) {
357786
-        qobject_ref(s->children[i]->bs->full_open_options);
357786
-        qlist_append(children, s->children[i]->bs->full_open_options);
357786
+        qlist_append(children,
357786
+                     qobject_ref(s->children[i]->bs->full_open_options));
357786
     }
357786
 
357786
     opts = qdict_new();
357786
diff --git a/include/qapi/qmp/qnull.h b/include/qapi/qmp/qnull.h
357786
index 75b29c6..c142688 100644
357786
--- a/include/qapi/qmp/qnull.h
357786
+++ b/include/qapi/qmp/qnull.h
357786
@@ -23,8 +23,7 @@ extern QNull qnull_;
357786
 
357786
 static inline QNull *qnull(void)
357786
 {
357786
-    qobject_ref(&qnull_);
357786
-    return &qnull_;
357786
+    return qobject_ref(&qnull_);
357786
 }
357786
 
357786
 bool qnull_is_equal(const QObject *x, const QObject *y);
357786
diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h
357786
index e20006f..fcfd549 100644
357786
--- a/include/qapi/qmp/qobject.h
357786
+++ b/include/qapi/qmp/qobject.h
357786
@@ -103,8 +103,15 @@ static inline void qobject_unref_impl(QObject *obj)
357786
 
357786
 /**
357786
  * qobject_ref(): Increment QObject's reference count
357786
+ *
357786
+ * Returns: the same @obj. The type of @obj will be propagated to the
357786
+ * return type.
357786
  */
357786
-#define qobject_ref(obj) qobject_ref_impl(QOBJECT(obj))
357786
+#define qobject_ref(obj) ({                     \
357786
+    typeof(obj) _o = (obj);                     \
357786
+    qobject_ref_impl(QOBJECT(_o));              \
357786
+    _o;                                         \
357786
+})
357786
 
357786
 /**
357786
  * qobject_unref(): Decrement QObject's reference count, deallocate
357786
diff --git a/monitor.c b/monitor.c
357786
index 32f72f2..d948dbd 100644
357786
--- a/monitor.c
357786
+++ b/monitor.c
357786
@@ -494,9 +494,8 @@ static void monitor_json_emitter(Monitor *mon, QObject *data)
357786
          * caller won't free the data (which will be finally freed in
357786
          * responder thread).
357786
          */
357786
-        qobject_ref(data);
357786
         qemu_mutex_lock(&mon->qmp.qmp_queue_lock);
357786
-        g_queue_push_tail(mon->qmp.qmp_responses, data);
357786
+        g_queue_push_tail(mon->qmp.qmp_responses, qobject_ref(data));
357786
         qemu_mutex_unlock(&mon->qmp.qmp_queue_lock);
357786
         qemu_bh_schedule(mon_global.qmp_respond_bh);
357786
     } else {
357786
@@ -614,8 +613,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp)
357786
              * replacing a prior stored event if any.
357786
              */
357786
             qobject_unref(evstate->qdict);
357786
-            evstate->qdict = qdict;
357786
-            qobject_ref(evstate->qdict);
357786
+            evstate->qdict = qobject_ref(qdict);
357786
         } else {
357786
             /*
357786
              * Last send was (at least) evconf->rate ns ago.
357786
@@ -629,8 +627,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp)
357786
 
357786
             evstate = g_new(MonitorQAPIEventState, 1);
357786
             evstate->event = event;
357786
-            evstate->data = data;
357786
-            qobject_ref(evstate->data);
357786
+            evstate->data = qobject_ref(data);
357786
             evstate->qdict = NULL;
357786
             evstate->timer = timer_new_ns(event_clock_type,
357786
                                           monitor_qapi_event_handler,
357786
@@ -4066,9 +4063,7 @@ static void monitor_qmp_respond(Monitor *mon, QObject *rsp,
357786
 
357786
     if (rsp) {
357786
         if (id) {
357786
-            /* This is for the qdict below. */
357786
-            qobject_ref(id);
357786
-            qdict_put_obj(qobject_to(QDict, rsp), "id", id);
357786
+            qdict_put_obj(qobject_to(QDict, rsp), "id", qobject_ref(id));
357786
         }
357786
 
357786
         monitor_json_emitter(mon, rsp);
357786
@@ -4208,15 +4203,14 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
357786
         goto err;
357786
     }
357786
 
357786
-    qobject_ref(id);
357786
-    qdict_del(qdict, "id");
357786
-
357786
     req_obj = g_new0(QMPRequest, 1);
357786
     req_obj->mon = mon;
357786
-    req_obj->id = id;
357786
+    req_obj->id = qobject_ref(id);
357786
     req_obj->req = req;
357786
     req_obj->need_resume = false;
357786
 
357786
+    qdict_del(qdict, "id");
357786
+
357786
     if (qmp_is_oob(qdict)) {
357786
         /* Out-Of-Band (OOB) requests are executed directly in parser. */
357786
         trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(req_obj->id)
357786
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
357786
index 7a290c4..da57f4c 100644
357786
--- a/qapi/qobject-input-visitor.c
357786
+++ b/qapi/qobject-input-visitor.c
357786
@@ -588,8 +588,7 @@ static void qobject_input_type_any(Visitor *v, const char *name, QObject **obj,
357786
         return;
357786
     }
357786
 
357786
-    qobject_ref(qobj);
357786
-    *obj = qobj;
357786
+    *obj = qobject_ref(qobj);
357786
 }
357786
 
357786
 static void qobject_input_type_null(Visitor *v, const char *name,
357786
@@ -677,8 +676,7 @@ static QObjectInputVisitor *qobject_input_visitor_base_new(QObject *obj)
357786
     v->visitor.optional = qobject_input_optional;
357786
     v->visitor.free = qobject_input_free;
357786
 
357786
-    v->root = obj;
357786
-    qobject_ref(obj);
357786
+    v->root = qobject_ref(obj);
357786
 
357786
     return v;
357786
 }
357786
diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c
357786
index 3a933b4..89ffd8a 100644
357786
--- a/qapi/qobject-output-visitor.c
357786
+++ b/qapi/qobject-output-visitor.c
357786
@@ -188,8 +188,8 @@ static void qobject_output_type_any(Visitor *v, const char *name,
357786
                                     QObject **obj, Error **errp)
357786
 {
357786
     QObjectOutputVisitor *qov = to_qov(v);
357786
-    qobject_ref(*obj);
357786
-    qobject_output_add_obj(qov, name, *obj);
357786
+
357786
+    qobject_output_add_obj(qov, name, qobject_ref(*obj));
357786
 }
357786
 
357786
 static void qobject_output_type_null(Visitor *v, const char *name,
357786
@@ -210,8 +210,7 @@ static void qobject_output_complete(Visitor *v, void *opaque)
357786
     assert(qov->root && QSLIST_EMPTY(&qov->stack));
357786
     assert(opaque == qov->result);
357786
 
357786
-    qobject_ref(qov->root);
357786
-    *qov->result = qov->root;
357786
+    *qov->result = qobject_ref(qov->root);
357786
     qov->result = NULL;
357786
 }
357786
 
357786
diff --git a/qobject/qdict.c b/qobject/qdict.c
357786
index 2e9bd53..22800ee 100644
357786
--- a/qobject/qdict.c
357786
+++ b/qobject/qdict.c
357786
@@ -373,8 +373,7 @@ QDict *qdict_clone_shallow(const QDict *src)
357786
 
357786
     for (i = 0; i < QDICT_BUCKET_MAX; i++) {
357786
         QLIST_FOREACH(entry, &src->table[i], next) {
357786
-            qobject_ref(entry->value);
357786
-            qdict_put_obj(dest, entry->key, entry->value);
357786
+            qdict_put_obj(dest, entry->key, qobject_ref(entry->value));
357786
         }
357786
     }
357786
 
357786
@@ -480,8 +479,7 @@ void qdict_copy_default(QDict *dst, QDict *src, const char *key)
357786
 
357786
     val = qdict_get(src, key);
357786
     if (val) {
357786
-        qobject_ref(val);
357786
-        qdict_put_obj(dst, key, val);
357786
+        qdict_put_obj(dst, key, qobject_ref(val));
357786
     }
357786
 }
357786
 
357786
@@ -526,8 +524,7 @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix)
357786
             qdict_flatten_qlist(qobject_to(QList, value), target, new_key);
357786
         } else {
357786
             /* All other types are moved to the target unchanged. */
357786
-            qobject_ref(value);
357786
-            qdict_put_obj(target, new_key, value);
357786
+            qdict_put_obj(target, new_key, qobject_ref(value));
357786
         }
357786
 
357786
         g_free(new_key);
357786
@@ -566,8 +563,7 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
357786
             delete = true;
357786
         } else if (prefix) {
357786
             /* All other objects are moved to the target unchanged. */
357786
-            qobject_ref(value);
357786
-            qdict_put_obj(target, new_key, value);
357786
+            qdict_put_obj(target, new_key, qobject_ref(value));
357786
             delete = true;
357786
         }
357786
 
357786
@@ -610,8 +606,7 @@ void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start)
357786
     while (entry != NULL) {
357786
         next = qdict_next(src, entry);
357786
         if (strstart(entry->key, start, &p)) {
357786
-            qobject_ref(entry->value);
357786
-            qdict_put_obj(*dst, p, entry->value);
357786
+            qdict_put_obj(*dst, p, qobject_ref(entry->value));
357786
             qdict_del(src, entry->key);
357786
         }
357786
         entry = next;
357786
@@ -894,16 +889,14 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
357786
                 qdict_put_obj(two_level, prefix, QOBJECT(child_dict));
357786
             }
357786
 
357786
-            qobject_ref(ent->value);
357786
-            qdict_put_obj(child_dict, suffix, ent->value);
357786
+            qdict_put_obj(child_dict, suffix, qobject_ref(ent->value));
357786
         } else {
357786
             if (child) {
357786
                 error_setg(errp, "Key %s prefix is already set as a dict",
357786
                            prefix);
357786
                 goto error;
357786
             }
357786
-            qobject_ref(ent->value);
357786
-            qdict_put_obj(two_level, prefix, ent->value);
357786
+            qdict_put_obj(two_level, prefix, qobject_ref(ent->value));
357786
         }
357786
 
357786
         g_free(prefix);
357786
@@ -924,8 +917,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
357786
 
357786
             qdict_put_obj(multi_level, ent->key, child);
357786
         } else {
357786
-            qobject_ref(ent->value);
357786
-            qdict_put_obj(multi_level, ent->key, ent->value);
357786
+            qdict_put_obj(multi_level, ent->key, qobject_ref(ent->value));
357786
         }
357786
     }
357786
     qobject_unref(two_level);
357786
@@ -951,8 +943,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
357786
                 goto error;
357786
             }
357786
 
357786
-            qobject_ref(child);
357786
-            qlist_append_obj(qobject_to(QList, dst), child);
357786
+            qlist_append_obj(qobject_to(QList, dst), qobject_ref(child));
357786
         }
357786
         qobject_unref(multi_level);
357786
         multi_level = NULL;
357786
@@ -1055,8 +1046,7 @@ void qdict_join(QDict *dest, QDict *src, bool overwrite)
357786
         next = qdict_next(src, entry);
357786
 
357786
         if (overwrite || !qdict_haskey(dest, entry->key)) {
357786
-            qobject_ref(entry->value);
357786
-            qdict_put_obj(dest, entry->key, entry->value);
357786
+            qdict_put_obj(dest, entry->key, qobject_ref(entry->value));
357786
             qdict_del(src, entry->key);
357786
         }
357786
 
357786
@@ -1088,8 +1078,7 @@ bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp)
357786
             }
357786
 
357786
             qobj = qdict_get(qdict, renames->from);
357786
-            qobject_ref(qobj);
357786
-            qdict_put_obj(qdict, renames->to, qobj);
357786
+            qdict_put_obj(qdict, renames->to, qobject_ref(qobj));
357786
             qdict_del(qdict, renames->from);
357786
         }
357786
 
357786
-- 
357786
1.8.3.1
357786