1394 Commits

Author SHA1 Message Date
Richard W.M. Jones
2066805a5d lib: Expose errno through new API guestfs_last_errno.
If either the daemon sends back an errno, or a system call
fails in the library, save the errno in the handle and then
make it available to callers through the guestfs_last_errno
function.
2010-11-03 18:48:56 +00:00
Richard W.M. Jones
d859c283c4 daemon: Send back the errno as a string.
This changes the protocol again so that if the errno is available,
it is converted to a string (like "EIO") and sent back over the
protocol to the library.

In this commit the library just discards the string.
2010-11-03 17:44:30 +00:00
Richard W.M. Jones
162c89ed49 capitests: Use ftruncate instead of seek + write to create test files. 2010-11-03 17:44:30 +00:00
Richard W.M. Jones
ec0fe45e48 capitests: Don't open test files with O_NONBLOCK.
I have no idea why we were doing this.
2010-11-03 17:44:30 +00:00
Richard W.M. Jones
2a33d81e2b capitests: Set path in TESTS_ENVIRONMENT instead of in tests.c
By exporting LIBGUESTFS_PATH with the right path to the appliance,
we no longer need to hard code the path in tests.c
2010-11-03 17:28:02 +00:00
Richard W.M. Jones
8ccc6cd1f7 generator: Remove unnecessary macro redefinitions.
These macros are already defined in guestfs-internals.h
2010-11-03 15:49:59 +00:00
Richard W.M. Jones
9ff9941836 daemon: Don't use ../src path to include generator_protocol.h
This file is already hard-linked into the current directory, so
the relative path is not required.
2010-11-03 13:15:19 +00:00
Richard W.M. Jones
c5a6584c4f tests: Remove use of sfdisk from tests.
Some older tests used sfdisk to create partitions for the
tests.  sfdisk is buggy (more so than parted -- what is it
with partitioning tools?) so replace these tests with
equivalent part-* commands.
2010-11-02 20:57:40 +00:00
Richard W.M. Jones
f0c28b391c inspect: Add support for MeeGo. 2010-11-02 10:11:04 +00:00
Richard Jones
7badf512f6 inspect: Add support for Ubuntu. 2010-10-29 11:54:54 +01:00
Richard Jones
96b44334dd inspect: Add detection of Gentoo. 2010-10-29 10:58:20 +01:00
Richard Jones
b4618fb060 inspect: Add detection of Arch Linux. 2010-10-29 10:55:40 +01:00
Richard Jones
233530d354 inspect: Add detection of Pardus. 2010-10-29 10:55:34 +01:00
Richard W.M. Jones
a51f56adb1 New API: inspect-get-windows-systemroot to get systemroot.
We are already using heuristics in the C inspection code to
determine the Windows %SYSTEMROOT% directory.  This change
just exposes this information through the API.
2010-10-28 15:16:15 +01:00
Richard W.M. Jones
33d6e0e723 Document problems mixing mkmountpoint and umount-all (RHBZ#599503). 2010-10-27 10:59:45 +01:00
Richard W.M. Jones
f48cd1f262 Enable autosync by default. 2010-10-27 10:59:45 +01:00
Richard W.M. Jones
b01ef8eae1 New API: lvm-canonical-lv-name: make LV name canonical.
When logical volume names appear in places like /etc/fstab
files they can have the form "/dev/mapper/foo-bar".  This
function takes such names and makes them canonical.

Note that this operation cannot be performed using the current
API, because 'guestfs_stat' does not work on device names, and
we don't really want to make a 'stat-device' call since that
exposes too much non-useful detail about the appliance.

With this patch you can do this:

><fs> debug ll /dev/mapper
total 8
drwxrwxr-x  2 root root   4096 Oct 25 12:51 .
drwxr-xr-x 16 root root   4096 Oct 25 12:51 ..
crw-------  1 root root 10, 62 Oct 25 12:51 control
lrwxrwxrwx  1 root root      7 Oct 25 12:51 vg_f13x64-lv_root -> ../dm-0
lrwxrwxrwx  1 root root      7 Oct 25 12:51 vg_f13x64-lv_swap -> ../dm-1

><fs> lvm-canonical-lv-name /dev/mapper/vg_f13x64-lv_root
/dev/vg_f13x64/lv_root
><fs> lvm-canonical-lv-name /dev/mapper/vg_f13x64-lv_swap
/dev/vg_f13x64/lv_swap
><fs> lvm-canonical-lv-name /dev/mapper/foo
libguestfs: error: lvm_canonical_lv_name: lvm_canonical_lv_name_stub: /dev/mapper/foo: No such file or directory
><fs> lvm-canonical-lv-name /dev/mapper/control
libguestfs: error: lvm_canonical_lv_name: /dev/mapper/control: not a logical volume
><fs> lvm-canonical-lv-name /dev/vg_f13x64/lv_root
/dev/vg_f13x64/lv_root
2010-10-27 10:59:45 +01:00
Matthew Booth
9332031543 Don't include control characters in BufferIn trace output (RHBZ#646822).
The example below shows what the output looks like for a large
random buffer.

$ guestfish -N fs -m /dev/sda1 -x -- \
    touch /test : \
    pwrite /test "$(dd if=/dev/urandom bs=128k count=1)" 0
[...]
pwrite "/test" "\x7f\xa0/\xb3\x80\xd3\xbc\xc3\xc3.\xb1\xe0\x1b\xafC\x06\xd5;\x0ajJ[o\xc1\xdd\xae\x1f\xce\xb2\x8d\xb3\xd0\x11\xcc$%\xe6<\xc7\xc7\xe7BU*\xc4l%\xaa\xea\xe9\x1an\xda]\xc6I\x0eC\xf9;\xec\x12a\x1f\xeaRH\xb2P\xd6+\xc4\xe6\xa5bW\x99\\x9d\xc8\x9bJ\xef\x99-\x16:h5\xe2\x0f\xa2\xa08\x9bU\x0b$\x138\xcf\xd4j\x9b\x83{%\xac0\xdaa1Xx\xbd`\x8e\xdd\x82\x87\x07\x98\xd2\x9ed\x8bq\xd0\x1f5\x8f\xab\xad4z1\xda\xc4b\xc1\xbc\x0f\xaa\xea\xc1\x15(\xfd1\xc2\x0bF\xe6\x9e\xb0+/g\\xab\xb0b\xde_\xca\xf9\xad\xe1?%\x17\xad\x98\xa4e\xc1\xe0f'\x89\xe9>\xff\xadhYi\xe7\x8c]%\xef\xe0\xa1R\xe5\xd5\x03K\xefI\xdf\xad\xd3\x82\xdb\x0f\xdd\xc3\x8f"\xf1G\xea\xf9r\xdd\xff\x88\x81\xb7\xf2\x0e\x0f\x1d;:\xf2F1\xdb\xb5D\xa1^\x928\xf5\x8e)\xab\xc4\xc3H(\xd0ol\xc6\xe4\xd6\xa3L\x1c\x06\xf4"<truncated, original size 130567 bytes> 0
[...]
2010-10-26 15:29:22 +01:00
Richard W.M. Jones
ae748ba3c1 fish: Quote optional argument name in error message. 2010-10-23 10:45:25 +01:00
Richard W.M. Jones
b7133b2709 fish: Reject unknown opt args (RHBZ#642934,CVE-2010-3851).
This updates commit 0c1d3c02a8.
2010-10-23 10:45:06 +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
87be9b26e7 generator: Rearrange argt logically (RHBZ#642934,CVE-2010-3851).
This structure has accreted over time.  Rearrange the types
into a logical order.
2010-10-22 17:11:32 +01:00
Richard W.M. Jones
ea62091980 generator: Refactor code for Perl bindings.
This simplifies the code that generates the Perl bindings
by removing repeated sections.
2010-10-21 13:59:36 +01:00
Richard W.M. Jones
ed74706d80 generator: Missing newline character. 2010-10-21 11:59:49 +01:00
Richard W.M. Jones
6391d1a7cf fish: Change 'int argc' to 'size_t argc' throughout. 2010-10-21 10:50:25 +01:00
Richard W.M. Jones
fcd75e021a generator: Remove unused parameter.
generate_c_call_args optional decl parameter is never actually
used, so remove it.
2010-10-20 13:35:43 +01:00
Richard W.M. Jones
6fbbcdd64c ocaml: Add g#ocaml_handle method. 2010-10-04 20:34:36 +01:00
Richard W.M. Jones
63bfcdbdd8 ocaml: Document g#close () method for objects. 2010-10-04 20:33:14 +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 W.M. Jones
7e4bf29fdf New API: pread-device, partial read for devices. 2010-09-27 12:04:44 +01:00
Richard W.M. Jones
eeaab2ba84 New API: pwrite-device
This is the same as the existing 'pwrite' API call, but allows you
to write to a device.
2010-09-26 22:21:36 +01:00
Richard W.M. Jones
c9c0ac7d36 Allow $TMPDIR to override most temporary directory uses.
Be more consistent in allowing the user to override use of the
temporary directory by specifying $TMPDIR.  Also prefer P_tmpdir
macro (defined in <stdio.h>) if that is defined, rather than
hard-coding "/tmp" for the fallback location.
2010-09-24 19:25:06 +01:00
Richard W.M. Jones
d75a2bff12 fish: Implement 'hexedit' command. 2010-09-21 19:51:22 +01:00
Richard W.M. Jones
5d4ae18e2b New APIs: upload-offset and download-offset
These APIs allow you to efficiently write and read parts of
files or devices.
2010-09-21 19:51:22 +01:00
Richard W.M. Jones
0003ea2c3d generator: Generate guestfish-only commands.
The guestfish-only commands such as 'alloc' and 'edit' are
now generated from one place in the generator instead of being
spread around ad-hoc in the C code.
2010-09-18 09:38:05 +01:00
Richard W.M. Jones
585fceb335 fish: In guestfish(1) turn command references into links. 2010-09-18 09:11:31 +01:00
Richard Jones
000c4a82fb New API: list-filesystems: list filesystems
This API is a simpler replacement for the guestfish commands
list-devices / list-partitions / lvs, in the case where you are
just examining a guest by hand to see what it contains.

Typical usage and output in guestfish is like this:

$ guestfish --ro -a /dev/vg_trick/F13x64
><fs> run
><fs> list-filesystems
/dev/vda1: ext4
/dev/vg_f13x64/lv_root: ext4
/dev/vg_f13x64/lv_swap: swap

It can also be used to replace programs that try to mount
devices to determine if they are mountable filesystems.
2010-09-15 19:42:23 +01:00
Richard Jones
ffd4820ffe New API: part-to-dev: Convert partition name to device name.
This adds a formal API for going from a partition to the containing
device, eg. /dev/sda1 -> /dev/sda
2010-09-15 17:16:51 +01:00
Richard Jones
ff38fea645 generator: Add TestOutputDevice.
This is for testing functions that return a device or partition
name, so that we can compare the return value with the canonical
device name (eg. "/dev/vda1" == "/dev/sda1").
2010-09-15 17:16:51 +01:00
Richard Jones
67fd3a7d99 generator: Provide no-op generator if no OCaml compiler. 2010-09-11 13:42:00 +01:00
Richard Jones
b42262c3db generator: Calculate MD5 of test.iso at runtime.
Because this used to be compiled into the C test, it changed
every time the ISO was rebuilt (which because of Makefile deps
was every run).

Now it is calculated at runtime so the C test file doesn't keep
changing.
2010-09-11 12:44:55 +01:00
Richard Jones
451a28349b generator: Don't use real uuidgen for UUIDs.
This was one reason why capitests/tests.c changed every time the
generator was run.
2010-09-11 12:44:52 +01:00
Richard Jones
04d8209077 Split generator into separate source files.
'src/generator.ml' is no more.  Instead the generator is logically
split up over many different source files.

Read generator/README for help and tips.

We compile the generator down to bytecode, not native code.  This
means it will run more slowly, but is done for maximum portability.
2010-09-11 12:04:44 +01:00