Commit Graph

81 Commits

Author SHA1 Message Date
Richard W.M. Jones
2cc348448a generator: Share Common_utils code.
For a very long time we have maintained two sets of utility functions,
in mllib/common_utils.ml and generator/utils.ml.  This changes things
so that the same set of utility functions can be shared with both
directories.

It's not possible to use common_utils.ml directly in the generator
because it provides several functions that use modules outside the
OCaml stdlib.  Therefore we add some lightweight post-processing which
extracts the functions using only the stdlib:

  (*<stdlib>*)
  ...
  (*</stdlib>*)

and creates generator/common_utils.ml and generator/common_utils.mli
from that.  The effect is we only need to write utility functions
once.

As with other tools, we still have generator-specific utility
functions in generator/utils.ml.

Also in this change:

 - Use String.uppercase_ascii and String.lowercase_ascii in place
   of deprecated String.uppercase/String.lowercase.

 - Implement String.capitalize_ascii to replace deprecated
   String.capitalize.

 - Move isspace, isdigit, isxdigit functions to Char module.
2016-12-09 09:31:25 +00:00
Richard W.M. Jones
4730f4a918 generator: Generalize the code used to split actions across files.
Previously we used an awkward hack to split up the large src/actions.c
into smaller files (which can benefit from being compiled in
parallel).  This commit generalizes that code, so that we pass a
subsetted actions list to certain generator functions.

The output of the generator is identical after this commit and the
previous commit, except for the UUID encoded into tests/c-api/tests.c
since that is derived from the MD5 hash of generator/actions.ml.
2016-09-02 23:14:08 +01:00
Richard W.M. Jones
f8978239e3 generator: Move all actions into a single list and add filter functions.
This mostly mechanical change moves all of the libguestfs API
lists of functions into a struct in the Actions module.

It also adds filter functions to be used elsewhere to get
subsets of these functions.

Original code         Replacement

all_functions         actions

daemon_functions      actions |> daemon_functions
non_daemon_functions  actions |> non_daemon_functions
external_functions    actions |> external_functions
internal_functions    actions |> internal_functions
documented_functions  actions |> documented_functions
fish_functions        actions |> fish_functions

*_functions_sorted    ... replacement as above ... |> sort
2016-09-02 23:14:08 +01:00
Pino Toscano
3b427b90ac doc: add info on per-function needed feature
Document which feature, if any, is needed for a function; this should
help users in properly checking feature availability when using certain
functions.
2016-02-26 18:36:42 +01:00
Pino Toscano
20efe36582 src: print contents of structs and struct lists on tracing
It eases the debugging, instead of getting just the name of the struct
returned.
2016-02-24 13:47:18 +01:00
Pino Toscano
2c0d16e82e src: generate code for printing contents of structs
Extend the generator to generate a source (and the header for it) with
functions that print the content of a guestfs struct.  The code is
modelled after the code for it in fish.ml, although made a bit more
generic (destination FILE*, line separator) so it can be used also in
the library, when tracing.

This just introduces the new code and builds it as part of the helper
libutils.la.
2016-02-24 13:47:18 +01:00
Richard W.M. Jones
ae3c051567 generator: Declare which input file(s) generate each output file. 2016-02-23 10:40:06 +00:00
Richard W.M. Jones
8cba70c038 lib: Stop exporting the safe_malloc, etc. functions.
As was forewarned in the comment, stop exporting these functions
outside the library.
2016-02-05 14:17:48 +00:00
Richard W.M. Jones
307c83177c Update copyright dates for 2016.
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2015/$1-2016/g' `git ls-files`
2016-01-02 21:19:51 +00:00
Richard W.M. Jones
32368f25f1 generator: Another minor indentation fix in src/actions-*.c files. 2015-11-06 12:09:53 +00:00
Pino Toscano
7c10cda266 generator: add a FilenameList parameter type
Mostly like StringList (so it can used in current StringList
parameters), but checking client- and daemon-side that the elements are
file names.
2015-10-21 13:00:18 +02:00
Richard W.M. Jones
ac5b3a050d header: Define GUESTFS_HAVE_STRUCT_* for each struct defined in the header. 2015-09-18 14:12:17 +01:00
Richard W.M. Jones
a17627cdd2 header: Define GUESTFS_HAVE_* for every function.
Previously we only defined GUESTFS_HAVE_* macros for functions that
were not deprecated, test or debug functions.  The reasoning for that
is given in this commit message [note that 'LIBGUESTFS_HAVE_' is the
old/deprecated macro]:

  commit 2d8fd7dacd
  Author: Richard Jones <rjones@redhat.com>
  Date:   Thu Sep 2 22:45:54 2010 +0100

    Define LIBGUESTFS_HAVE_<shortname> for C API functions.

    The actions each have a corresponding define, eg:

      #define LIBGUESTFS_HAVE_VGUUID 1
      extern char *guestfs_vguuid (guestfs_h *g, const char *vgname);

    However functions which are for testing, debugging or deprecated do
    not have the corresponding define.  Also a few functions are so
    basic (eg. guestfs_create) that there is no point defining a symbol
    for them.

This wasn't in fact carried through very consistently, since when we
replaced s/LIBGUESTFS_HAVE_/GUESTFS_HAVE_/, we kept the old
LIBGUESTFS_HAVE_* macros, but defined them for every function.  Oops.

This commit defines GUESTFS_HAVE_* for every function in <guestfs.h>,
making it easier to write the Python language bindings (see following
commits).
2015-09-18 14:12:17 +01:00
Pino Toscano
fc1f6deab1 generator: move api_version to a common version_added
This way the version string of each API can be used also in other
generator modules.

Mostly code motion, no actual behaviour changes.
2015-05-28 16:47:21 +02:00
Richard W.M. Jones
9c773962c5 Remove src/api-support and generate this information from actions added field. 2015-05-26 21:13:44 +01:00
Richard W.M. Jones
0f029a5f58 Whitespace changes arising from the previous two commits. 2015-02-14 18:46:05 +00:00
Richard W.M. Jones
1efd8aa8f1 Change guestfs__* to guestfs_impl_*
libguestfs has used double and triple underscores in identifiers.
These aren't valid for global names in C++.

The second step is to replace all guestfs__* (2 underscores) with
guestfs_impl_*.

These functions are used where a libguestfs API call is implemented on
the library side.  The generator creates a wrapper function which
calls guestfs_impl_* to do the work.  (Libguestfs APIs which are
passed directly by the daemon work differently and don't require a
guestfs_impl_* function).

This is an entirely mechanical change done using:
  git ls-files | xargs perl -pi.bak -e 's/guestfs___/guestfs_impl_/g'

Reference: http://stackoverflow.com/a/228797
2015-02-14 18:46:04 +00:00
Richard W.M. Jones
bfbcc01403 Change guestfs___* to guestfs_int_*
libguestfs has used double and triple underscores in identifiers.
These aren't valid for global names in C++.

The first step is to replace all guestfs___* (3 underscores) with
guestfs_int_*.  We've used guestfs_int_* elsewhere already as a prefix
for internal identifiers.

This is an entirely mechanical change done using:
  git ls-files | xargs perl -pi.bak -e 's/guestfs___/guestfs_int_/g'

Reference: http://stackoverflow.com/a/228797
2015-02-14 18:46:04 +00:00
Pino Toscano
8aadde50b3 generator: add VPublicNoFish visibility type
Usable to have public functions, i.e. like VPublic, but do not showing
them in guestfish.
2015-02-02 18:44:52 +00:00
Richard W.M. Jones
c5800dc97d Update copyright dates for 2015. 2015-01-17 09:08:15 +00:00
Richard W.M. Jones
96158d42f5 New(ish) API: guestfs_add_libvirt_dom.
This API already existed (as guestfs___add_libvirt_dom), and was used
by a few tools.

This commit changes it to a public API.

Note that for reasons outlined in the previous commit message, it is
impossible to call this from guestfish or from non-C language
bindings.
2014-12-11 14:15:00 +00:00
Richard W.M. Jones
fd9ac7f47d generator: Implement Pointer arguments.
This implements Pointer arguments properly, at least for certain
limited definitions of "implements" and "properly".

'Pointer' as an argument type is meant to indicate a pointer passed to
an API.  The canonical example is the following proposed API:

  int guestfs_add_libvirt_dom (guestfs_h *g, virDomainPtr dom, ...);

where 'dom' is described in the generator as:

  Pointer ("virDomainPtr", "dom")

Pointer existed already in the generator, but the implementation was
broken.  It is not used by any existing API.

There are two basic difficulties of implementing Pointer:

(1) In language bindings there is no portable way to turn (eg.) a Perl
Sys::Virt 'dom' object into a C virDomainPtr.

(2) We can't rely on <libvirt/libvirt.h> being included (since it's an
optional dependency).

In this commit, we solve (2) by using a 'void *'.

We don't solve (1), really.  Instead we have a macro
POINTER_NOT_IMPLEMENTED which is used by currently all the non-C
language bindings.  It complains loudly and passes a NULL to the
underlying function.  The underlying function detects the NULL and
safely returns an error.  It is to be hoped that people will
contribute patches to make each language binding work, although in
some bindings it will always remain impossible to implement.
2014-12-11 14:15:00 +00:00
Pino Toscano
78b27cc0b6 Include string.h where needed
Required for using strlen, memcpy, etc. Apparently implicitly pulled so
far.
2014-10-23 19:03:11 +02:00
Pino Toscano
4d8ecb0d30 generator: fix daemon functions with optional params but no mandatory params
The
  struct guestfs_$function_args args;
declaration was not emitted in that case, leading to build failure.
2014-05-29 10:32:15 +02:00
Richard W.M. Jones
01548fd5b7 generator: Generate copyright notice in generated POD fragments.
Using =begin comment ... =end comment.
2014-03-20 13:46:53 +00:00
Richard W.M. Jones
19dcc0de1f Annual scavange to find mixed declarations and statements.
Hopefully this is just code motion.
2014-03-17 19:54:16 +00:00
Pino Toscano
775cad63a3 generator: generate code for parameter validation
Implemented only in the C output, since every binding uses it anyway,
and just for the "GUID" type (since its format is well-known).
2014-02-06 20:02:51 +01:00
Pino Toscano
b10dd601fb generator: add a GUID parameter type
At the moment it is basically the change as String, and it is mapped as
if it was such.
2014-02-06 17:43:04 +01:00
Richard W.M. Jones
6c971faecf Update copyright dates for 2014. 2014-01-02 16:53:34 +00:00
Richard W.M. Jones
78b9229bc8 lib: Export guestfs_compare_* functions for comparing structs and lists of structs. 2013-12-18 15:15:52 +00:00
Richard W.M. Jones
3d398687be lib: Export guestfs_copy_* functions for copying structs and lists of structs.
These complement the guestfs_free_* functions.
2013-12-18 15:15:52 +00:00
Richard W.M. Jones
0f3489ba6b lib: Rename cleanup-structs.c -> structs-cleanup.c and free-structs.c -> structs-free.c.
Just renaming generated files, no other effects.
2013-12-18 15:15:52 +00:00
Richard W.M. Jones
882b91cb48 generator: Fix bug in documentation of guestfs_free_* functions.
These appeared in the documentation as:

 void guestfs_free_int_bool (struct guestfs_free_int_bool *);
                                            ^^^^

which is obviously wrong.
2013-12-18 15:15:52 +00:00
Richard W.M. Jones
b2baaa0029 generator: Change handling of C 'function(void)' to be simpler.
This also fixes an obscure case in daemon/optgroups.h.

The only difference in the generated output is:

--- daemon/optgroups.h.orig	     2013-10-09 20:42:02.479681861 +0100
+++ daemon/optgroups.h		     2013-10-09 20:42:10.563681858 +0100
@@ -149,7 +149,7 @@
   int optgroup_inotify_available (void) { return 0; }

 #define OPTGROUP_JOURNAL_NOT_AVAILABLE \
-  int __attribute__((noreturn)) do_internal_journal_get () { abort (); } \
+  int __attribute__((noreturn)) do_internal_journal_get (void) { abort (); } \
   int __attribute__((noreturn)) do_journal_close (void) { abort (); } \
   int64_t __attribute__((noreturn)) do_journal_get_data_threshold (void) { abort (); } \
   int __attribute__((noreturn)) do_journal_next (void) { abort (); } \
2013-10-09 20:43:25 +01:00
Richard W.M. Jones
e31c32ce1b generator: Fix the case where a daemon function has one FileIn/FileOut parameter and no other parameters.
The FileIn/FileOut parameters are not passed through to the daemon.
Previously we generated incorrect RPC code (an empty 'struct
guestfs_<fn>_args') because we didn't account for these FileIn/FileOut
parameters correctly.
2013-07-27 16:45:37 +01:00
Richard W.M. Jones
22d82d00b4 generator: Small fix for OCaml 3.12.1.
OCaml 3.12.1 (unlike 4.00.1) doesn't let you use printf formatters
in this way:

  printf (if foo then "&%s" else "%s") str
2013-03-08 13:17:45 +00:00
Richard W.M. Jones
d08f5ebd9a generator: Generate guestfs_user_cancel.
This function is now generated, so bindings in various languages
are made automatically.

Note that the function previously returned void, but now it returns
int (although always 0).  We don't believe that this is an ABI break
since existing programs will continue to work.
2013-03-04 15:24:26 +00:00
Richard W.M. Jones
ac2f6c4ef2 generator: Add 'wrapper' flag to control when wrapper is generated.
Non-daemon functions normally have a wrapper function called
eg. guestfs_name.  The "real" (ie. hand-written) function is called
eg. guestfs__name.  The wrapper deals with checking parameters and
doing trace messages.

This commit allows the wrapper function to be omitted.  The reason is
so that we can handle a few functions that have to be thread-safe
(currently just: guestfs_user_cancel).  The wrapper is not thread safe
because it can call events and/or the error handler.
2013-03-04 15:24:05 +00:00
Richard W.M. Jones
66351f7494 trace: Put trace buffer on the stack instead of in the handle.
This makes more sense, and makes the code slightly closer to being
thread safe (although it's still NOT thread safe).
2013-03-04 15:07:50 +00:00
Richard W.M. Jones
ce7cffa85a libutils: Don't include "guestfs-internal.h".
This mini-library shouldn't access library-internal stuff.  It should
only use the "guestfs-internal-frontend.h" header.
2013-02-27 14:07:25 +00:00
Richard W.M. Jones
4c5c555eeb generator: Line up GUESTFS_EVENT_ALL. 2013-02-26 22:11:40 +00:00
Richard W.M. Jones
c29660588f generator: Remove "deprecated macros for internal functions".
No need for these since these are internal functions that only code
under our control should have been calling.
2013-02-26 22:08:53 +00:00
Richard W.M. Jones
76266be549 lib: Export guestfs___add_libvirt_dom for use by virt-df and virt-alignment-scan.
See the comment in guestfs-internal-frontend.h in this commit.
2013-02-26 17:02:32 +00:00
Richard W.M. Jones
04723b4dd1 lib: Create libutils convenience library.
The libutils convenience library is a place for code shared between
the main library, language bindings and virt tools.  Note that the
code is statically linked into both the library, each binding and each
tool, but this is an improvement because (a) the source is shared and
(b) libguestfs.so can export fewer private functions.

Currently it contains the cleanup functions, and the functions
guestfs___free_string_list function and guestfs___for_each_disk.

guestfs___for_each_disk has changed so that it no longer
unconditionally sets the error in the guestfs handle.  Instead callers
can control error handling.
2013-02-20 19:15:05 +00:00
Richard W.M. Jones
a4953090e1 lib: Rename guestfs_error_errno as guestfs___error_errno, etc.
These are internal functions.  Very old versions of libguestfs used to
export them, but they haven't been (and shouldn't be) exported for a
long time.

Also remove the unused guestfs_error function.
2013-02-20 17:09:52 +00:00
Richard W.M. Jones
b793fafcb7 New C only API: guestfs_event_to_string. 2013-02-19 13:41:57 +00:00
Matthew Booth
942e139562 mountable: Implement Mountable_or_Path
A Mountable_or_Path argument is passed as a mountable_t. A new type is
added to mountable_t to handle already mounted paths.
2013-02-11 16:54:42 +00:00
Richard W.M. Jones
f226133c1a lib: Define GUESTFS_GCC_VERSION in the internal header.
Note that you have to use this as follows:

#if defined(__GNUC__) && GUESTFS_GCC_VERSION >= x0y0z /* gcc >= x.y.z */

since GUESTFS_GCC_VERSION is not defined unless it's GCC.
2013-02-11 16:10:17 +00:00
Matthew Booth
ef2276654e generator: Create Mountable_or_Path, initially identical to Dev_or_Path 2013-02-11 15:43:53 +00:00
Matthew Booth
47b929b789 mountable: Implement Mountable support for all apis which take it
A Mountable is passed from the library to the daemon as a string. The daemon
stub parses it into a mountable_t, which it passes to the implementation.

Update all implementations which now take a mountable_t.
2013-02-11 15:42:58 +00:00