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(a)redhat.com>
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>
---
tools/virsh-util.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/tools/virsh-util.c b/tools/virsh-util.c
index 884261eb49..d78a196cc6 100644
--- a/tools/virsh-util.c
+++ b/tools/virsh-util.c
@@ -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;
}
--
2.26.2