From: John Snow <jsnow@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: jcody@redhat.com
Subject: Re: [Qemu-devel] [PATCH 03/10] blockjob: introduce block_job_fail
Date: Fri, 7 Apr 2017 19:24:18 -0400 [thread overview]
Message-ID: <410edac6-737f-d341-b2a3-8979528b3ba4@redhat.com> (raw)
In-Reply-To: <20170323173928.14439-4-pbonzini@redhat.com>
On 03/23/2017 01:39 PM, Paolo Bonzini wrote:
> Outside blockjob.c, block_job_unref is only used when a block job fails
> to start, and block_job_ref is not used at all. The reference counting
> thus is pretty well hidden. Introduce a separate function to be used
> by block jobs; because block_job_ref and block_job_unref now become
> static, move them earlier in blockjob.c.
>
Early into the series, "I guess so."
It makes it a lot less obvious and more vague as to what exactly is
happening here, so I like it less.
> Later on, block_job_fail will also have different locking than
> block_job_unref.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> block/backup.c | 2 +-
> block/commit.c | 2 +-
> block/mirror.c | 2 +-
> blockjob.c | 47 ++++++++++++++++++++++++++------------------
> include/block/blockjob_int.h | 15 +++-----------
> tests/test-blockjob.c | 10 +++++-----
> 6 files changed, 39 insertions(+), 39 deletions(-)
>
> diff --git a/block/backup.c b/block/backup.c
> index a4fb288..f284fd5 100644
> --- a/block/backup.c
> +++ b/block/backup.c
> @@ -692,7 +692,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
> }
> if (job) {
> backup_clean(&job->common);
> - block_job_unref(&job->common);
> + block_job_fail(&job->common);
> }
>
> return NULL;
> diff --git a/block/commit.c b/block/commit.c
> index 2832482..9b9ea39 100644
> --- a/block/commit.c
> +++ b/block/commit.c
> @@ -424,7 +424,7 @@ fail:
> if (commit_top_bs) {
> bdrv_set_backing_hd(overlay_bs, top, &error_abort);
> }
> - block_job_unref(&s->common);
> + block_job_fail(&s->common);
> }
>
>
> diff --git a/block/mirror.c b/block/mirror.c
> index ca4baa5..5cb2134 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -1243,7 +1243,7 @@ fail:
> if (s) {
> g_free(s->replaces);
> blk_unref(s->target);
> - block_job_unref(&s->common);
> + block_job_fail(&s->common);
> }
>
> bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
> diff --git a/blockjob.c b/blockjob.c
> index 24d1e12..1c63d15 100644
> --- a/blockjob.c
> +++ b/blockjob.c
> @@ -106,6 +106,32 @@ BlockJob *block_job_get(const char *id)
> return NULL;
> }
>
> +static void block_job_ref(BlockJob *job)
> +{
> + ++job->refcnt;
> +}
> +
> +static void block_job_attached_aio_context(AioContext *new_context,
> + void *opaque);
> +static void block_job_detach_aio_context(void *opaque);
> +
^ Some tagalongs to the party?
> +static void block_job_unref(BlockJob *job)
> +{
> + if (--job->refcnt == 0) {
> + BlockDriverState *bs = blk_bs(job->blk);
> + bs->job = NULL;
> + block_job_remove_all_bdrv(job);
> + blk_remove_aio_context_notifier(job->blk,
> + block_job_attached_aio_context,
> + block_job_detach_aio_context, job);
> + blk_unref(job->blk);
> + error_free(job->blocker);
> + g_free(job->id);
> + QLIST_REMOVE(job, job_list);
> + g_free(job);
> + }
> +}
> +
> static void block_job_attached_aio_context(AioContext *new_context,
> void *opaque)
> {
> @@ -293,26 +319,9 @@ void block_job_start(BlockJob *job)
> qemu_coroutine_enter(job->co);
> }
>
> -void block_job_ref(BlockJob *job)
> -{
> - ++job->refcnt;
> -}
> -
> -void block_job_unref(BlockJob *job)
> +void block_job_fail(BlockJob *job)
> {
> - if (--job->refcnt == 0) {
> - BlockDriverState *bs = blk_bs(job->blk);
> - bs->job = NULL;
> - block_job_remove_all_bdrv(job);
> - blk_remove_aio_context_notifier(job->blk,
> - block_job_attached_aio_context,
> - block_job_detach_aio_context, job);
> - blk_unref(job->blk);
> - error_free(job->blocker);
> - g_free(job->id);
> - QLIST_REMOVE(job, job_list);
> - g_free(job);
> - }
> + block_job_unref(job);
> }
>
> static void block_job_completed_single(BlockJob *job)
> diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
> index bfcc5d1..97ffc43 100644
> --- a/include/block/blockjob_int.h
> +++ b/include/block/blockjob_int.h
> @@ -156,21 +156,12 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns);
> void block_job_yield(BlockJob *job);
>
> /**
> - * block_job_ref:
> + * block_job_fail:
> * @bs: The block device.
> *
> - * Grab a reference to the block job. Should be paired with block_job_unref.
> + * The block job could not be started, free it.
> */
> -void block_job_ref(BlockJob *job);
> -
> -/**
> - * block_job_unref:
> - * @bs: The block device.
> - *
> - * Release reference to the block job and release resources if it is the last
> - * reference.
> - */
> -void block_job_unref(BlockJob *job);
> +void block_job_fail(BlockJob *job);
>
> /**
> * block_job_completed:
> diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
> index 740e740..35bbbbc 100644
> --- a/tests/test-blockjob.c
> +++ b/tests/test-blockjob.c
> @@ -116,11 +116,11 @@ static void test_job_ids(void)
> job[1] = do_test_id(blk[1], "id0", false);
>
> /* But once job[0] finishes we can reuse its ID */
> - block_job_unref(job[0]);
> + block_job_fail(job[0]);
> job[1] = do_test_id(blk[1], "id0", true);
>
> /* No job ID specified, defaults to the backend name ('drive1') */
> - block_job_unref(job[1]);
> + block_job_fail(job[1]);
> job[1] = do_test_id(blk[1], NULL, true);
>
> /* Duplicate job ID */
> @@ -133,9 +133,9 @@ static void test_job_ids(void)
> /* This one is valid */
> job[2] = do_test_id(blk[2], "id_2", true);
>
> - block_job_unref(job[0]);
> - block_job_unref(job[1]);
> - block_job_unref(job[2]);
> + block_job_fail(job[0]);
> + block_job_fail(job[1]);
> + block_job_fail(job[2]);
>
> destroy_blk(blk[0]);
> destroy_blk(blk[1]);
>
Mechanically OK, of course. Allow me to discover my appetite for it
further into your series.
next prev parent reply other threads:[~2017-04-07 23:24 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-23 17:39 [Qemu-devel] [PATCH for-2.10 00/10] Preparation for block job mutex Paolo Bonzini
2017-03-23 17:39 ` [Qemu-devel] [PATCH 01/10] blockjob: remove unnecessary check Paolo Bonzini
2017-04-07 22:30 ` John Snow
2017-04-07 22:54 ` Philippe Mathieu-Daudé
2017-04-07 23:16 ` John Snow
2017-04-10 9:27 ` Stefan Hajnoczi
2017-03-23 17:39 ` [Qemu-devel] [PATCH 02/10] blockjob: remove iostatus_reset callback Paolo Bonzini
2017-04-07 23:12 ` John Snow
2017-04-08 0:18 ` Philippe Mathieu-Daudé
2017-04-10 9:27 ` Stefan Hajnoczi
2017-03-23 17:39 ` [Qemu-devel] [PATCH 03/10] blockjob: introduce block_job_fail Paolo Bonzini
2017-04-07 23:24 ` John Snow [this message]
2017-04-10 9:22 ` Stefan Hajnoczi
2017-04-11 4:00 ` Paolo Bonzini
2017-03-23 17:39 ` [Qemu-devel] [PATCH 04/10] blockjob: introduce block_job_pause/resume_all Paolo Bonzini
2017-04-07 23:37 ` John Snow
2017-04-10 9:26 ` Stefan Hajnoczi
2017-03-23 17:39 ` [Qemu-devel] [PATCH 05/10] blockjob: separate monitor and blockjob APIs Paolo Bonzini
2017-04-08 0:03 ` John Snow
2017-04-08 9:52 ` Paolo Bonzini
2017-04-10 16:05 ` John Snow
2017-04-11 4:57 ` Paolo Bonzini
2017-04-11 16:19 ` John Snow
2017-04-10 9:30 ` Stefan Hajnoczi
2017-03-23 17:39 ` [Qemu-devel] [PATCH 06/10] blockjob: move iostatus reset inside block_job_user_resume Paolo Bonzini
2017-04-08 0:28 ` John Snow
2017-04-10 9:33 ` Stefan Hajnoczi
2017-03-23 17:39 ` [Qemu-devel] [PATCH 07/10] blockjob: strengthen a bit test-blockjob-txn Paolo Bonzini
2017-04-08 0:37 ` John Snow
2017-04-10 9:35 ` Stefan Hajnoczi
2017-03-23 17:39 ` [Qemu-devel] [PATCH 08/10] blockjob: introduce block_job_cancel_async Paolo Bonzini
2017-04-08 1:13 ` John Snow
2017-04-08 9:54 ` Paolo Bonzini
2017-04-10 9:36 ` Stefan Hajnoczi
2017-03-23 17:39 ` [Qemu-devel] [PATCH 09/10] blockjob: reorganize block_job_completed_txn_abort Paolo Bonzini
2017-04-08 1:15 ` John Snow
2017-04-08 10:03 ` Paolo Bonzini
2017-04-10 9:44 ` Stefan Hajnoczi
2017-04-10 19:17 ` John Snow
2017-04-11 4:11 ` Paolo Bonzini
2017-03-23 17:39 ` [Qemu-devel] [PATCH 10/10] blockjob: use deferred_to_main_loop to indicate the coroutine has ended Paolo Bonzini
2017-04-08 1:32 ` John Snow
2017-04-08 9:56 ` Paolo Bonzini
2017-04-10 9:46 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=410edac6-737f-d341-b2a3-8979528b3ba4@redhat.com \
--to=jsnow@redhat.com \
--cc=jcody@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).