Skip to content

Commit cb3e7f0

Browse files
elmarcoMarkus Armbruster
authored and
Markus Armbruster
committed
qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF
Now that we can safely call QOBJECT() on QObject * as well as its subtypes, we can have macros qobject_ref() / qobject_unref() that work everywhere instead of having to use QINCREF() / QDECREF() for QObject and qobject_incref() / qobject_decref() for its subtypes. The replacement is mechanical, except I broke a long line, and added a cast in monitor_qmp_cleanup_req_queue_locked(). Unlike qobject_decref(), qobject_unref() doesn't accept void *. Note that the new macros evaluate their argument exactly once, thus no need to shout them. Signed-off-by: Marc-André Lureau <[email protected]> Reviewed-by: Eric Blake <[email protected]> Message-Id: <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> [Rebased, semantic conflict resolved, commit message improved] Signed-off-by: Markus Armbruster <[email protected]>
1 parent 3d3eaca commit cb3e7f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+609
-613
lines changed

block.c

+39-39
Original file line numberDiff line numberDiff line change
@@ -1227,9 +1227,9 @@ BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_name,
12271227

12281228
ret = bdrv_open_driver(bs, drv, node_name, bs->options, flags, errp);
12291229
if (ret < 0) {
1230-
QDECREF(bs->explicit_options);
1230+
qobject_unref(bs->explicit_options);
12311231
bs->explicit_options = NULL;
1232-
QDECREF(bs->options);
1232+
qobject_unref(bs->options);
12331233
bs->options = NULL;
12341234
bdrv_unref(bs);
12351235
return NULL;
@@ -1460,7 +1460,7 @@ static QDict *parse_json_filename(const char *filename, Error **errp)
14601460

14611461
options = qobject_to(QDict, options_obj);
14621462
if (!options) {
1463-
qobject_decref(options_obj);
1463+
qobject_unref(options_obj);
14641464
error_setg(errp, "Invalid JSON object given");
14651465
return NULL;
14661466
}
@@ -1490,7 +1490,7 @@ static void parse_json_protocol(QDict *options, const char **pfilename,
14901490
/* Options given in the filename have lower priority than options
14911491
* specified directly */
14921492
qdict_join(options, json_options, false);
1493-
QDECREF(json_options);
1493+
qobject_unref(json_options);
14941494
*pfilename = NULL;
14951495
}
14961496

@@ -2273,23 +2273,23 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
22732273
if (reference || qdict_haskey(options, "file.filename")) {
22742274
backing_filename[0] = '\0';
22752275
} else if (bs->backing_file[0] == '\0' && qdict_size(options) == 0) {
2276-
QDECREF(options);
2276+
qobject_unref(options);
22772277
goto free_exit;
22782278
} else {
22792279
bdrv_get_full_backing_filename(bs, backing_filename, PATH_MAX,
22802280
&local_err);
22812281
if (local_err) {
22822282
ret = -EINVAL;
22832283
error_propagate(errp, local_err);
2284-
QDECREF(options);
2284+
qobject_unref(options);
22852285
goto free_exit;
22862286
}
22872287
}
22882288

22892289
if (!bs->drv || !bs->drv->supports_backing) {
22902290
ret = -EINVAL;
22912291
error_setg(errp, "Driver doesn't support backing files");
2292-
QDECREF(options);
2292+
qobject_unref(options);
22932293
goto free_exit;
22942294
}
22952295

@@ -2323,7 +2323,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
23232323

23242324
free_exit:
23252325
g_free(backing_filename);
2326-
QDECREF(tmp_parent_options);
2326+
qobject_unref(tmp_parent_options);
23272327
return ret;
23282328
}
23292329

@@ -2356,7 +2356,7 @@ bdrv_open_child_bs(const char *filename, QDict *options, const char *bdref_key,
23562356
error_setg(errp, "A block device must be specified for \"%s\"",
23572357
bdref_key);
23582358
}
2359-
QDECREF(image_options);
2359+
qobject_unref(image_options);
23602360
goto done;
23612361
}
23622362

@@ -2449,7 +2449,7 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
24492449
obj = NULL;
24502450

24512451
fail:
2452-
qobject_decref(obj);
2452+
qobject_unref(obj);
24532453
visit_free(v);
24542454
return bs;
24552455
}
@@ -2519,7 +2519,7 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
25192519
}
25202520

25212521
out:
2522-
QDECREF(snapshot_options);
2522+
qobject_unref(snapshot_options);
25232523
g_free(tmp_filename);
25242524
return bs_snapshot;
25252525
}
@@ -2530,7 +2530,7 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
25302530
* options is a QDict of options to pass to the block drivers, or NULL for an
25312531
* empty set of options. The reference to the QDict belongs to the block layer
25322532
* after the call (even on failure), so if the caller intends to reuse the
2533-
* dictionary, it needs to use QINCREF() before calling bdrv_open.
2533+
* dictionary, it needs to use qobject_ref() before calling bdrv_open.
25342534
*
25352535
* If *pbs is NULL, a new BDS will be created with a pointer to it stored there.
25362536
* If it is not NULL, the referenced BDS will be reused.
@@ -2561,7 +2561,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
25612561

25622562
if (reference) {
25632563
bool options_non_empty = options ? qdict_size(options) : false;
2564-
QDECREF(options);
2564+
qobject_unref(options);
25652565

25662566
if (filename || options_non_empty) {
25672567
error_setg(errp, "Cannot reference an existing block device with "
@@ -2752,7 +2752,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
27522752

27532753
bdrv_parent_cb_change_media(bs, true);
27542754

2755-
QDECREF(options);
2755+
qobject_unref(options);
27562756

27572757
/* For snapshot=on, create a temporary qcow2 overlay. bs points to the
27582758
* temporary snapshot afterwards. */
@@ -2776,10 +2776,10 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
27762776

27772777
fail:
27782778
blk_unref(file);
2779-
QDECREF(snapshot_options);
2780-
QDECREF(bs->explicit_options);
2781-
QDECREF(bs->options);
2782-
QDECREF(options);
2779+
qobject_unref(snapshot_options);
2780+
qobject_unref(bs->explicit_options);
2781+
qobject_unref(bs->options);
2782+
qobject_unref(options);
27832783
bs->options = NULL;
27842784
bs->explicit_options = NULL;
27852785
bdrv_unref(bs);
@@ -2788,8 +2788,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
27882788

27892789
close_and_fail:
27902790
bdrv_unref(bs);
2791-
QDECREF(snapshot_options);
2792-
QDECREF(options);
2791+
qobject_unref(snapshot_options);
2792+
qobject_unref(options);
27932793
error_propagate(errp, local_err);
27942794
return NULL;
27952795
}
@@ -2884,7 +2884,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,
28842884
old_options = qdict_clone_shallow(bs->explicit_options);
28852885
}
28862886
bdrv_join_options(bs, options, old_options);
2887-
QDECREF(old_options);
2887+
qobject_unref(old_options);
28882888

28892889
explicit_options = qdict_clone_shallow(options);
28902890

@@ -2899,13 +2899,13 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,
28992899
qemu_opts_absorb_qdict(opts, options_copy, NULL);
29002900
update_flags_from_options(&flags, opts);
29012901
qemu_opts_del(opts);
2902-
QDECREF(options_copy);
2902+
qobject_unref(options_copy);
29032903
}
29042904

29052905
/* Old values are used for options that aren't set yet */
29062906
old_options = qdict_clone_shallow(bs->options);
29072907
bdrv_join_options(bs, options, old_options);
2908-
QDECREF(old_options);
2908+
qobject_unref(old_options);
29092909

29102910
/* bdrv_open_inherit() sets and clears some additional flags internally */
29112911
flags &= ~BDRV_O_PROTOCOL;
@@ -2917,8 +2917,8 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,
29172917
bs_entry = g_new0(BlockReopenQueueEntry, 1);
29182918
QSIMPLEQ_INSERT_TAIL(bs_queue, bs_entry, entry);
29192919
} else {
2920-
QDECREF(bs_entry->state.options);
2921-
QDECREF(bs_entry->state.explicit_options);
2920+
qobject_unref(bs_entry->state.options);
2921+
qobject_unref(bs_entry->state.explicit_options);
29222922
}
29232923

29242924
bs_entry->state.bs = bs;
@@ -3008,9 +3008,9 @@ int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **er
30083008
if (ret && bs_entry->prepared) {
30093009
bdrv_reopen_abort(&bs_entry->state);
30103010
} else if (ret) {
3011-
QDECREF(bs_entry->state.explicit_options);
3011+
qobject_unref(bs_entry->state.explicit_options);
30123012
}
3013-
QDECREF(bs_entry->state.options);
3013+
qobject_unref(bs_entry->state.options);
30143014
g_free(bs_entry);
30153015
}
30163016
g_free(bs_queue);
@@ -3253,7 +3253,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state)
32533253
}
32543254

32553255
/* set BDS specific flags now */
3256-
QDECREF(bs->explicit_options);
3256+
qobject_unref(bs->explicit_options);
32573257

32583258
bs->explicit_options = reopen_state->explicit_options;
32593259
bs->open_flags = reopen_state->flags;
@@ -3296,7 +3296,7 @@ void bdrv_reopen_abort(BDRVReopenState *reopen_state)
32963296
drv->bdrv_reopen_abort(reopen_state);
32973297
}
32983298

3299-
QDECREF(reopen_state->explicit_options);
3299+
qobject_unref(reopen_state->explicit_options);
33003300

33013301
bdrv_abort_perm_update(reopen_state->bs);
33023302
}
@@ -3343,11 +3343,11 @@ static void bdrv_close(BlockDriverState *bs)
33433343
bs->total_sectors = 0;
33443344
bs->encrypted = false;
33453345
bs->sg = false;
3346-
QDECREF(bs->options);
3347-
QDECREF(bs->explicit_options);
3346+
qobject_unref(bs->options);
3347+
qobject_unref(bs->explicit_options);
33483348
bs->options = NULL;
33493349
bs->explicit_options = NULL;
3350-
QDECREF(bs->full_open_options);
3350+
qobject_unref(bs->full_open_options);
33513351
bs->full_open_options = NULL;
33523352

33533353
bdrv_release_named_dirty_bitmaps(bs);
@@ -5134,7 +5134,7 @@ static bool append_open_options(QDict *d, BlockDriverState *bs)
51345134
continue;
51355135
}
51365136

5137-
qobject_incref(qdict_entry_value(entry));
5137+
qobject_ref(qdict_entry_value(entry));
51385138
qdict_put_obj(d, qdict_entry_key(entry), qdict_entry_value(entry));
51395139
found_any = true;
51405140
}
@@ -5174,21 +5174,21 @@ void bdrv_refresh_filename(BlockDriverState *bs)
51745174
* information before refreshing it */
51755175
bs->exact_filename[0] = '\0';
51765176
if (bs->full_open_options) {
5177-
QDECREF(bs->full_open_options);
5177+
qobject_unref(bs->full_open_options);
51785178
bs->full_open_options = NULL;
51795179
}
51805180

51815181
opts = qdict_new();
51825182
append_open_options(opts, bs);
51835183
drv->bdrv_refresh_filename(bs, opts);
5184-
QDECREF(opts);
5184+
qobject_unref(opts);
51855185
} else if (bs->file) {
51865186
/* Try to reconstruct valid information from the underlying file */
51875187
bool has_open_options;
51885188

51895189
bs->exact_filename[0] = '\0';
51905190
if (bs->full_open_options) {
5191-
QDECREF(bs->full_open_options);
5191+
qobject_unref(bs->full_open_options);
51925192
bs->full_open_options = NULL;
51935193
}
51945194

@@ -5207,12 +5207,12 @@ void bdrv_refresh_filename(BlockDriverState *bs)
52075207
* suffices without querying the (exact_)filename of this BDS. */
52085208
if (bs->file->bs->full_open_options) {
52095209
qdict_put_str(opts, "driver", drv->format_name);
5210-
QINCREF(bs->file->bs->full_open_options);
5210+
qobject_ref(bs->file->bs->full_open_options);
52115211
qdict_put(opts, "file", bs->file->bs->full_open_options);
52125212

52135213
bs->full_open_options = opts;
52145214
} else {
5215-
QDECREF(opts);
5215+
qobject_unref(opts);
52165216
}
52175217
} else if (!bs->full_open_options && qdict_size(bs->options)) {
52185218
/* There is no underlying file BDS (at least referenced by BDS.file),
@@ -5246,7 +5246,7 @@ void bdrv_refresh_filename(BlockDriverState *bs)
52465246
QString *json = qobject_to_json(QOBJECT(bs->full_open_options));
52475247
snprintf(bs->filename, sizeof(bs->filename), "json:%s",
52485248
qstring_get_str(json));
5249-
QDECREF(json);
5249+
qobject_unref(json);
52505250
}
52515251
}
52525252

block/blkdebug.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -845,12 +845,12 @@ static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
845845
opts = qdict_new();
846846
qdict_put_str(opts, "driver", "blkdebug");
847847

848-
QINCREF(bs->file->bs->full_open_options);
848+
qobject_ref(bs->file->bs->full_open_options);
849849
qdict_put(opts, "image", bs->file->bs->full_open_options);
850850

851851
for (e = qdict_first(options); e; e = qdict_next(options, e)) {
852852
if (strcmp(qdict_entry_key(e), "x-image")) {
853-
qobject_incref(qdict_entry_value(e));
853+
qobject_ref(qdict_entry_value(e));
854854
qdict_put_obj(opts, qdict_entry_key(e), qdict_entry_value(e));
855855
}
856856
}

block/blkverify.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options)
291291
QDict *opts = qdict_new();
292292
qdict_put_str(opts, "driver", "blkverify");
293293

294-
QINCREF(bs->file->bs->full_open_options);
294+
qobject_ref(bs->file->bs->full_open_options);
295295
qdict_put(opts, "raw", bs->file->bs->full_open_options);
296-
QINCREF(s->test_file->bs->full_open_options);
296+
qobject_ref(s->test_file->bs->full_open_options);
297297
qdict_put(opts, "test", s->test_file->bs->full_open_options);
298298

299299
bs->full_open_options = opts;

block/crypto.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,
305305

306306
ret = 0;
307307
cleanup:
308-
QDECREF(cryptoopts);
308+
qobject_unref(cryptoopts);
309309
qapi_free_QCryptoBlockOpenOptions(open_opts);
310310
return ret;
311311
}
@@ -635,7 +635,7 @@ static int coroutine_fn block_crypto_co_create_opts_luks(const char *filename,
635635
fail:
636636
bdrv_unref(bs);
637637
qapi_free_QCryptoBlockCreateOptions(create_opts);
638-
QDECREF(cryptoopts);
638+
qobject_unref(cryptoopts);
639639
return ret;
640640
}
641641

block/gluster.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
650650
}
651651
gsconf = NULL;
652652

653-
QDECREF(backing_options);
653+
qobject_unref(backing_options);
654654
backing_options = NULL;
655655
g_free(str);
656656
str = NULL;
@@ -663,7 +663,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
663663
qapi_free_SocketAddress(gsconf);
664664
qemu_opts_del(opts);
665665
g_free(str);
666-
QDECREF(backing_options);
666+
qobject_unref(backing_options);
667667
errno = EINVAL;
668668
return -errno;
669669
}

block/iscsi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ static int coroutine_fn iscsi_co_create_opts(const char *filename, QemuOpts *opt
21432143
} else {
21442144
ret = iscsi_open(bs, bs_options, 0, NULL);
21452145
}
2146-
QDECREF(bs_options);
2146+
qobject_unref(bs_options);
21472147

21482148
if (ret != 0) {
21492149
goto out;

block/nbd.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
293293
}
294294

295295
done:
296-
QDECREF(addr);
297-
qobject_decref(crumpled_addr);
296+
qobject_unref(addr);
297+
qobject_unref(crumpled_addr);
298298
visit_free(iv);
299299
return saddr;
300300
}

block/nfs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options,
567567
v = qobject_input_visitor_new_keyval(crumpled);
568568
visit_type_BlockdevOptionsNfs(v, NULL, &opts, &local_err);
569569
visit_free(v);
570-
qobject_decref(crumpled);
570+
qobject_unref(crumpled);
571571

572572
if (local_err) {
573573
return NULL;
@@ -683,7 +683,7 @@ static int coroutine_fn nfs_file_co_create_opts(const char *url, QemuOpts *opts,
683683

684684
ret = 0;
685685
out:
686-
QDECREF(options);
686+
qobject_unref(options);
687687
qapi_free_BlockdevCreateOptions(create_options);
688688
return ret;
689689
}

block/null.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static int coroutine_fn null_co_block_status(BlockDriverState *bs,
244244

245245
static void null_refresh_filename(BlockDriverState *bs, QDict *opts)
246246
{
247-
QINCREF(opts);
247+
qobject_ref(opts);
248248
qdict_del(opts, "filename");
249249

250250
if (!qdict_size(opts)) {

0 commit comments

Comments
 (0)