[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 13/14] block/file-posix: implement .bdrv_close_safe
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH 13/14] block/file-posix: implement .bdrv_close_safe |
Date: |
Mon, 7 Feb 2022 17:37:27 +0100 |
Implement new close API for 'file' driver, so that we now have the
minimal set working: qcow2 + file.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/file-posix.c | 38 +++++++++++++++++++++++++++++++-------
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 1f1756e192..90642d8185 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2195,14 +2195,38 @@ static void raw_aio_attach_aio_context(BlockDriverState
*bs,
#endif
}
-static void raw_close(BlockDriverState *bs)
+static void raw_close_commit(void *opaque)
+{
+ BDRVRawState *s = opaque;
+
+ if (s->fd >= 0) {
+ /*
+ * Closing fd is unrecoverable action, that's why it is in .commit.
+ * So, yes, it may fail, but we ignore the failure.
+ */
+ qemu_close(s->fd);
+ s->fd = -1;
+ }
+}
+
+TransactionActionDrv raw_close_drv = {
+ .commit = raw_close_commit,
+};
+
+static int raw_close_safe(BlockDriverState *bs, Transaction *tran,
+ Error **errp)
{
BDRVRawState *s = bs->opaque;
if (s->fd >= 0) {
- qemu_close(s->fd);
- s->fd = -1;
+ if (tran) {
+ tran_add(tran, &raw_close_drv, s);
+ } else {
+ raw_close_commit(s);
+ }
}
+
+ return 0;
}
/**
@@ -3278,7 +3302,7 @@ BlockDriver bdrv_file = {
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
- .bdrv_close = raw_close,
+ .bdrv_close_safe = raw_close_safe,
.bdrv_co_create = raw_co_create,
.bdrv_co_create_opts = raw_co_create_opts,
.bdrv_has_zero_init = bdrv_has_zero_init_1,
@@ -3643,7 +3667,7 @@ static BlockDriver bdrv_host_device = {
.bdrv_probe_device = hdev_probe_device,
.bdrv_parse_filename = hdev_parse_filename,
.bdrv_file_open = hdev_open,
- .bdrv_close = raw_close,
+ .bdrv_close_safe = raw_close_safe,
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
@@ -3771,7 +3795,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_probe_device = cdrom_probe_device,
.bdrv_parse_filename = cdrom_parse_filename,
.bdrv_file_open = cdrom_open,
- .bdrv_close = raw_close,
+ .bdrv_close_safe = raw_close_safe,
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
@@ -3902,7 +3926,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_probe_device = cdrom_probe_device,
.bdrv_parse_filename = cdrom_parse_filename,
.bdrv_file_open = cdrom_open,
- .bdrv_close = raw_close,
+ .bdrv_close_safe = raw_close_safe,
.bdrv_reopen_prepare = raw_reopen_prepare,
.bdrv_reopen_commit = raw_reopen_commit,
.bdrv_reopen_abort = raw_reopen_abort,
--
2.31.1
- [PATCH 02/14] block: drop bdrv_detach_child(), (continued)
- [PATCH 02/14] block: drop bdrv_detach_child(), Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 01/14] block: refactor bdrv_remove_file_or_backing_child to bdrv_remove_child, Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 04/14] block: add bdrv_try_set_aio_context_tran transaction action, Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 10/14] qcow2: qcow2_inactivate(): don't call qcow2_mark_clean() when RO, Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 14/14] iotests: add test for blockdev-del(force=false), Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 06/14] block: bdrv_delete(): drop unnecessary zeroing, Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 08/14] qapi/block-core: add 'force' argument to blockdev-del, Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 03/14] block: bdrv_refresh_perms(): allow external tran, Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 05/14] block: merge bdrv_delete and bdrv_close, Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 12/14] qcow2: implement .bdrv_close_safe, Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 13/14] block/file-posix: implement .bdrv_close_safe,
Vladimir Sementsov-Ogievskiy <=
- [PATCH 09/14] qcow2: qcow2_inactivate(): use qcow2_flush_caches(), Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 07/14] block: implemet bdrv_try_unref(), Vladimir Sementsov-Ogievskiy, 2022/02/07
- [PATCH 11/14] qcow2: refactor qcow2_inactivate, Vladimir Sementsov-Ogievskiy, 2022/02/07