yeahuh / rpms / qemu-kvm

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