From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, jcody@redhat.com,
jsnow@redhat.com, berto@igalia.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 09/14] backup: Pack Notifier within BackupBlockJob
Date: Wed, 4 May 2016 11:39:20 +0200 [thread overview]
Message-ID: <1462354765-14037-10-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1462354765-14037-1-git-send-email-kwolf@redhat.com>
From: John Snow <jsnow@redhat.com>
Instead of relying on peeking at bs->job, we want to explicitly get
a reference to the job that was involved in this notifier callback.
Pack the Notifier inside of the BackupBlockJob so we can use
container_of to get a reference back to the BackupBlockJob object.
This cuts out one more case where we rely unnecessarily on bs->job.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/backup.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/block/backup.c b/block/backup.c
index a990cf1..a57288f 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -47,6 +47,7 @@ typedef struct BackupBlockJob {
uint64_t sectors_read;
unsigned long *done_bitmap;
int64_t cluster_size;
+ NotifierWithReturn before_write;
QLIST_HEAD(, CowRequest) inflight_reqs;
} BackupBlockJob;
@@ -94,11 +95,11 @@ static void cow_request_end(CowRequest *req)
}
static int coroutine_fn backup_do_cow(BlockDriverState *bs,
+ BackupBlockJob *job,
int64_t sector_num, int nb_sectors,
bool *error_is_read,
bool is_write_notifier)
{
- BackupBlockJob *job = (BackupBlockJob *)bs->job;
CowRequest cow_request;
struct iovec iov;
QEMUIOVector bounce_qiov;
@@ -197,6 +198,7 @@ static int coroutine_fn backup_before_write_notify(
NotifierWithReturn *notifier,
void *opaque)
{
+ BackupBlockJob *job = container_of(notifier, BackupBlockJob, before_write);
BdrvTrackedRequest *req = opaque;
int64_t sector_num = req->offset >> BDRV_SECTOR_BITS;
int nb_sectors = req->bytes >> BDRV_SECTOR_BITS;
@@ -204,7 +206,8 @@ static int coroutine_fn backup_before_write_notify(
assert((req->offset & (BDRV_SECTOR_SIZE - 1)) == 0);
assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
- return backup_do_cow(req->bs, sector_num, nb_sectors, NULL, true);
+ return backup_do_cow(req->bs, job, sector_num,
+ nb_sectors, NULL, true);
}
static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp)
@@ -343,7 +346,7 @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job)
if (yield_and_check(job)) {
return ret;
}
- ret = backup_do_cow(bs, cluster * sectors_per_cluster,
+ ret = backup_do_cow(bs, job, cluster * sectors_per_cluster,
sectors_per_cluster, &error_is_read,
false);
if ((ret < 0) &&
@@ -378,9 +381,6 @@ static void coroutine_fn backup_run(void *opaque)
BackupCompleteData *data;
BlockDriverState *bs = job->common.bs;
BlockDriverState *target = job->target;
- NotifierWithReturn before_write = {
- .notify = backup_before_write_notify,
- };
int64_t start, end;
int64_t sectors_per_cluster = cluster_size_sectors(job);
int ret = 0;
@@ -393,7 +393,8 @@ static void coroutine_fn backup_run(void *opaque)
job->done_bitmap = bitmap_new(end);
- bdrv_add_before_write_notifier(bs, &before_write);
+ job->before_write.notify = backup_before_write_notify;
+ bdrv_add_before_write_notifier(bs, &job->before_write);
if (job->sync_mode == MIRROR_SYNC_MODE_NONE) {
while (!block_job_is_cancelled(&job->common)) {
@@ -445,7 +446,7 @@ static void coroutine_fn backup_run(void *opaque)
}
}
/* FULL sync mode we copy the whole drive. */
- ret = backup_do_cow(bs, start * sectors_per_cluster,
+ ret = backup_do_cow(bs, job, start * sectors_per_cluster,
sectors_per_cluster, &error_is_read, false);
if (ret < 0) {
/* Depending on error action, fail now or retry cluster */
@@ -461,7 +462,7 @@ static void coroutine_fn backup_run(void *opaque)
}
}
- notifier_with_return_remove(&before_write);
+ notifier_with_return_remove(&job->before_write);
/* wait until pending backup_do_cow() calls have completed */
qemu_co_rwlock_wrlock(&job->flush_rwlock);
--
1.8.3.1
next prev parent reply other threads:[~2016-05-04 9:40 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-04 9:39 [Qemu-devel] [PATCH 00/14] block jobs: Convert I/O to BlockBackend Kevin Wolf
2016-05-04 9:39 ` [Qemu-devel] [PATCH 01/14] block: keep a list of block jobs Kevin Wolf
2016-05-13 13:09 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 02/14] block: Cancel jobs first in bdrv_close_all() Kevin Wolf
2016-05-06 9:17 ` Alberto Garcia
2016-05-13 13:14 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 03/14] block: Default to enabled write cache in blk_new() Kevin Wolf
2016-05-13 13:24 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 04/14] block: Convert block job core to BlockBackend Kevin Wolf
2016-05-13 13:45 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 05/14] stream: Use BlockBackend for I/O Kevin Wolf
2016-05-13 14:03 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 06/14] mirror: Allow target that already has a BlockBackend Kevin Wolf
2016-05-13 14:18 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 07/14] mirror: Use BlockBackend for I/O Kevin Wolf
2016-05-13 14:38 ` Max Reitz
2016-05-13 14:38 ` Max Reitz
2016-05-13 14:57 ` Eric Blake
2016-05-04 9:39 ` [Qemu-devel] [PATCH 08/14] backup: Don't leak BackupBlockJob in error path Kevin Wolf
2016-05-09 13:21 ` Alberto Garcia
2016-05-13 14:46 ` Max Reitz
2016-05-04 9:39 ` Kevin Wolf [this message]
2016-05-13 15:01 ` [Qemu-devel] [PATCH 09/14] backup: Pack Notifier within BackupBlockJob Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 10/14] backup: Remove bs parameter from backup_do_cow() Kevin Wolf
2016-05-13 15:06 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 11/14] block: Add blk_co_readv/writev() Kevin Wolf
2016-05-13 15:12 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 12/14] backup: Use BlockBackend for I/O Kevin Wolf
2016-05-13 15:25 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 13/14] commit: " Kevin Wolf
2016-05-13 15:36 ` Max Reitz
2016-05-04 9:39 ` [Qemu-devel] [PATCH 14/14] blockjob: Remove BlockJob.bs Kevin Wolf
2016-05-13 15:37 ` Max Reitz
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=1462354765-14037-10-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=berto@igalia.com \
--cc=jcody@redhat.com \
--cc=jsnow@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.