Commit Graph

139 Commits

Author SHA1 Message Date
Richard W.M. Jones
cd00157efc ocaml: Generate ocamldoc.
Also includes improvements to the OCaml documentation.
2011-07-17 11:23:47 +01:00
Richard W.M. Jones
e72592563c ocaml: Bind guestfs_last_errno. 2011-07-16 19:15:29 +01:00
Richard W.M. Jones
60dd9494f0 ocaml: Add binding for guestfs_user_cancel. 2011-07-15 14:34:21 +01:00
Richard W.M. Jones
f2c7df589c Add new guestfs-rescue(1) man page with recipes. 2011-05-18 21:03:44 +01:00
Richard W.M. Jones
7e51cc94dd New event API - OCaml bindings (RHBZ#664558).
The functions set_progress_callback and clear_progress_callback have
been removed, and replaced with a complete mechanism for setting and
deleting general-purpose events.
2011-03-15 12:16:50 +00:00
Richard W.M. Jones
477eebc83d perl: Translate C examples into Perl and include a manual page. 2011-01-30 23:41:05 +00:00
Richard W.M. Jones
0c60e4d9dd fish: Don't fail if some mountpoints in /etc/fstab are bogus (RHBZ#668574).
Fix guestfish (and other C tools) so that they ignore errors
when /etc/fstab contains bogus entries.

Update the documentation for inspect-get-mountpoints to emphasize
that callers must be aware of this when mounting the returned
values.

Add a regression test.

Update the example code ("inspect_vm") to reflect the way this
API ought to be called.

For more detail see:
https://bugzilla.redhat.com/show_bug.cgi?id=668574
2011-01-11 11:09:41 +00:00
Richard W.M. Jones
13af3835cd ocaml: Combine tests together to reduce number of launches.
Combine launch, lvcreate and readdir tests together into a
single 'basic' test, so that we don't launch the appliance
so often when testing in this subdirectory.
2010-11-30 13:56:33 +00:00
Richard W.M. Jones
37e632b7b8 ruby: Translate C examples into Ruby and include documentation. 2010-11-24 20:13:13 +00:00
Richard W.M. Jones
472722a72d python: Translate C examples into Python and include documentation. 2010-11-24 20:12:50 +00:00
Richard W.M. Jones
086bd1f7bf ocaml: Translate C examples into OCaml and include documentation. 2010-11-24 20:12:16 +00:00
Richard W.M. Jones
8d3e97679a ocaml: Fix some unused parameter warnings in OCaml bindings. 2010-11-23 18:25:18 +00:00
Richard W.M. Jones
f6c4026f85 build: xml-light is no longer required (thanks Maxim Koltsov).
At some point we removed the last thing that required
xml-light, but were still testing for it at various places
in the build.  This removes all traces.
2010-11-11 18:03:12 +00:00
Richard Jones
e3acf93ce9 Revert "Remove ocaml/.depend from git."
This reverts commit 064569bcbf.

This commit does the wrong thing: creating an empty ocaml/.depend
file is wrong because building the OCaml bindings will fail.
Not having this file will prevent automake from running.  Therefore
this file has to exist with the correct content in git.
2010-11-08 22:35:13 +00:00
Richard W.M. Jones
53c5248193 ocaml: Remove the old OCaml viewer program.
This program is obsolete and the code has been reused for
guestfs-browser here:
http://people.redhat.com/~rjones/guestfs-browser/
2010-11-08 14:28:44 +00:00
Matthew Booth
064569bcbf Remove ocaml/.depend from git.
ocaml/.depend is automatically generated. This patch removes it from git.
2010-10-28 15:16:14 +01:00
Richard W.M. Jones
14490c3e1a generator: Optional arguments, add-drive-opts (RHBZ#642934,CVE-2010-3851).
This large commit changes the generator so that optional arguments
can be supported for functions.

The model for arguments (known as the "style") is changed from
(ret, args) to (ret, args, optargs) where optargs is a more limited
list of arguments.

One function has been added which takes optional arguments, it is
"add-drive-opts", modelled as:

  (RErr, [String "filename"], #required
         [Bool "readonly"; String "format"; String "iface"]) #optional

Note that this function is processed in the library (does not go over
the RPC protocol to the daemon).  This has allowed us to simplify
the current implementation by omitting changes related to RPC or the
daemon, although we plan to add these at some point in the future.

From C this function can be called in 3 different ways as in these
examples:

  guestfs_add_drive_opts (g, filename,
                          GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
			  GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
                          -1);

(the argument(s) between 'filename' and '-1' are the optional ones).

  guestfs_add_drive_opts_va (g, filename, args);

where 'args' is a va_list.  This works like the first version.

  struct guestfs_add_drive_opts_argv optargs = {
    .bitmask = GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK,
    .readonly = 1,
  }
  guestfs_add_drive_opts_argv (g, filename, &optargs);

This last form lets you construct lists of optional arguments, and
is used by guestfish and the language bindings.

In guestfish optional arguments are used like this:

  add-drive-opts filename readonly:true

In OCaml these are mapped naturally to OCaml optional arguments, eg:

  g#add_drive_opts ~readonly:true filename;

In Perl these are mapped to extra arguments, eg:

  $g->add_drive_opts ($filename, readonly => 1);

In Python these are mapped to optional arguments, eg:

  g.add_drive_opts ("file", readonly = 1, format = "qcow2")

In Ruby these are mapped to a final hash argument, eg:

  g.add_drive_opts("file", {})
  g.add_drive_opts("file", :readonly => 1)
  g.add_drive_opts("file", :readonly => 1, :iface => "virtio")

In PHP these are mapped to extra parameters.  This is not quite
accurate since you cannot omit arbitrary optional parameters, but
there's not much than can be done within the limitations of PHP
as a language.

Unimplemented in: Haskell, C#, Java.
2010-10-22 17:45:00 +01:00
Richard W.M. Jones
6af1cd7245 ocaml: Create the handle when the object is instantiated.
Previously we had only one handle shared between all objects .. oops.
This fixes commit 67636f7210.
2010-10-04 20:29:05 +01:00
Richard W.M. Jones
67636f7210 ocaml: Add alternate object-oriented programming style.
In original style:

let () =
  let filename = Sys.argv.(1) in
  let g = Guestfs.create () in
  Guestfs.add_drive_ro g filename;
  Guestfs.launch g;
  let roots = Guestfs.inspect_os g in
  print_endline (Guestfs.inspect_get_product_name g roots.(0))

The same code in the new OO style:

let () =
  let filename = Sys.argv.(1) in
  let g = new Guestfs.guestfs in
  g#add_drive_ro filename;
  g#launch ();
  let roots = g#inspect_os () in
  print_endline (g#inspect_get_product_name roots.(0))
2010-10-03 21:18:25 +01:00
Richard Jones
025583593b Update OCaml dependencies. 2010-09-10 10:28:51 +01:00
Richard Jones
d1485e02f5 ocaml: Add test for progress notification callbacks. 2010-09-01 17:12:15 +01:00
Richard Jones
3978a308a5 ocaml: bindings to progress callback. 2010-09-01 14:20:21 +01:00
Richard Jones
ad373a4d6c Remove old ocaml-inspector code.
Not used by anyone, didn't work well, and replaced now by the
C inspection APIs.
2010-08-17 14:09:26 +01:00
Richard Jones
1079f74704 ocaml: Fix thread safety of strings in bindings (RHBZ#604691).
There's a thread safety issue with the current OCaml bindings which
is well explained in the bug report:

https://bugzilla.redhat.com/show_bug.cgi?id=604691

This commit fixes the safety issue by copying strings temporarily
before releasing the thread lock.  Updated code looks like this:

  char *filename = guestfs_safe_strdup (g, String_val (filenamev));
  int r;

  caml_enter_blocking_section ();
  r = guestfs_add_drive_ro (g, filename);
  caml_leave_blocking_section ();
  free (filename);
  if (r == -1)
    ocaml_guestfs_raise_error (g, "add_drive_ro");

Also included is a regression test.
2010-06-16 15:32:20 +01:00
Richard Jones
82bd4fac87 ocaml examples: Fix linking line so it uses local library. 2010-03-22 10:41:46 +00:00
Richard Jones
2e2eb15df0 Remove separate inspector_generator.ml, combine this with generator.ml.
This commit combines the previously separate "inspector_generator.ml"
program which generated bindings for virt-inspector.

Having two separate programs caused no end of troubles for developers,
so we now combine them into a single program.

NOTE: OCaml xml-light is now *required* in order to rebuild the
generated code.
2009-12-31 11:20:56 +00:00
Matthew Booth
c477e2fb78 build: Fix inter-directory dependencies
This change adds an explicit dependency on generator.ml for every file it
generates, except java files. Java is left for another time because it's
considerably trickier.

It also adds a build rule for src/libguestfs.la so it can be rebuilt as required
from other directories.

It does this by creating a top level make file, subdir-rules.mk, which can be
included from sub-directories. sub-directories need to define 'generator_built'
to include local files which are built by generator.ml, and they will be updated
automatically.

This fixes parallel make, and will automatically re-create generated files when
make is run from any directory.

It also fixes the problem which efad4f53 was targetting. Specifically,
src/guestfs_protocol.(c|h) had an erroneous dependency on stamp-generator, and
therefore generator.ml, despite not being directly created by it. This caused
them to be recreated every time generator.ml ran rather than only when
src/guestfs_protocol.x was updated, which cascaded into a daemon and therefore
appliance update.

This patch also changes the contents of the distribution tarball by including
files created by rpcgen.
2009-11-19 16:40:22 +00:00
Richard Jones
b1e1ca2f74 Generic partition creation interface.
This commit introduces a generic partition creation interface
which should be future-proof and extensible, and partially
replaces the old sfdisk-based interface.

The implementation is based on parted but is hopefully not too
dependent on the particulars of parted.

The following new calls are introduced:

  guestfs_part_init:
    Initialize a disk with a partition table.  Unlike the sfdisk-
    based interface, we also support GPT and other partition
    types, which is essential to scale to devices larger than 2TB.

  guestfs_part_add: Add a partition to an existing disk.

  guestfs_part_disk:
    Convenience function which combines part_init & part_add,
    creating a single partition that covers the whole disk.

  guestfs_part_set_bootable:
  guestfs_part_set_name:
    Set various aspects of existing partitions.

  guestfs_part_list:
    List partitions on a device.  This returns a programming-friendly
    list of partition structs (in contrast to sfdisk-l which cannot
    be parsed).

  guestfs_part_get_parttype:
    Return the partition table type, eg. "msdos" or "gpt".

The following calls are planned, but not added currently:

  guestfs_part_get_bootable
  guestfs_part_get_name
  guestfs_part_set_type
  guestfs_part_get_type
2009-11-10 16:32:20 +00:00
Richard Jones
93e3253fa6 ocaml: Update dependencies file. 2009-11-09 11:05:19 +00:00
Richard W.M. Jones
c0465ca3ae ocaml: Sort the dependencies so they are stable between machines. 2009-11-06 12:33:27 +00:00
Richard W.M. Jones
79125c4dea ocaml: General improvements to generated code. 2009-11-06 10:49:32 +00:00
Richard Jones
de64183f3d Tab to space fixes, now passes 'make syntax-check' 2009-10-20 15:03:16 +01:00
Richard Jones
f57f338c3b Add some missing EXTRA_DIST files. 2009-10-14 11:24:33 +01:00
Richard Jones
d37f697953 inspector: Generate language bindings for OCaml.
This commit adds a generic mechanism for deriving language bindings
for virt-inspector, and implements one concrete binding, for OCaml.

The bindings are generated from the RELAX NG schema (virt-inspector.rng)
which is supposed to be a correct and always up to date description
of the XML that the virt-inspector program can generate.

From the RNG we generate a set of types to describe the output of
virt-inspector for the language, plus an XML parser, plus some
glue code to actually run an external instance of virt-inspector
and parse the resulting XML.

At runtime, an external 'virt-inspector --xml <name>' command runs
and the XML is parsed into language-specific structures.

This has been tested on the four example files (inspector/example?.xml)

The only particular difficulty about the OCaml binding is the use of
Obj.magic, which is naughty but works because of the isomorphism
between the representation of tuples and records in OCaml.  This
seems to cause no problems in my test program.  Apart from this, the
OCaml binding is straightforward and could be adapted easily for any
other languages that want type-safe virt-inspector bindings.

It's important to keep virt-inspector.rng up to date with changes
to virt-inspector's XML output format.
2009-10-13 17:53:20 +01:00
Jim Meyering
c6b8db6493 build: avoid parallel ocaml/... build failure
A parallel build could fail due to the use in ocaml/examples
of ocaml/guestfs.cmi before it was built.
* Makefile.am (SUBDIRS): Add both ocaml and ocaml/examples,
to ensure they're built in this order, and not in parallel.
* ocaml/Makefile.am (SUBDIRS): Don't define.
2009-10-05 14:16:46 +02:00
Jim Meyering
dde81c0c0e build: fix compile error
Link demo scripts with just-build library, not the installed one.
* ocaml/examples/Makefile.am (OCAMLFINDFLAGS): New variable.
(lvs, viewer): Use it.
This fix is based on a suggestion from Rich Jones.
This addresses RHBZ#526917.
2009-10-02 16:15:12 +02:00
Richard Jones
d525103c86 OCaml viewer: Use ocamlduce to replace xpath code. 2009-09-30 16:14:35 +01:00
Richard Jones
d278ef8ad9 OCaml viewer: Handle exceptions properly. 2009-09-29 11:56:26 +01:00
Richard Jones
4c8bdd3424 OCaml example: graphical disk usage viewer.
This is an example of how to write an app which uses libguestfs
and libvirt, and has a responsive user interface (using threads).
It is a Gtk-based "graphical virt-df".

Read the top of the 'viewer.ml' file first for instructions on
how to compile.  This program is not compiled by default.
2009-09-29 11:05:26 +01:00
Richard Jones
8869adf1e8 Remove guestfs_wait_ready (turn it into a no-op).
This commit changes guestfs_launch so that it both launches
the appliance and waits until it is ready (ie. the daemon communicates
back to us).

Since we removed the pretence that we could implement a low-level
asynchronous API, the need to call launch() followed by wait_ready()
has looked a bit silly.

Now guestfs_wait_ready() is basically a no-op.  It is left in the
API for backwards compatibility.  Any calls to guestfs_wait_ready()
can be removed from client code.
2009-09-21 12:01:51 +01:00
Jim Meyering
e933691fd1 build: enable gcc warnings in capitests/ and ocaml/
* capitests/Makefile.am: Use $(WARN_CFLAGS) and $(WERROR_CFLAGS).
* ocaml/Makefile.am:: Likewise.
2009-08-27 13:23:52 +02:00
Jim Meyering
4125126085 ocaml/guestfs_c.c: avoid warning about missing prototypes
* ocaml/guestfs_c.c (ocaml_guestfs_create, ocaml_guestfs_close): Declare.
2009-08-27 13:23:52 +02:00
Jim Meyering
27420d5dcf ocaml/guestfs_c.c: avoid warning about initialization discarding "const"
* ocaml/guestfs_c.c (guestfs_custom_operations): Add a cast.
2009-08-27 13:23:52 +02:00
Jim Meyering
1accb67720 ocaml/guestfs_c.c avoid signed/unsigned-comparison warning
* ocaml/guestfs_c.c (ocaml_guestfs_strings_val): Declare index as
unsigned int.
2009-08-27 13:23:52 +02:00
Jim Meyering
0c463dd0aa build: remove trailing blank lines; enable the syntax-check rule
* cfg.mk (disable_temporarily): Remove sc_prohibit_trailing_blank_lines.
* appliance/Makefile.am: Remove trailing blank line(s).
* appliance/debian/modules/y0_install-guestfsd: Likewise.
* appliance/make.sh.in: Likewise.
* appliance/packagelist.in: Likewise.
* appliance/update.sh.in: Likewise.
* haskell/run-bindtests: Likewise.
* ocaml/run-bindtests: Likewise.
* python/run-python-tests: Likewise.
* recipes/squashfs.example: Likewise.
* ruby/run-ruby-tests: Likewise.
2009-08-04 14:47:09 +02:00
Jim Meyering
dc3d0e3b8e build: don't emit trailing blanks, remove generated file
* ocaml/Makefile.am (.depend): Don't redirect directly to $@.
Filter out trailing blanks.
* ocaml/.depend: Regenerate.
2009-08-04 14:26:28 +02:00
Jim Meyering
2f1a50d816 Convert all TABs-as-indentation to spaces.
Do it by running this command:
[exempted files are matched via .x-sc_TAB_in_indentation]

  git ls-files \
    | pcregrep -vf .x-sc_TAB_in_indentation \
    | xargs pcregrep -l '^ *\t' \
    | xargs perl -MText::Tabs -ni -le \
      '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
2009-08-03 17:17:57 +02:00
Jim Meyering
3572996364 always include <config.h>
* ocaml/guestfs_c.c: Include <config.h>.
* examples/to-xml.c: Likewise.
* examples/hello.c: Likewise.
2009-08-03 15:14:30 +02:00
Jim Meyering
d39310d108 build: add -I option to get config.h.
* ocaml/Makefile.am (AM_CPPFLAGS): Define.
(guestfs_c.o, guestfs_c_actions.o): Use it.
2009-08-03 15:14:30 +02:00
Richard Jones
2d5b0e7599 ocaml: Rebuild the tests from source if the main library changes. 2009-07-29 12:45:11 +01:00