virshStreamInData: Handle block devices

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>
This commit is contained in:
Michal Privoznik 2020-07-02 15:51:20 +02:00
parent 6e0306fa26
commit 9e0ba037cd

View 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;
}