summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-20 14:58:04 +0100
committerRichard Jones <rjones@redhat.com>2009-04-20 14:58:04 +0100
commit4ce2b7b7fb949f584e4ad4b9d18121459be34a6a (patch)
tree17e46ad2e1d924f74b2c1c446f867aca797af180
parentc5d37435aa9e257fac1c2d517fadc7630fa0d869 (diff)
downloadlibguestfs-4ce2b7b7fb949f584e4ad4b9d18121459be34a6a.tar.gz
libguestfs-4ce2b7b7fb949f584e4ad4b9d18121459be34a6a.tar.xz
libguestfs-4ce2b7b7fb949f584e4ad4b9d18121459be34a6a.zip
Make daemon cancellation really work.
-rw-r--r--src/guestfs.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/guestfs.c b/src/guestfs.c
index 1b7d61ca..74fd76b0 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -1534,11 +1534,14 @@ guestfs__send_file_sync (guestfs_h *g, const char *filename)
/* Send file in chunked encoding. */
while (!cancel && (r = read (fd, buf, sizeof buf)) > 0) {
err = send_file_data_sync (g, buf, r);
- if (err < 0)
+ if (err < 0) {
+ if (err == -2) /* daemon sent cancellation */
+ send_file_cancellation_sync (g);
return err;
+ }
}
- if (cancel) {
+ if (cancel) { /* cancel from either end */
send_file_cancellation_sync (g);
return -1;
}
@@ -1604,14 +1607,22 @@ send_file_chunk_sync (guestfs_h *g, int cancel, const char *buf, size_t len)
}
/* Did the daemon send a cancellation message? */
- if (check_for_daemon_cancellation (g))
+ if (check_for_daemon_cancellation (g)) {
+ if (g->verbose)
+ fprintf (stderr, "got daemon cancellation\n");
return -2;
+ }
/* Serialize the chunk. */
chunk.cancel = cancel;
chunk.data.data_len = len;
chunk.data.data_val = (char *) buf;
+ if (g->verbose)
+ fprintf (stderr,
+ "library sending chunk cancel = %d, len = %zu, buf = %p\n",
+ cancel, len, buf);
+
xdrmem_create (&xdr, data, sizeof data, XDR_ENCODE);
if (!xdr_guestfs_chunk (&xdr, &chunk)) {
error (g, "xdr_guestfs_chunk failed (buf = %p, len = %zu)", buf, len);