[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/13] block.c: adding bdrv_co_delete_file
From: |
Kevin Wolf |
Subject: |
[PULL 11/13] block.c: adding bdrv_co_delete_file |
Date: |
Wed, 11 Mar 2020 16:42:16 +0100 |
From: Daniel Henrique Barboza <address@hidden>
Using the new 'bdrv_co_delete_file' interface, a pure co_routine function
'bdrv_co_delete_file' inside block.c can can be used in a way similar of
the existing bdrv_create_file to to clean up a created file.
We're creating a pure co_routine because the only caller of
'bdrv_co_delete_file' will be already in co_routine context, thus there
is no need to add all the machinery to check for qemu_in_coroutine() and
create a separated co_routine to do the job.
Suggested-by: Daniel P. Berrangé <address@hidden>
Signed-off-by: Daniel Henrique Barboza <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/block/block.h | 1 +
block.c | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/include/block/block.h b/include/block/block.h
index cd6b5b95aa..e569a4d747 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -363,6 +363,7 @@ bool bdrv_is_backing_chain_frozen(BlockDriverState *bs,
BlockDriverState *base,
int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base,
Error **errp);
void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *base);
+int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp);
typedef struct BdrvCheckResult {
diff --git a/block.c b/block.c
index 8fc7b56937..a2542c977b 100644
--- a/block.c
+++ b/block.c
@@ -668,6 +668,32 @@ int bdrv_create_file(const char *filename, QemuOpts *opts,
Error **errp)
}
}
+int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)
+{
+ Error *local_err = NULL;
+ int ret;
+
+ assert(bs != NULL);
+
+ if (!bs->drv) {
+ error_setg(errp, "Block node '%s' is not opened", bs->filename);
+ return -ENOMEDIUM;
+ }
+
+ if (!bs->drv->bdrv_co_delete_file) {
+ error_setg(errp, "Driver '%s' does not support image deletion",
+ bs->drv->format_name);
+ return -ENOTSUP;
+ }
+
+ ret = bs->drv->bdrv_co_delete_file(bs, &local_err);
+ if (ret < 0) {
+ error_propagate(errp, local_err);
+ }
+
+ return ret;
+}
+
/**
* Try to get @bs's logical and physical block size.
* On success, store them in @bsz struct and return 0.
--
2.20.1
- [PULL 03/13] block: Relax restrictions for blockdev-snapshot, (continued)
- [PULL 03/13] block: Relax restrictions for blockdev-snapshot, Kevin Wolf, 2020/03/11
- [PULL 05/13] iotests: Test mirror with temporarily disabled target backing file, Kevin Wolf, 2020/03/11
- [PULL 06/13] block: Fix cross-AioContext blockdev-snapshot, Kevin Wolf, 2020/03/11
- [PULL 02/13] block: Make bdrv_get_cumulative_perm() public, Kevin Wolf, 2020/03/11
- [PULL 08/13] qapi: Add '@allow-write-only-overlay' feature for 'blockdev-snapshot', Kevin Wolf, 2020/03/11
- [PULL 07/13] iotests: Add iothread cases to 155, Kevin Wolf, 2020/03/11
- [PULL 09/13] tests/qemu-iotests: Fix socket_scm_helper build path, Kevin Wolf, 2020/03/11
- [PULL 12/13] crypto.c: cleanup created file when block_crypto_co_create_opts_luks fails, Kevin Wolf, 2020/03/11
- [PULL 10/13] block: introducing 'bdrv_co_delete_file' interface, Kevin Wolf, 2020/03/11
- [PULL 13/13] qemu-iotests: adding LUKS cleanup for non-UTF8 secret error, Kevin Wolf, 2020/03/11
- [PULL 11/13] block.c: adding bdrv_co_delete_file,
Kevin Wolf <=
- Re: [PULL 00/13] Block layer patches, Peter Maydell, 2020/03/12
- Re: [PULL 00/13] Block layer patches, Peter Maydell, 2020/03/12