block: Add blk_make_empty()
authorMax Reitz <mreitz@redhat.com>
Wed, 29 Apr 2020 14:11:25 +0000 (16:11 +0200)
committerKevin Wolf <kwolf@redhat.com>
Mon, 18 May 2020 17:05:25 +0000 (19:05 +0200)
Two callers of BlockDriver.bdrv_make_empty() remain that should not call
this method directly.  Both do not have access to a BdrvChild, but they
can use a BlockBackend, so we add this function that lets them use it.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200429141126.85159-4-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/block-backend.c
include/sysemu/block-backend.h

index f4944861fa4e44222466de796936d81b65f3e963..47bd56244d35d52d5549002aa0ac1cc868020737 100644 (file)
@@ -2402,3 +2402,13 @@ const BdrvChild *blk_root(BlockBackend *blk)
 {
     return blk->root;
 }
+
+int blk_make_empty(BlockBackend *blk, Error **errp)
+{
+    if (!blk_is_available(blk)) {
+        error_setg(errp, "No medium inserted");
+        return -ENOMEDIUM;
+    }
+
+    return bdrv_make_empty(blk->root, errp);
+}
index 0917663d89f4582bc20f7587187a9ccd6bb08ad7..8203d7f6f90c792ca3f70e516909d3fe1d266cce 100644 (file)
@@ -266,4 +266,6 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
 
 const BdrvChild *blk_root(BlockBackend *blk);
 
+int blk_make_empty(BlockBackend *blk, Error **errp);
+
 #endif