mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-20 11:48:28 -06:00
Separate out code for sending tunnelled data
Simplify the doTunnelMigrate code by pulling out the code for sending all tunnelled data into separate helper * qemu/qemu_driver.c: introduce doTunnelSendAll() method
This commit is contained in:
parent
0d5600fd2f
commit
8d75cb7fde
@ -6469,6 +6469,40 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int doTunnelSendAll(virDomainPtr dom,
|
||||||
|
virStreamPtr st,
|
||||||
|
int sock)
|
||||||
|
{
|
||||||
|
char buffer[65536];
|
||||||
|
int nbytes = sizeof(buffer);
|
||||||
|
|
||||||
|
/* XXX should honour the 'resource' parameter here */
|
||||||
|
for (;;) {
|
||||||
|
nbytes = saferead(sock, buffer, nbytes);
|
||||||
|
if (nbytes < 0) {
|
||||||
|
virStreamAbort(st);
|
||||||
|
virReportSystemError(dom->conn, errno, "%s",
|
||||||
|
_("tunnelled migration failed to read from qemu"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (nbytes == 0)
|
||||||
|
/* EOF; get out of here */
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (virStreamSend(st, buffer, nbytes) < 0) {
|
||||||
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
||||||
|
_("Failed to write migration data to remote libvirtd"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virStreamFinish(st) < 0)
|
||||||
|
/* virStreamFinish set the error for us */
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int doTunnelMigrate(virDomainPtr dom,
|
static int doTunnelMigrate(virDomainPtr dom,
|
||||||
virConnectPtr dconn,
|
virConnectPtr dconn,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
@ -6485,7 +6519,6 @@ static int doTunnelMigrate(virDomainPtr dom,
|
|||||||
virDomainPtr ddomain;
|
virDomainPtr ddomain;
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
ssize_t bytes;
|
ssize_t bytes;
|
||||||
char buffer[65536];
|
|
||||||
virStreamPtr st;
|
virStreamPtr st;
|
||||||
char *unixfile = NULL;
|
char *unixfile = NULL;
|
||||||
int internalret;
|
int internalret;
|
||||||
@ -6594,34 +6627,8 @@ static int doTunnelMigrate(virDomainPtr dom,
|
|||||||
goto qemu_cancel_migration;
|
goto qemu_cancel_migration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retval = doTunnelSendAll(dom, st, client_sock);
|
||||||
|
|
||||||
/* XXX should honour the 'resource' parameter here */
|
|
||||||
for (;;) {
|
|
||||||
bytes = saferead(client_sock, buffer, sizeof(buffer));
|
|
||||||
if (bytes < 0) {
|
|
||||||
virStreamAbort(st);
|
|
||||||
virReportSystemError(dconn, errno, "%s",
|
|
||||||
_("tunnelled migration failed to read from qemu"));
|
|
||||||
goto close_client_sock;
|
|
||||||
}
|
|
||||||
else if (bytes == 0)
|
|
||||||
/* EOF; get out of here */
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (virStreamSend(st, buffer, bytes) < 0) {
|
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
|
||||||
_("Failed to write migration data to remote libvirtd"));
|
|
||||||
goto close_client_sock;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virStreamFinish(st) < 0)
|
|
||||||
/* virStreamFinish set the error for us */
|
|
||||||
goto close_client_sock;
|
|
||||||
|
|
||||||
retval = 0;
|
|
||||||
|
|
||||||
close_client_sock:
|
|
||||||
close(client_sock);
|
close(client_sock);
|
||||||
|
|
||||||
qemu_cancel_migration:
|
qemu_cancel_migration:
|
||||||
|
Loading…
Reference in New Issue
Block a user