summaryrefslogtreecommitdiffstats
path: root/src/proto.c
Commit message (Collapse)AuthorAgeFilesLines
* syntax: Remove include <signal.h> in file that doesn't use it.Richard W.M. Jones2012-09-151-1/+0
| | | | Found by 'make syntax-check'.
* lib: Rearrange headers.Richard W.M. Jones2012-09-151-5/+4
| | | | This is just code motion.
* lib: Remove unused headers <arpa/inet.h> and <netinet/in.h>Richard W.M. Jones2012-09-151-2/+0
| | | | | These were used back in the day when we used TCP for the communications channel with the guest.
* syntax: Remove HAVE_*_H tests which are always true.Richard W.M. Jones2012-09-151-19/+3
| | | | | Gnulib supplies replacements for these headers, so there is no need to test.
* shutdown: Add 'check_for_errors' hint along the shutdown path.Richard W.M. Jones2012-09-041-1/+1
| | | | | | | | This hint tells the backend whether anyone cares about errors when the appliance is shut down. Currently this only has any effect on the libvirt backend, where it controls whether or not we use the VIR_DOMAIN_DESTROY_GRACEFUL flag.
* launch: Abstract attach method operations.Richard W.M. Jones2012-07-201-6/+8
| | | | | | g->attach_ops points to a structure which contains the operations supported by each attach method backend (ie. appliance, unix, etc.).
* lib: Remove the BUSY state.Richard W.M. Jones2012-04-261-65/+12
| | | | | | | | | | | | | | | Originally this state was intended so that in some way you could find out if the appliance was running a command. However there was never a thread-safe way to access the state of the handle, so in effect you could never do anything useful safely with this information. This commit completely removes the BUSY state. The only visible change is to the guestfs_is_busy API. Previously you could never call this safely from another thread. If you called it from the same thread it would always return false (since the current thread can't be running a libguestfs command at that point by definition). Now it always returns false.
* Use posix_fadvise when uploading or downloading files.Richard W.M. Jones2012-04-091-0/+17
| | | | | But ignore it if the call fails, since the file descriptor could be a non-file (eg. /dev/stdout).
* Use O_CLOEXEC / SOCK_CLOEXEC for almost all file descriptors.Richard W.M. Jones2012-03-141-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | The presumption is that all file descriptors should be created with the close-on-exec flag set. The only exception are file descriptors that we want passed through to exec'd subprocesses (mainly pipes and stdin/stdout/stderr). For open calls, we pass O_CLOEXEC as an extra flag, eg: fd = open ("foo", O_RDONLY|O_CLOEXEC); This is a Linux-ism, but using a macro we can easily make it portable. For sockets, similarly: sock = socket (..., SOCK_STREAM|SOCK_CLOEXEC, ...); For accepted sockets, we use the Linux accept4 system call which allows flags to be supplied, but we use the Gnulib 'accept4' module to make this portable. For dup, dup2, we use the Linux dup3 system call, and the Gnulib modules 'dup3' and 'cloexec'.
* Replace 'int' with 'size_t' passim.Richard W.M. Jones2012-03-131-1/+1
| | | | | Analyze all uses of 'int' in the code, and replace with 'size_t' where appropriate.
* daemon: proto: Close fd along error paths (found by Coverity).Richard W.M. Jones2012-03-081-0/+3
| | | | | | | | | Error: RESOURCE_LEAK: /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:894: open_fn: Calling opening function "open". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:894: var_assign: Assigning: "fd" = handle returned from "open(filename, 0)". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:903: noescape: Variable "fd" is not closed or saved in function "read". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:911: leaked_handle: Handle variable "fd" going out of scope leaks the handle. /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:918: leaked_handle: Handle variable "fd" going out of scope leaks the handle.
* proto: Close file along error and cancel paths (found by Coverity).Richard W.M. Jones2012-03-081-1/+5
| | | | | | | | | Error: RESOURCE_LEAK: /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1125: open_fn: Calling opening function "open". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1125: var_assign: Assigning: "fd" = handle returned from "open(filename, 833, 438)". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1133: noescape: Variable "fd" is not closed or saved in function "xwrite". /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1146: leaked_handle: Handle variable "fd" going out of scope leaks the handle. /builddir/build/BUILD/libguestfs-1.16.5/src/proto.c:1173: leaked_handle: Handle variable "fd" going out of scope leaks the handle.
* Tempus fugit.Richard W.M. Jones2012-01-181-1/+1
| | | | Update all copyright dates to 2012.
* protocol: Memory leak: Free temporary buffer along recv_discard path.Richard W.M. Jones2011-11-291-0/+1
|
* Add user cancellation to the C API.Richard W.M. Jones2011-07-151-7/+20
| | | | | | | | | This allows long transfers (FileIn and FileOut operations) to be cancelled by calling the signal and thread safe guestfs_user_cancel function. Most of this commit consists of a multithreaded program that tests user cancellation of uploads and downloads.
* protocol: Enhance "unexpected end of file when reading from daemon" error.Richard W.M. Jones2011-06-071-2/+21
| | | | | Make this error more informative, since it is a common error when the appliance fails to start up.
* Generate progress messages during launch.Richard W.M. Jones2011-04-011-0/+18
| | | | | | | | | | | | | | | | | | | This commit generates approximate progress messages during the guestfs_launch call. Currently this code generates: 0 / 12: launch clock starts 3 / 12: appliance created 6 / 12: detected that guest kernel started 9 / 12: detected that /init script is running 12 / 12: launch completed successfully (Note this is not an ABI and may be changed or removed in a future version). Progress messages are only generated at all if 5 seconds have elapsed since the launch, and they are only generated for the ordinary appliance (not if using attach-method to attach to an existing virtio serial port).
* protocol: Sleep for 1ms before reading log messages.Richard W.M. Jones2011-04-011-1/+8
| | | | | | | | | | | | | | | As explained in the comment: /* QEMU's console emulates a 16550A serial port. The real 16550A * device has a small FIFO buffer (16 bytes) which means here we see * lots of small reads of 1-16 bytes in length, usually single * bytes. Sleeping here for a very brief period groups reads * together (so we usually get a few lines of output at once) and * improves overall throughput, as well as making the event * interface a bit more sane for callers. With a virtio-serial * based console (not yet implemented) we may be able to remove * this. XXX */
* Shared function to send progress messages.Richard W.M. Jones2011-04-011-4/+6
| | | | This is just code motion.
* proto: Fix both-ends-cancel case.Richard W.M. Jones2011-03-181-3/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the case where both ends cancel at the same time (eg. both ends realize there are errors before or during the transfer), previously we skipped sending back an error from the daemon, on the spurious basis that the library would not need it (the library is cancelling because of its own error). However this is wrong: we should always send back an error message from the daemon in order to preserve synchronization of the protocol. A simple test case is: $ guestfish -N fs -m /dev/sda1 upload nosuchfile / libguestfs: error: open: nosuchfile: No such file or directory libguestfs: error: unexpected procedure number (66/282) (Notice two things: there are errors at both ends, and the loss of synchronization). After applying this commit, the loss of synchronization does not occur and we just see the library error: $ guestfish -N fs -m /dev/sda1 upload nosuchfile / libguestfs: error: open: nosuchfile: No such file or directory The choice of displaying the library or the daemon error is fairly arbitrary in this case -- it would be valid to display either or even to combine them into one error. Displaying the library error only makes the code considerably simpler. This commit also (re-)enables a test for this case.
* proto: Don't drop outgoing message when daemon cancels (RHBZ#576879).Richard Jones2011-03-181-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a (potential) fix for the long standing protocol bug which causes loss of synchronization when a FileIn action fails very early on the daemon side. The canonical example would be the 'upload' action failing immediately if no filesystem is mounted. What's supposed to happen is this: (1) library sends request message (2) daemon processes request first chunk of data and sees that it will fail, sends cancellation (3) discards chunks of data (4) library sees daemon cancellation and stops sending chunks It was going wrong in step (1), in guestfs___send_to_daemon. In some (timing related) circumstances, send_to_daemon could receive the cancellation before sending the first chunk, at which point it would exit, *discarding the first chunk*. This causes the daemon to fail in step (3) since it reads the next request as if it was a chunk, thus losing synchronization. (The protocol specifies that you always have to send at least one chunk if there is a FileIn or FileOut parameter). The patch changes guestfs___send_to_daemon so that if it detects cancellation, it sends the remaining data in its output buffer instead of discarding it. (This also fixes another edge case to do with sending partial data although I don't think we ever saw that in practice).
* proto: Improve debug messages.Richard W.M. Jones2011-03-181-9/+58
|
* New event API (RHBZ#664558).Richard W.M. Jones2011-03-151-43/+33
| | | | | | | | | | | | | This API allows more than one callback to be registered for each event, makes it possible to call the API from other languages, and allows [nearly all] log, debug and trace messages to be rerouted from stderr. An older version of this API was discussed on the mailing list here: https://www.redhat.com/archives/libguestfs/2010-December/msg00081.html https://www.redhat.com/archives/libguestfs/2011-January/msg00012.html This also updates guestfish to use the new API for its progress bars.
* lib: Implement attach-method unix:<path>Richard W.M. Jones2011-02-031-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | Allow connections to a Unix domain socket which is connected (via virtio-serial) to a guestfsd running free in an existing guest. In order to use this you have to add the following element to the libvirt XML: <channel type='unix'> <source mode='bind' path='/tmp/socket'/> <target type='virtio' name='org.libguestfs.channel.0'/> </channel> (or perform the equivalent on the qemu command line). Then in guestfish, you can do: guestfish \ attach-method unix:/tmp/socket : \ run : \ ll / (or any other commands as desired).
* generator: Code to handle optional arguments in daemon functions.Richard W.M. Jones2010-12-021-2/+3
| | | | | | | | Previously we only supported optional arguments for library functions (commit 14490c3e1aac61c6ac90f28828896683f64f0dc9). This extends that work so that optional arguments can also be passed through to the daemon.
* protocol: Handle progress notification messages during FileIn.Richard W.M. Jones2010-12-011-3/+30
| | | | | | | If the daemon sends progress notification messages while we are uploading FileIn parameters, these are received in check_for_daemon_cancellation_or_eof. Modify this library function so that it turns these messages into callbacks.
* protocol: Really read 4 bytes while checking for cancellation.Richard W.M. Jones2010-12-011-10/+49
| | | | | | | | | | | | We've not actually hit this bug in practice, but at least in theory while checking for cancellation we could read > 0 but fewer than 4 bytes, which would effectively be discarded and we would lose synchronization. Note the socket is non-blocking. Change the code so that we temporarily set the socket back to blocking and force the read of all 4 bytes.
* protocol: Send progress_hint in header.Richard W.M. Jones2010-12-011-2/+3
| | | | | | For actions that have FileIn arguments, count the size of all the input files and send that in the progress_hint field of the request header.
* protocol: Upload progress messages and optional arguments.Richard W.M. Jones2010-12-011-0/+2
| | | | | | | | Two unrelated changes to the protocol to support progress messages during uploads, and optional arguments. Note that this makes an incompatible change to the protocol, and this is reflected in the protocol version field (3 -> 4).
* Implement progress messages in the daemon and library.Richard Jones2010-08-311-3/+44
| | | | | | | | | | | | This implements progress notification messages in the daemon, and adds a callback in the library to handle them. No calls are changed so far, so in fact no progress messages can be generated by this commit. For more details, see: https://www.redhat.com/archives/libguestfs/2010-July/msg00003.html https://www.redhat.com/archives/libguestfs/2010-July/msg00024.html
* Rename internal functions.Richard Jones2010-07-281-7/+7
| | | | | | | This is an update to commit 41f25ab3df5f306ac717fa7a6efd58328d30c1ae. Internal functions should be named guestfs___* (3 underscores) to avoid clashing with the implementation of actions (2 underscores).
* Rearrange library code into separate files.Richard Jones2010-07-271-0/+987
We split the library code into these separate files: - guestfs.c: creating handles, closing handles, handle-related variables - actions.c: generated library-side stubs for each action - bindtests.c: generated code to test bindings - launch.c: launching the appliance - proto.c: the library side of the daemon communications protocol This is just code movement.