Files
libguestfs/generator
Richard W.M. Jones 5a50c04906 Improve zeroing and detection of zeroes.
This code modifies zero, zero-device, is-zero, is-zero-device.

zero and zero-device are modified so that if the blocks of the device
already contain zeroes, then we don't write zeroes.  The reason for
this is to avoid unnecessarily making the underlying storage
non-sparse or (in the qcow2 case) growing it.

is-zero and is-zero-device are modified so that zero detection is
faster.  This is a nice side effect of making the first change.

Since avoiding unnecessary zeroing involves reading the blocks before
writing them, whereas before we just blindly wrote, this can be
slower.  As you can see from the tests below, in the case where the
disk is sparse, it actually turns out to be faster, because we avoid
allocating the underlying blocks.

However in the case where the disk is non-sparse and full of existing
data, it is much slower.  There might be a case for an API flag to
adjust whether or not we perform the zero check.  I did not add this
flag because it is unlikely that the caller would have enough
information to be able to set the flag correctly.

                                (Elapsed time in seconds)
Format  Test case                 Before     After

Raw     Sparse                    16.4       5.3

        Preallocated zero         17.0       18.8

        Preallocated random       16.0       41.3

Qcow2   preallocation=off         18.7       5.6

        preallocation=metadata    17.4       5.8

The current code uses a fixed block size of 4K for reading and
writing.  I also tried the same tests with a block size of 64K but it
didn't make any significant difference.

(Thanks to Federico Simoncelli for suggesting this change)
2011-08-16 13:25:20 +01:00
..
2011-04-22 21:50:16 +01:00
2011-07-17 11:23:47 +01:00

This program generates a large amount of code and documentation for
all the daemon actions.

To add a new action there are only two files you need to change,
'generator_actions.ml' to describe the interface, and
daemon/<somefile>.c to write the implementation.

After editing these files, build it (make -C generator) to regenerate
all the output files.  'make' will rerun this automatically when
necessary.

IMPORTANT: This program should NOT print any warnings at compile time
or run time.  If it prints warnings, you should treat them as errors.

OCaml tips:

(1) In emacs, install tuareg-mode to display and format OCaml code
correctly.  'vim' comes with a good OCaml editing mode by default.

(2) Read the resources at http://ocaml-tutorial.org/

(3) A module called 'Generator_foo' is defined in one or two files
called 'generator_foo.mli' and 'generator_foo.ml' (NB: lowercase first
letter).  The *.mli file, if present, defines the public interface for
the module.  The *.ml file is the implementation.  If the *.mli file
is missing then everything is exported.

Some notable files in this directory:

generator_actions.ml          The libguestfs API.
generator_structs.ml          Structures returned by the API.
generator_c.ml                Generate C API.
generator_<lang>.ml           Generate bindings for <lang>.
generator_main.ml             The main generator program.