[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/11] block: add bdrv_co_delete_file_noerr
From: |
Kevin Wolf |
Subject: |
[PULL 08/11] block: add bdrv_co_delete_file_noerr |
Date: |
Mon, 15 Feb 2021 16:00:57 +0100 |
From: Maxim Levitsky <mlevitsk@redhat.com>
This function wraps bdrv_co_delete_file for the common case of removing a file,
which was just created by format driver, on an error condition.
It hides the -ENOTSUPP error, and reports all other errors otherwise.
Use it in luks driver
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-Id: <20201217170904.946013-3-mlevitsk@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/block.h | 1 +
block.c | 22 ++++++++++++++++++++++
block/crypto.c | 15 ++-------------
3 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/include/block/block.h b/include/block/block.h
index a9b7f03f11..b3f6e509d4 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -441,6 +441,7 @@ 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);
+void coroutine_fn bdrv_co_delete_file_noerr(BlockDriverState *bs);
typedef struct BdrvCheckResult {
diff --git a/block.c b/block.c
index c682c3e3b9..a1f3cecd75 100644
--- a/block.c
+++ b/block.c
@@ -706,6 +706,28 @@ int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs,
Error **errp)
return ret;
}
+void coroutine_fn bdrv_co_delete_file_noerr(BlockDriverState *bs)
+{
+ Error *local_err = NULL;
+ int ret;
+
+ if (!bs) {
+ return;
+ }
+
+ ret = bdrv_co_delete_file(bs, &local_err);
+ /*
+ * ENOTSUP will happen if the block driver doesn't support
+ * the 'bdrv_co_delete_file' interface. This is a predictable
+ * scenario and shouldn't be reported back to the user.
+ */
+ if (ret == -ENOTSUP) {
+ error_free(local_err);
+ } else if (ret < 0) {
+ error_report_err(local_err);
+ }
+}
+
/**
* Try to get @bs's logical and physical block size.
* On success, store them in @bsz struct and return 0.
diff --git a/block/crypto.c b/block/crypto.c
index b3a5275132..1d30fde38e 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -725,19 +725,8 @@ fail:
* If an error occurred, delete 'filename'. Even if the file existed
* beforehand, it has been truncated and corrupted in the process.
*/
- if (ret && bs) {
- Error *local_delete_err = NULL;
- int r_del = bdrv_co_delete_file(bs, &local_delete_err);
- /*
- * ENOTSUP will happen if the block driver doesn't support
- * the 'bdrv_co_delete_file' interface. This is a predictable
- * scenario and shouldn't be reported back to the user.
- */
- if ((r_del < 0) && (r_del != -ENOTSUP)) {
- error_report_err(local_delete_err);
- } else {
- error_free(local_delete_err);
- }
+ if (ret) {
+ bdrv_co_delete_file_noerr(bs);
}
bdrv_unref(bs);
--
2.29.2
- [PULL 00/11] Block layer patches, Kevin Wolf, 2021/02/15
- [PULL 04/11] hw/ide/ahci: map cmd_fis as DMA_DIRECTION_TO_DEVICE, Kevin Wolf, 2021/02/15
- [PULL 01/11] qemu-storage-daemon: Enable object-add, Kevin Wolf, 2021/02/15
- [PULL 05/11] xen-block: fix reporting of discard feature, Kevin Wolf, 2021/02/15
- [PULL 09/11] block: qcow2: remove the created file on initialization error, Kevin Wolf, 2021/02/15
- [PULL 06/11] tests/qemu-iotests: Remove test 259 from the "auto" group, Kevin Wolf, 2021/02/15
- [PULL 03/11] blockjob: Fix crash with IOthread when block commit after snapshot, Kevin Wolf, 2021/02/15
- [PULL 10/11] monitor: Fix assertion failure on shutdown, Kevin Wolf, 2021/02/15
- [PULL 07/11] crypto: luks: Fix tiny memory leak, Kevin Wolf, 2021/02/15
- [PULL 08/11] block: add bdrv_co_delete_file_noerr,
Kevin Wolf <=
- [PULL 11/11] monitor/qmp: Stop processing requests when shutdown is requested, Kevin Wolf, 2021/02/15
- [PULL 02/11] iotests: Consistent $IMGOPTS boundary matching, Kevin Wolf, 2021/02/15
- Re: [PULL 00/11] Block layer patches, Peter Maydell, 2021/02/15