[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/51] block: Add bdrv_make_empty()
From: |
Kevin Wolf |
Subject: |
[PULL 08/51] block: Add bdrv_make_empty() |
Date: |
Fri, 15 May 2020 14:44:38 +0200 |
From: Max Reitz <address@hidden>
Right now, all users of bdrv_make_empty() call the BlockDriver method
directly. That is not only bad style, it is also wrong, unless the
caller has a BdrvChild with a WRITE or WRITE_UNCHANGED permission.
(WRITE_UNCHANGED suffices, because callers generally use this function
to clear a node with a backing file after a commit operation.)
Introduce bdrv_make_empty() that verifies that it does.
Signed-off-by: Max Reitz <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/block/block.h | 1 +
block.c | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/block/block.h b/include/block/block.h
index 4de8d8f8a6..8f3eb70df4 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -352,6 +352,7 @@ BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts
*opts,
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
void bdrv_refresh_limits(BlockDriverState *bs, Error **errp);
int bdrv_commit(BlockDriverState *bs);
+int bdrv_make_empty(BdrvChild *c, Error **errp);
int bdrv_change_backing_file(BlockDriverState *bs,
const char *backing_file, const char *backing_fmt);
void bdrv_register(BlockDriver *bdrv);
diff --git a/block.c b/block.c
index 0653ccb913..c6a5c144b7 100644
--- a/block.c
+++ b/block.c
@@ -6764,3 +6764,26 @@ void bdrv_del_child(BlockDriverState *parent_bs,
BdrvChild *child, Error **errp)
parent_bs->drv->bdrv_del_child(parent_bs, child, errp);
}
+
+int bdrv_make_empty(BdrvChild *c, Error **errp)
+{
+ BlockDriver *drv = c->bs->drv;
+ int ret;
+
+ assert(c->perm & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED));
+
+ if (!drv->bdrv_make_empty) {
+ error_setg(errp, "%s does not support emptying nodes",
+ drv->format_name);
+ return -ENOTSUP;
+ }
+
+ ret = drv->bdrv_make_empty(c->bs);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Failed to empty %s",
+ c->bs->filename);
+ return ret;
+ }
+
+ return 0;
+}
--
2.25.4
- [PULL 00/51] Block layer patches, Kevin Wolf, 2020/05/15
- [PULL 02/51] iotests/229: Use blkdebug to inject an error, Kevin Wolf, 2020/05/15
- [PULL 01/51] iotests/109: Don't mirror with mismatched size, Kevin Wolf, 2020/05/15
- [PULL 03/51] mirror: Make sure that source and target size match, Kevin Wolf, 2020/05/15
- [PULL 05/51] block/replication.c: Avoid cancelling the job twice, Kevin Wolf, 2020/05/15
- [PULL 04/51] iotests: Mirror with different source/target size, Kevin Wolf, 2020/05/15
- [PULL 06/51] iotests: Fix incomplete type declarations, Kevin Wolf, 2020/05/15
- [PULL 07/51] iotests: Run pylint and mypy in a testcase, Kevin Wolf, 2020/05/15
- [PULL 11/51] replication: Avoid blk_make_empty() on read-only child, Kevin Wolf, 2020/05/15
- [PULL 08/51] block: Add bdrv_make_empty(),
Kevin Wolf <=
- [PULL 09/51] block: Add blk_make_empty(), Kevin Wolf, 2020/05/15
- [PULL 12/51] block: Use bdrv_make_empty() where possible, Kevin Wolf, 2020/05/15
- [PULL 10/51] block: Use blk_make_empty() after commits, Kevin Wolf, 2020/05/15
- [PULL 13/51] block: Mark commit, mirror, blkreplay as filters, Kevin Wolf, 2020/05/15
- [PULL 16/51] block: Add BdrvChildRole and BdrvChildRoleBits, Kevin Wolf, 2020/05/15
- [PULL 20/51] block: Pass parent_is_format to .inherit_options(), Kevin Wolf, 2020/05/15
- [PULL 21/51] block: Rename bdrv_inherited_options(), Kevin Wolf, 2020/05/15
- [PULL 23/51] block: Use bdrv_inherited_options(), Kevin Wolf, 2020/05/15
- [PULL 14/51] block: Add BlockDriver.is_format, Kevin Wolf, 2020/05/15
- [PULL 15/51] block: Rename BdrvChildRole to BdrvChildClass, Kevin Wolf, 2020/05/15