@@ -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,
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(-)