]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virshStreamInData: Handle block devices
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 2 Jul 2020 13:51:20 +0000 (15:51 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 24 Aug 2020 11:39:55 +0000 (13:39 +0200)
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. Just like in previous commit, emulate a DATA section
for block devices.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
tools/virsh-util.c

index 884261eb49dc776a43e52a282dcf06d642d7ceae..d78a196cc67cb0fffa3ded5609eac163fd3dc0d5 100644 (file)
@@ -230,12 +230,25 @@ 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) {
+        /* Block devices are always in data section by definition. The
+         * @sectionLen is slightly more tricky. While we could try and get
+         * how much bytes is there left until EOF, we can pretend there is
+         * always X bytes left and let the saferead() below hit EOF (which
+         * is then handled gracefully anyway). Worst case scenario, this
+         * branch is called more than once.
+         * X was chosen to be 1MiB but it has ho special meaning. */
+        *inData = 1;
+        *offset = 1 * 1024 * 1024;
+    } else {
+        if (virFileInData(fd, inData, offset) < 0) {
+            vshError(ctl, "%s", _("Unable to get current position in stream"));
+            return -1;
+        }
+    }
 
-    return ret;
+    return 0;
 }