From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFHso-00038j-8E for qemu-devel@nongnu.org; Tue, 21 Jun 2016 05:22:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFHsm-0000H5-G4 for qemu-devel@nongnu.org; Tue, 21 Jun 2016 05:22:10 -0400 From: Kevin Wolf Date: Tue, 21 Jun 2016 11:21:26 +0200 Message-Id: <1466500894-9710-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1466500894-9710-1-git-send-email-kwolf@redhat.com> References: <1466500894-9710-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 09/17] block: Move bdrv_commit() to block/commit.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, famz@redhat.com, mreitz@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org No code changes, just moved from one file to another. Signed-off-by: Kevin Wolf --- block.c | 110 --------------------------------------------------- block/Makefile.objs | 3 +- block/commit.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 112 deletions(-) diff --git a/block.c b/block.c index b331eb9..160324a 100644 --- a/block.c +++ b/block.c @@ -2331,116 +2331,6 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix) return bs->drv->bdrv_check(bs, res, fix); } -#define COMMIT_BUF_SECTORS 2048 - -/* commit COW file into the raw image */ -int bdrv_commit(BlockDriverState *bs) -{ - BlockDriver *drv = bs->drv; - int64_t sector, total_sectors, length, backing_length; - int n, ro, open_flags; - int ret = 0; - uint8_t *buf = NULL; - - if (!drv) - return -ENOMEDIUM; - - if (!bs->backing) { - return -ENOTSUP; - } - - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT_SOURCE, NULL) || - bdrv_op_is_blocked(bs->backing->bs, BLOCK_OP_TYPE_COMMIT_TARGET, NULL)) { - return -EBUSY; - } - - ro = bs->backing->bs->read_only; - open_flags = bs->backing->bs->open_flags; - - if (ro) { - if (bdrv_reopen(bs->backing->bs, open_flags | BDRV_O_RDWR, NULL)) { - return -EACCES; - } - } - - length = bdrv_getlength(bs); - if (length < 0) { - ret = length; - goto ro_cleanup; - } - - backing_length = bdrv_getlength(bs->backing->bs); - if (backing_length < 0) { - ret = backing_length; - goto ro_cleanup; - } - - /* If our top snapshot is larger than the backing file image, - * grow the backing file image if possible. If not possible, - * we must return an error */ - if (length > backing_length) { - ret = bdrv_truncate(bs->backing->bs, length); - if (ret < 0) { - goto ro_cleanup; - } - } - - total_sectors = length >> BDRV_SECTOR_BITS; - - /* qemu_try_blockalign() for bs will choose an alignment that works for - * bs->backing->bs as well, so no need to compare the alignment manually. */ - buf = qemu_try_blockalign(bs, COMMIT_BUF_SECTORS * BDRV_SECTOR_SIZE); - if (buf == NULL) { - ret = -ENOMEM; - goto ro_cleanup; - } - - for (sector = 0; sector < total_sectors; sector += n) { - ret = bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n); - if (ret < 0) { - goto ro_cleanup; - } - if (ret) { - ret = bdrv_read(bs, sector, buf, n); - if (ret < 0) { - goto ro_cleanup; - } - - ret = bdrv_write(bs->backing->bs, sector, buf, n); - if (ret < 0) { - goto ro_cleanup; - } - } - } - - if (drv->bdrv_make_empty) { - ret = drv->bdrv_make_empty(bs); - if (ret < 0) { - goto ro_cleanup; - } - bdrv_flush(bs); - } - - /* - * Make sure all data we wrote to the backing device is actually - * stable on disk. - */ - if (bs->backing) { - bdrv_flush(bs->backing->bs); - } - - ret = 0; -ro_cleanup: - qemu_vfree(buf); - - if (ro) { - /* ignoring error return here */ - bdrv_reopen(bs->backing->bs, open_flags & ~BDRV_O_RDWR, NULL); - } - - return ret; -} - /* * Return values: * 0 - success diff --git a/block/Makefile.objs b/block/Makefile.objs index 44a5416..2593a2f 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -9,7 +9,7 @@ block-obj-y += block-backend.o snapshot.o qapi.o block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o block-obj-$(CONFIG_POSIX) += raw-posix.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o -block-obj-y += null.o mirror.o io.o +block-obj-y += null.o mirror.o commit.o io.o block-obj-y += throttle-groups.o block-obj-y += nbd.o nbd-client.o sheepdog.o @@ -26,7 +26,6 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o common-obj-y += stream.o -common-obj-y += commit.o common-obj-y += backup.o iscsi.o-cflags := $(LIBISCSI_CFLAGS) diff --git a/block/commit.c b/block/commit.c index 444333b..4ac3df3 100644 --- a/block/commit.c +++ b/block/commit.c @@ -282,3 +282,114 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base, trace_commit_start(bs, base, top, s, s->common.co, opaque); qemu_coroutine_enter(s->common.co, s); } + + +#define COMMIT_BUF_SECTORS 2048 + +/* commit COW file into the raw image */ +int bdrv_commit(BlockDriverState *bs) +{ + BlockDriver *drv = bs->drv; + int64_t sector, total_sectors, length, backing_length; + int n, ro, open_flags; + int ret = 0; + uint8_t *buf = NULL; + + if (!drv) + return -ENOMEDIUM; + + if (!bs->backing) { + return -ENOTSUP; + } + + if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT_SOURCE, NULL) || + bdrv_op_is_blocked(bs->backing->bs, BLOCK_OP_TYPE_COMMIT_TARGET, NULL)) { + return -EBUSY; + } + + ro = bs->backing->bs->read_only; + open_flags = bs->backing->bs->open_flags; + + if (ro) { + if (bdrv_reopen(bs->backing->bs, open_flags | BDRV_O_RDWR, NULL)) { + return -EACCES; + } + } + + length = bdrv_getlength(bs); + if (length < 0) { + ret = length; + goto ro_cleanup; + } + + backing_length = bdrv_getlength(bs->backing->bs); + if (backing_length < 0) { + ret = backing_length; + goto ro_cleanup; + } + + /* If our top snapshot is larger than the backing file image, + * grow the backing file image if possible. If not possible, + * we must return an error */ + if (length > backing_length) { + ret = bdrv_truncate(bs->backing->bs, length); + if (ret < 0) { + goto ro_cleanup; + } + } + + total_sectors = length >> BDRV_SECTOR_BITS; + + /* qemu_try_blockalign() for bs will choose an alignment that works for + * bs->backing->bs as well, so no need to compare the alignment manually. */ + buf = qemu_try_blockalign(bs, COMMIT_BUF_SECTORS * BDRV_SECTOR_SIZE); + if (buf == NULL) { + ret = -ENOMEM; + goto ro_cleanup; + } + + for (sector = 0; sector < total_sectors; sector += n) { + ret = bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n); + if (ret < 0) { + goto ro_cleanup; + } + if (ret) { + ret = bdrv_read(bs, sector, buf, n); + if (ret < 0) { + goto ro_cleanup; + } + + ret = bdrv_write(bs->backing->bs, sector, buf, n); + if (ret < 0) { + goto ro_cleanup; + } + } + } + + if (drv->bdrv_make_empty) { + ret = drv->bdrv_make_empty(bs); + if (ret < 0) { + goto ro_cleanup; + } + bdrv_flush(bs); + } + + /* + * Make sure all data we wrote to the backing device is actually + * stable on disk. + */ + if (bs->backing) { + bdrv_flush(bs->backing->bs); + } + + ret = 0; +ro_cleanup: + qemu_vfree(buf); + + if (ro) { + /* ignoring error return here */ + bdrv_reopen(bs->backing->bs, open_flags & ~BDRV_O_RDWR, NULL); + } + + return ret; +} -- 1.8.3.1