cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ddf19c
From 23b92512d7f11b3a38cf24a5c2fe7848f1e550e8 Mon Sep 17 00:00:00 2001
ddf19c
From: Maxim Levitsky <mlevitsk@redhat.com>
ddf19c
Date: Sun, 31 May 2020 16:40:34 +0100
ddf19c
Subject: [PATCH 6/7] block.c: adding bdrv_co_delete_file
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-3-mlevitsk@redhat.com>
ddf19c
Patchwork-id: 97058
ddf19c
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 2/3] block.c: adding bdrv_co_delete_file
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
Using the new 'bdrv_co_delete_file' interface, a pure co_routine function
ddf19c
'bdrv_co_delete_file' inside block.c can can be used in a way similar of
ddf19c
the existing bdrv_create_file to to clean up a created file.
ddf19c
ddf19c
We're creating a pure co_routine because the only caller of
ddf19c
'bdrv_co_delete_file' will be already in co_routine context, thus there
ddf19c
is no need to add all the machinery to check for qemu_in_coroutine() and
ddf19c
create a separated co_routine to do the job.
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-3-danielhb413@gmail.com>
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
(cherry picked from commit e1d7f8bb1ec0c6911dcea81641ce6139dbded02d)
ddf19c
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 block.c               | 26 ++++++++++++++++++++++++++
ddf19c
 include/block/block.h |  1 +
ddf19c
 2 files changed, 27 insertions(+)
ddf19c
ddf19c
diff --git a/block.c b/block.c
ddf19c
index ba3b40d7..d6a05da 100644
ddf19c
--- a/block.c
ddf19c
+++ b/block.c
ddf19c
@@ -672,6 +672,32 @@ int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp)
ddf19c
     return bdrv_create(drv, filename, opts, errp);
ddf19c
 }
ddf19c
 
ddf19c
+int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)
ddf19c
+{
ddf19c
+    Error *local_err = NULL;
ddf19c
+    int ret;
ddf19c
+
ddf19c
+    assert(bs != NULL);
ddf19c
+
ddf19c
+    if (!bs->drv) {
ddf19c
+        error_setg(errp, "Block node '%s' is not opened", bs->filename);
ddf19c
+        return -ENOMEDIUM;
ddf19c
+    }
ddf19c
+
ddf19c
+    if (!bs->drv->bdrv_co_delete_file) {
ddf19c
+        error_setg(errp, "Driver '%s' does not support image deletion",
ddf19c
+                   bs->drv->format_name);
ddf19c
+        return -ENOTSUP;
ddf19c
+    }
ddf19c
+
ddf19c
+    ret = bs->drv->bdrv_co_delete_file(bs, &local_err);
ddf19c
+    if (ret < 0) {
ddf19c
+        error_propagate(errp, local_err);
ddf19c
+    }
ddf19c
+
ddf19c
+    return ret;
ddf19c
+}
ddf19c
+
ddf19c
 /**
ddf19c
  * Try to get @bs's logical and physical block size.
ddf19c
  * On success, store them in @bsz struct and return 0.
ddf19c
diff --git a/include/block/block.h b/include/block/block.h
ddf19c
index 92685d2..b2a3074 100644
ddf19c
--- a/include/block/block.h
ddf19c
+++ b/include/block/block.h
ddf19c
@@ -373,6 +373,7 @@ bool bdrv_is_backing_chain_frozen(BlockDriverState *bs, BlockDriverState *base,
ddf19c
 int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base,
ddf19c
                               Error **errp);
ddf19c
 void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *base);
ddf19c
+int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp);
ddf19c
 
ddf19c
 
ddf19c
 typedef struct BdrvCheckResult {
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c