[PATCH 8/9] virshStreamInData: Handle block devices

Michal Privoznik mprivozn at redhat.com
Fri Jul 3 10:28:49 UTC 2020


This is very similar to previous commit.

The virshStreamInData() callback is used by virStreamSparseSendAll()
to detect whether the file the data is read from is in data or hole
section. The SendAll() will then send corresponding type of virStream
message to make server create a hole or write actual data. But the
callback uses virFileInData() even for block devices, which results in
an error. Switch to virFileInDataDetectZeroes() for block devices.

Partially resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1852528

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tools/virsh-util.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/virsh-util.c b/tools/virsh-util.c
index 884261eb49..867f69577f 100644
--- a/tools/virsh-util.c
+++ b/tools/virsh-util.c
@@ -230,12 +230,20 @@ virshStreamInData(virStreamPtr st G_GNUC_UNUSED,
     virshStreamCallbackDataPtr cbData = opaque;
     vshControl *ctl = cbData->ctl;
     int fd = cbData->fd;
-    int ret;
 
-    if ((ret = virFileInData(fd, inData, offset)) < 0)
-        vshError(ctl, "%s", _("Unable to get current position in stream"));
+    if (cbData->isBlock) {
+        if (virFileInDataDetectZeroes(fd, inData, offset) < 0) {
+            vshError(ctl, "%s", _("Unable to get current position in stream"));
+            return -1;
+        }
+    } else {
+        if (virFileInData(fd, inData, offset) < 0) {
+            vshError(ctl, "%s", _("Unable to get current position in stream"));
+            return -1;
+        }
+    }
 
-    return ret;
+    return 0;
 }
 
 
-- 
2.26.2




More information about the libvir-list mailing list