[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] Inspection code in C

Currently virt-inspector is a Perl script[1], which uses a Perl
library called Sys::Guestfs::Lib[2].  This library contains (amongst
other things) heuristics for determining what operating system is in a
disk image.  The library is the basis for both virt-inspector and

[1] http://git.annexia.org/?p=libguestfs.git;a=blob;f=inspector/virt-inspector;hb=HEAD
[2] http://git.annexia.org/?p=libguestfs.git;a=blob;f=perl/lib/Sys/Guestfs/Lib.pm;hb=HEAD

Writing these in Perl was useful at the time because they involved a
lot of string matching, and rules which we thought would change
frequently.  However these have proved to be simpler and more stable
than we originally thought.

If we rewrite these rules in C and make them available as part of the
core libguestfs API, then we gain some benefits:

(a) The generator will create bindings for us in all languages.

(b) We don't need to run an external virt-inspector binary to
  implement the "guestfish -i" option, which means that option will
  work much faster and with fewer limitations.

(c) We can get rid of the inspector-generator code which only works
  for OCaml, is a big hack, and is not used by anyone.

(d) People can write tools like virt-edit, virt-cat, virt-inspector,
  virt-v2v in languages other than Perl.

The downside is that this will become a core API which we cannot break
(because of the C ABI guarantee).

The main issues (hardest first) are:

(i) How to map the current tree structure returned by Sys::Guestfs::-
  Lib into the flat list-of-structures that the generator supports (or
  modifying the generator to support trees, but that is much more
  complex and I don't think necessary).

(ii) Decide on the final API.

(iii) Decide how much of the current API to move to C.

  The current "inspect_in_detail" call lists applications, kernels,
  drivers etc installed in the guest.  Furthermore the current API
  exposes a lot of information about individual filesystems, such as
  their UUID, which is nowadays unnecessary since we added calls such as
  guestfs_vfs_uuid to the main libguestfs API.  I don't think it's
  necessary to move all of this into C.  We can move it later if we want
  to, or leave it to the higher level tools.

  But it's not necessary to gain the benefits (a) through (d) above.

  As a result, the proposed API below is considerably simpler than
  the current Perl API, which (I think) exposing all the important
  information that anyone cares about and cannot be derived in any
  other way.

(iv) Modify virt-v2v and virt-inspector to use the new API.

(v) Introduces a direct dependency on hivex.

Please read the proposed API below, and let me know what you think.



/* Inspect and return list of operating systems found.
 * Returned list empty => no operating systems found.
 * 1 element => single operating system found.
 * > 1 element => multi-boot image.
char ** /* list of root devices */
  guestfs_inspect_os (guestfs_h *g);

/* Pass in a root device of one of the operating systems.  These
 * functions return ancillary information such as the name of the
 * OS, version numbers, etc.  If it could not be determined, these
 * return an error.
char *
  guestfs_inspect_get_name (guestfs_h *g, const char *root);
char *
  guestfs_inspect_get_arch (guestfs_h *g, const char *root);
char *
  guestfs_inspect_get_distro (guestfs_h *g, const char *root);
char *
  guestfs_inspect_get_product_name (guestfs_h *g, const char *root);
  guestfs_inspect_get_major_version (guestfs_h *g, const char *root);
  guestfs_inspect_get_minor_version (guestfs_h *g, const char *root);
char *
  guestfs_inspect_get_package_format (guestfs_h *g, const char *root);
char *
  guestfs_inspect_get_package_management (guestfs_h *g, const char *root);
char ** /* hash of mount point -> device */
  guestfs_inspect_get_mountpoints (guestfs_h *g, const char *root);
char ** /* list of filesystems */
  guestfs_inspect_get_filesystems (guestfs_h *g, const char *root);

Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://et.redhat.com/~rjones/libguestfs/
See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]