block: add bdrv_co_delete_file_noerr
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>
This commit is contained in:
parent
dcb6699512
commit
a890f08e58
22
block.c
22
block.c
@ -706,6 +706,28 @@ int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)
|
|||||||
return ret;
|
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.
|
* Try to get @bs's logical and physical block size.
|
||||||
* On success, store them in @bsz struct and return 0.
|
* On success, store them in @bsz struct and return 0.
|
||||||
|
@ -725,19 +725,8 @@ fail:
|
|||||||
* If an error occurred, delete 'filename'. Even if the file existed
|
* If an error occurred, delete 'filename'. Even if the file existed
|
||||||
* beforehand, it has been truncated and corrupted in the process.
|
* beforehand, it has been truncated and corrupted in the process.
|
||||||
*/
|
*/
|
||||||
if (ret && bs) {
|
if (ret) {
|
||||||
Error *local_delete_err = NULL;
|
bdrv_co_delete_file_noerr(bs);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bdrv_unref(bs);
|
bdrv_unref(bs);
|
||||||
|
@ -441,6 +441,7 @@ int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base,
|
|||||||
Error **errp);
|
Error **errp);
|
||||||
void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *base);
|
void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *base);
|
||||||
int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp);
|
int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp);
|
||||||
|
void coroutine_fn bdrv_co_delete_file_noerr(BlockDriverState *bs);
|
||||||
|
|
||||||
|
|
||||||
typedef struct BdrvCheckResult {
|
typedef struct BdrvCheckResult {
|
||||||
|
Loading…
Reference in New Issue
Block a user