|
|
77c23f |
From 9581770f48911cbe68cfa1a7fa125df2a0a27d02 Mon Sep 17 00:00:00 2001
|
|
|
77c23f |
From: Maxim Levitsky <mlevitsk@redhat.com>
|
|
|
77c23f |
Date: Sun, 31 May 2020 16:40:33 +0100
|
|
|
77c23f |
Subject: [PATCH 5/7] block: introducing 'bdrv_co_delete_file' interface
|
|
|
77c23f |
MIME-Version: 1.0
|
|
|
77c23f |
Content-Type: text/plain; charset=UTF-8
|
|
|
77c23f |
Content-Transfer-Encoding: 8bit
|
|
|
77c23f |
|
|
|
77c23f |
RH-Author: Maxim Levitsky <mlevitsk@redhat.com>
|
|
|
77c23f |
Message-id: <20200531164035.34188-2-mlevitsk@redhat.com>
|
|
|
77c23f |
Patchwork-id: 97057
|
|
|
77c23f |
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 1/3] block: introducing 'bdrv_co_delete_file' interface
|
|
|
77c23f |
Bugzilla: 1827630
|
|
|
77c23f |
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
|
|
|
77c23f |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
77c23f |
RH-Acked-by: Eric Blake <eblake@redhat.com>
|
|
|
77c23f |
|
|
|
77c23f |
From: Daniel Henrique Barboza <danielhb413@gmail.com>
|
|
|
77c23f |
|
|
|
77c23f |
Adding to Block Drivers the capability of being able to clean up
|
|
|
77c23f |
its created files can be useful in certain situations. For the
|
|
|
77c23f |
LUKS driver, for instance, a failure in one of its authentication
|
|
|
77c23f |
steps can leave files in the host that weren't there before.
|
|
|
77c23f |
|
|
|
77c23f |
This patch adds the 'bdrv_co_delete_file' interface to block
|
|
|
77c23f |
drivers and add it to the 'file' driver in file-posix.c. The
|
|
|
77c23f |
implementation is given by 'raw_co_delete_file'.
|
|
|
77c23f |
|
|
|
77c23f |
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
77c23f |
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
|
|
|
77c23f |
Message-Id: <20200130213907.2830642-2-danielhb413@gmail.com>
|
|
|
77c23f |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
77c23f |
(cherry picked from commit 9bffae14df879255329473a7bd578643af2d4c9c)
|
|
|
77c23f |
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
|
|
|
77c23f |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
77c23f |
---
|
|
|
77c23f |
block/file-posix.c | 23 +++++++++++++++++++++++
|
|
|
77c23f |
include/block/block_int.h | 4 ++++
|
|
|
77c23f |
2 files changed, 27 insertions(+)
|
|
|
77c23f |
|
|
|
77c23f |
diff --git a/block/file-posix.c b/block/file-posix.c
|
|
|
77c23f |
index dd18d40..1609598 100644
|
|
|
77c23f |
--- a/block/file-posix.c
|
|
|
77c23f |
+++ b/block/file-posix.c
|
|
|
77c23f |
@@ -2388,6 +2388,28 @@ static int coroutine_fn raw_co_create_opts(BlockDriver *drv,
|
|
|
77c23f |
return raw_co_create(&options, errp);
|
|
|
77c23f |
}
|
|
|
77c23f |
|
|
|
77c23f |
+static int coroutine_fn raw_co_delete_file(BlockDriverState *bs,
|
|
|
77c23f |
+ Error **errp)
|
|
|
77c23f |
+{
|
|
|
77c23f |
+ struct stat st;
|
|
|
77c23f |
+ int ret;
|
|
|
77c23f |
+
|
|
|
77c23f |
+ if (!(stat(bs->filename, &st) == 0) || !S_ISREG(st.st_mode)) {
|
|
|
77c23f |
+ error_setg_errno(errp, ENOENT, "%s is not a regular file",
|
|
|
77c23f |
+ bs->filename);
|
|
|
77c23f |
+ return -ENOENT;
|
|
|
77c23f |
+ }
|
|
|
77c23f |
+
|
|
|
77c23f |
+ ret = unlink(bs->filename);
|
|
|
77c23f |
+ if (ret < 0) {
|
|
|
77c23f |
+ ret = -errno;
|
|
|
77c23f |
+ error_setg_errno(errp, -ret, "Error when deleting file %s",
|
|
|
77c23f |
+ bs->filename);
|
|
|
77c23f |
+ }
|
|
|
77c23f |
+
|
|
|
77c23f |
+ return ret;
|
|
|
77c23f |
+}
|
|
|
77c23f |
+
|
|
|
77c23f |
/*
|
|
|
77c23f |
* Find allocation range in @bs around offset @start.
|
|
|
77c23f |
* May change underlying file descriptor's file offset.
|
|
|
77c23f |
@@ -3019,6 +3041,7 @@ BlockDriver bdrv_file = {
|
|
|
77c23f |
.bdrv_co_block_status = raw_co_block_status,
|
|
|
77c23f |
.bdrv_co_invalidate_cache = raw_co_invalidate_cache,
|
|
|
77c23f |
.bdrv_co_pwrite_zeroes = raw_co_pwrite_zeroes,
|
|
|
77c23f |
+ .bdrv_co_delete_file = raw_co_delete_file,
|
|
|
77c23f |
|
|
|
77c23f |
.bdrv_co_preadv = raw_co_preadv,
|
|
|
77c23f |
.bdrv_co_pwritev = raw_co_pwritev,
|
|
|
77c23f |
diff --git a/include/block/block_int.h b/include/block/block_int.h
|
|
|
77c23f |
index 529f153..562dca1 100644
|
|
|
77c23f |
--- a/include/block/block_int.h
|
|
|
77c23f |
+++ b/include/block/block_int.h
|
|
|
77c23f |
@@ -316,6 +316,10 @@ struct BlockDriver {
|
|
|
77c23f |
*/
|
|
|
77c23f |
int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs);
|
|
|
77c23f |
|
|
|
77c23f |
+ /* Delete a created file. */
|
|
|
77c23f |
+ int coroutine_fn (*bdrv_co_delete_file)(BlockDriverState *bs,
|
|
|
77c23f |
+ Error **errp);
|
|
|
77c23f |
+
|
|
|
77c23f |
/*
|
|
|
77c23f |
* Flushes all data that was already written to the OS all the way down to
|
|
|
77c23f |
* the disk (for example file-posix.c calls fsync()).
|
|
|
77c23f |
--
|
|
|
77c23f |
1.8.3.1
|
|
|
77c23f |
|