thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-introducing-bdrv_co_delete_file-interface.patch

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