From patchwork Wed May 4 09:39:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9011971 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DEFA79F1C1 for ; Wed, 4 May 2016 09:46:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA3702038F for ; Wed, 4 May 2016 09:46:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A58612038D for ; Wed, 4 May 2016 09:46:51 +0000 (UTC) Received: from localhost ([::1]:46686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axtOJ-0000Ms-Rx for patchwork-qemu-devel@patchwork.kernel.org; Wed, 04 May 2016 05:46:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axtIX-00061I-5U for qemu-devel@nongnu.org; Wed, 04 May 2016 05:40:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1axtIF-0005v8-Mw for qemu-devel@nongnu.org; Wed, 04 May 2016 05:40:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52967) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axtHv-0005d7-O0; Wed, 04 May 2016 05:40:11 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A4C662678; Wed, 4 May 2016 09:39:55 +0000 (UTC) Received: from noname.str.redhat.com. (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u449dYeA000875; Wed, 4 May 2016 05:39:53 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 4 May 2016 11:39:23 +0200 Message-Id: <1462354765-14037-13-git-send-email-kwolf@redhat.com> In-Reply-To: <1462354765-14037-1-git-send-email-kwolf@redhat.com> References: <1462354765-14037-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 04 May 2016 09:39:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/14] backup: Use BlockBackend for I/O X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berto@igalia.com, jcody@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This changes the backup block job to use the job's BlockBackend for performing its I/O. job->bs isn't used by the backup code any more afterwards. Signed-off-by: Kevin Wolf --- block/backup.c | 42 ++++++++++++++++++++++-------------------- block/block-backend.c | 14 ++++++++++++++ block/io.c | 9 --------- blockdev.c | 4 +--- include/block/block.h | 2 -- include/sysemu/block-backend.h | 2 ++ trace-events | 2 +- 7 files changed, 40 insertions(+), 35 deletions(-) diff --git a/block/backup.c b/block/backup.c index 670ba50..ba9eb42 100644 --- a/block/backup.c +++ b/block/backup.c @@ -36,7 +36,7 @@ typedef struct CowRequest { typedef struct BackupBlockJob { BlockJob common; - BlockDriverState *target; + BlockBackend *target; /* bitmap for sync=incremental */ BdrvDirtyBitmap *sync_bitmap; MirrorSyncMode sync_mode; @@ -99,7 +99,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job, bool *error_is_read, bool is_write_notifier) { - BlockDriverState *bs = job->common.bs; + BlockBackend *blk = job->common.blk; CowRequest cow_request; struct iovec iov; QEMUIOVector bounce_qiov; @@ -132,19 +132,18 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job, start * sectors_per_cluster); if (!bounce_buffer) { - bounce_buffer = qemu_blockalign(bs, job->cluster_size); + bounce_buffer = blk_blockalign(blk, job->cluster_size); } iov.iov_base = bounce_buffer; iov.iov_len = n * BDRV_SECTOR_SIZE; qemu_iovec_init_external(&bounce_qiov, &iov, 1); if (is_write_notifier) { - ret = bdrv_co_readv_no_serialising(bs, - start * sectors_per_cluster, - n, &bounce_qiov); + ret = blk_co_readv_no_serialising(blk, start * sectors_per_cluster, + n, &bounce_qiov); } else { - ret = bdrv_co_readv(bs, start * sectors_per_cluster, n, - &bounce_qiov); + ret = blk_co_readv(blk, start * sectors_per_cluster, n, + &bounce_qiov); } if (ret < 0) { trace_backup_do_cow_read_fail(job, start, ret); @@ -155,13 +154,13 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job, } if (buffer_is_zero(iov.iov_base, iov.iov_len)) { - ret = bdrv_co_write_zeroes(job->target, + ret = blk_co_write_zeroes(job->target, start * sectors_per_cluster, n, BDRV_REQ_MAY_UNMAP); } else { - ret = bdrv_co_writev(job->target, - start * sectors_per_cluster, n, - &bounce_qiov); + ret = blk_co_writev(job->target, + start * sectors_per_cluster, n, + &bounce_qiov); } if (ret < 0) { trace_backup_do_cow_write_fail(job, start, ret); @@ -203,7 +202,7 @@ static int coroutine_fn backup_before_write_notify( int64_t sector_num = req->offset >> BDRV_SECTOR_BITS; int nb_sectors = req->bytes >> BDRV_SECTOR_BITS; - assert(req->bs == job->common.bs); + assert(req->bs == blk_bs(job->common.blk)); assert((req->offset & (BDRV_SECTOR_SIZE - 1)) == 0); assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) == 0); @@ -224,7 +223,7 @@ static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp) static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret) { BdrvDirtyBitmap *bm; - BlockDriverState *bs = job->common.bs; + BlockDriverState *bs = blk_bs(job->common.blk); if (ret < 0 || block_job_is_cancelled(&job->common)) { /* Merge the successor back into the parent, delete nothing. */ @@ -282,7 +281,7 @@ static void backup_complete(BlockJob *job, void *opaque) BackupBlockJob *s = container_of(job, BackupBlockJob, common); BackupCompleteData *data = opaque; - bdrv_unref(s->target); + blk_unref(s->target); block_job_completed(job, data->ret); g_free(data); @@ -378,8 +377,8 @@ static void coroutine_fn backup_run(void *opaque) { BackupBlockJob *job = opaque; BackupCompleteData *data; - BlockDriverState *bs = job->common.bs; - BlockDriverState *target = job->target; + BlockDriverState *bs = blk_bs(job->common.blk); + BlockBackend *target = job->target; int64_t start, end; int64_t sectors_per_cluster = cluster_size_sectors(job); int ret = 0; @@ -468,7 +467,7 @@ static void coroutine_fn backup_run(void *opaque) qemu_co_rwlock_unlock(&job->flush_rwlock); g_free(job->done_bitmap); - bdrv_op_unblock_all(target, job->common.blocker); + bdrv_op_unblock_all(blk_bs(target), job->common.blocker); data = g_malloc(sizeof(*data)); data->ret = ret; @@ -548,9 +547,11 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target, goto error; } + job->target = blk_new(&error_abort); + blk_insert_bs(job->target, target); + job->on_source_error = on_source_error; job->on_target_error = on_target_error; - job->target = target; job->sync_mode = sync_mode; job->sync_bitmap = sync_mode == MIRROR_SYNC_MODE_INCREMENTAL ? sync_bitmap : NULL; @@ -558,7 +559,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target, /* If there is no backing file on the target, we cannot rely on COW if our * backup cluster size is smaller than the target cluster size. Even for * targets with a backing file, try to avoid COW if possible. */ - ret = bdrv_get_info(job->target, &bdi); + ret = bdrv_get_info(target, &bdi); if (ret < 0 && !target->backing) { error_setg_errno(errp, -ret, "Couldn't determine the cluster size of the target image, " @@ -585,6 +586,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target, bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL); } if (job) { + blk_unref(job->target); block_job_unref(&job->common); } } diff --git a/block/block-backend.c b/block/block-backend.c index 8dc3aa5..2b3c55f 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -807,6 +807,20 @@ int coroutine_fn blk_co_readv(BlockBackend *blk, int64_t sector_num, nb_sectors << BDRV_SECTOR_BITS, qiov, 0); } +int coroutine_fn blk_co_readv_no_serialising(BlockBackend *blk, + int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) +{ + trace_blk_co_readv_no_serialising(blk, blk_bs(blk), sector_num, nb_sectors); + + if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { + return -EINVAL; + } + + return blk_co_preadv(blk, sector_num << BDRV_SECTOR_BITS, + nb_sectors << BDRV_SECTOR_BITS, qiov, + BDRV_REQ_NO_SERIALISING); +} + int coroutine_fn blk_co_copy_on_readv(BlockBackend *blk, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { diff --git a/block/io.c b/block/io.c index 8280e14..eeb0e4c 100644 --- a/block/io.c +++ b/block/io.c @@ -1093,15 +1093,6 @@ int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, return bdrv_co_do_readv(bs, sector_num, nb_sectors, qiov, 0); } -int coroutine_fn bdrv_co_readv_no_serialising(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) -{ - trace_bdrv_co_readv_no_serialising(bs, sector_num, nb_sectors); - - return bdrv_co_do_readv(bs, sector_num, nb_sectors, qiov, - BDRV_REQ_NO_SERIALISING); -} - #define MAX_WRITE_ZEROES_BOUNCE_BUFFER 32768 static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, diff --git a/blockdev.c b/blockdev.c index 7a0196f..fa381ce 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3268,8 +3268,8 @@ static void do_drive_backup(const char *device, const char *target, backup_start(bs, target_bs, speed, sync, bmap, on_source_error, on_target_error, block_job_cb, bs, txn, &local_err); + bdrv_unref(target_bs); if (local_err != NULL) { - bdrv_unref(target_bs); error_propagate(errp, local_err); goto out; } @@ -3353,12 +3353,10 @@ void do_blockdev_backup(const char *device, const char *target, } target_bs = blk_bs(target_blk); - bdrv_ref(target_bs); bdrv_set_aio_context(target_bs, aio_context); backup_start(bs, target_bs, speed, sync, NULL, on_source_error, on_target_error, block_job_cb, bs, txn, &local_err); if (local_err != NULL) { - bdrv_unref(target_bs); error_propagate(errp, local_err); } out: diff --git a/include/block/block.h b/include/block/block.h index 39b5812..8e7d348 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -243,8 +243,6 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset, const void *buf, int count); int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); -int coroutine_fn bdrv_co_readv_no_serialising(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); /* diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index d98552c..715fd9e 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -118,6 +118,8 @@ int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf, int nb_sectors); int coroutine_fn blk_co_readv(BlockBackend *blk, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); +int coroutine_fn blk_co_readv_no_serialising(BlockBackend *blk, + int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn blk_co_copy_on_readv(BlockBackend *blk, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn blk_co_writev(BlockBackend *blk, int64_t sector_num, diff --git a/trace-events b/trace-events index 3b5cce3..2ee3cb7 100644 --- a/trace-events +++ b/trace-events @@ -65,6 +65,7 @@ bdrv_lock_medium(void *bs, bool locked) "bs %p locked %d" blk_co_readv(void *blk, void *bs, int64_t sector_num, int nb_sector) "blk %p bs %p sector_num %"PRId64" nb_sectors %d" blk_co_writev(void *blk, void *bs, int64_t sector_num, int nb_sector) "blk %p bs %p sector_num %"PRId64" nb_sectors %d" blk_co_copy_on_readv(void *blk, void *bs, int64_t sector_num, int nb_sector) "blk %p bs %p sector_num %"PRId64" nb_sectors %d" +blk_co_readv_no_serialising(void *blk, void *bs, int64_t sector_num, int nb_sector) "blk %p bs %p sector_num %"PRId64" nb_sectors %d" # block/io.c bdrv_aio_discard(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" @@ -73,7 +74,6 @@ bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs % bdrv_aio_writev(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" bdrv_aio_write_zeroes(void *bs, int64_t sector_num, int nb_sectors, int flags, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d flags %#x opaque %p" bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" -bdrv_co_readv_no_serialising(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" bdrv_co_write_zeroes(void *bs, int64_t sector_num, int nb_sector, int flags) "bs %p sector_num %"PRId64" nb_sectors %d flags %#x" bdrv_co_do_copy_on_readv(void *bs, int64_t sector_num, int nb_sectors, int64_t cluster_sector_num, int cluster_nb_sectors) "bs %p sector_num %"PRId64" nb_sectors %d cluster_sector_num %"PRId64" cluster_nb_sectors %d"