[PATCH 01/10] Revert "Revert "generator: Add CamelName flag""
by Matthew Booth
This reverts commit 3f6ca541c7b24d4c86688a509582cb41a7e0078c.
The original commit was reverted prematurely.
---
generator/generator_actions.ml | 10 +++++-----
generator/generator_checks.ml | 5 +++++
generator/generator_types.ml | 3 +++
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index 56691c5..d2e9f67 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -6189,7 +6189,7 @@ Note that for large devices this can take a long time to run.");
List all 9p filesystems attached to the guest. A list of
mount tags is returned.");
- ("mount_9p", (RErr, [String "mounttag"; String "mountpoint"], [OString "options"]), 286, [],
+ ("mount_9p", (RErr, [String "mounttag"; String "mountpoint"], [OString "options"]), 286, [CamelName "Mount9P"],
[],
"mount 9p filesystem",
"\
@@ -6213,7 +6213,7 @@ Device mapper devices which correspond to logical volumes are I<not>
returned in this list. Call C<guestfs_lvs> if you want to list logical
volumes.");
- ("ntfsresize_opts", (RErr, [Device "device"], [OInt64 "size"; OBool "force"]), 288, [Optional "ntfsprogs"],
+ ("ntfsresize_opts", (RErr, [Device "device"], [OInt64 "size"; OBool "force"]), 288, [Optional "ntfsprogs"; CamelName "NTFSResizeOpts"],
[],
"resize an NTFS filesystem",
"\
@@ -6245,7 +6245,7 @@ single filesystem without booting into Windows between each resize.
See also L<ntfsresize(8)>.");
- ("btrfs_filesystem_resize", (RErr, [Pathname "mountpoint"], [OInt64 "size"]), 289, [Optional "btrfs"],
+ ("btrfs_filesystem_resize", (RErr, [Pathname "mountpoint"], [OInt64 "size"]), 289, [Optional "btrfs"; CamelName "BTRFSFilesystemResize"],
[],
"resize a btrfs filesystem",
"\
@@ -6379,7 +6379,7 @@ is for copying blocks within existing files. See C<guestfs_cp>,
C<guestfs_cp_a> and C<guestfs_mv> for general file copying and
moving functions.");
- ("tune2fs", (RErr, [Device "device"], [OBool "force"; OInt "maxmountcount"; OInt "mountcount"; OString "errorbehavior"; OInt64 "group"; OInt "intervalbetweenchecks"; OInt "reservedblockspercentage"; OString "lastmounteddirectory"; OInt64 "reservedblockscount"; OInt64 "user"]), 298, [],
+ ("tune2fs", (RErr, [Device "device"], [OBool "force"; OInt "maxmountcount"; OInt "mountcount"; OString "errorbehavior"; OInt64 "group"; OInt "intervalbetweenchecks"; OInt "reservedblockspercentage"; OString "lastmounteddirectory"; OInt64 "reservedblockscount"; OInt64 "user"]), 298, [CamelName "Tune2FS"],
[InitScratchFS, Always, TestOutputHashtable (
[["tune2fs"; "/dev/sdb1"; "false"; "0"; ""; "NOARG"; ""; "0"; ""; "NOARG"; ""; ""];
["tune2fs_l"; "/dev/sdb1"]],
@@ -6476,7 +6476,7 @@ To get the current values of filesystem parameters, see
C<guestfs_tune2fs_l>. For precise details of how tune2fs
works, see the L<tune2fs(8)> man page.");
- ("md_create", (RErr, [String "name"; DeviceList "devices"], [OInt64 "missingbitmap"; OInt "nrdevices"; OInt "spare"; OInt64 "chunk"; OString "level"]), 299, [Optional "mdadm"],
+ ("md_create", (RErr, [String "name"; DeviceList "devices"], [OInt64 "missingbitmap"; OInt "nrdevices"; OInt "spare"; OInt64 "chunk"; OString "level"]), 299, [Optional "mdadm"; CamelName "MDCreate"],
[],
"create a Linux md (RAID) device",
"\
diff --git a/generator/generator_checks.ml b/generator/generator_checks.ml
index 4792dbf..464b9cd 100644
--- a/generator/generator_checks.ml
+++ b/generator/generator_checks.ml
@@ -208,6 +208,11 @@ let () =
failwithf "%s: Optional group name %s should not contain uppercase chars" name n;
if String.contains n '-' || String.contains n '_' then
failwithf "%s: Optional group name %s should not contain '-' or '_'" name n
+ | CamelName n ->
+ if not (contains_uppercase n) then
+ failwithf "%s: camel case name must contains uppercase characters" name n;
+ if String.contains n '_' then
+ failwithf "%s: camel case name must not contain '_'" name n;
| Cancellable ->
(match ret with
| RConstOptString n ->
diff --git a/generator/generator_types.ml b/generator/generator_types.ml
index d690377..233be54 100644
--- a/generator/generator_types.ml
+++ b/generator/generator_types.ml
@@ -222,6 +222,9 @@ type flags =
| DeprecatedBy of string (* function is deprecated, use .. instead *)
| Optional of string (* function is part of an optional group *)
| Progress (* function can generate progress messages *)
+ | CamelName of string (* Pretty camel case name of function. Only specify
+ this if the generator doesn't make a good job of
+ it, for example if it contains an abbreviation *)
| Cancellable (* The user can cancel this long-running function *)
and fish_output_t =
--
1.7.7.5
12 years, 10 months
GObject bindings overview
by Matthew Booth
I've summarised how the GObject bindings work below, which should
hopefully help reviewing the generator/generated code.
There are a couple of points in here I'm still not 100% happy with.
Specifically the handling of FBuffer and the Cancellable flag. Both are
explained below. I'm interested in suggestions.
Return values:
**************
All functions which can return an error have as their final argument a
GError **. GI maps this to the appropriate error mechanism for each
target language.
RErr returns a gboolean, true = success, false = failure.
The following types return the value from libguestfs unchanged:
RInt
RInt64
RBool
RConstString (transfer none): gobject doesn't manage returned memory
RConstOptString (transfer none). Methods don't return an error (no
GError**)
RString
RStringList
RHashtable is converted to a GHashTable. The keys and values from
libguestfs are inserted directly into the GHashTable without copying.
The top level array returned by libguestfs is freed.
RStruct is converted to GObject boxed type for the target struct. It
returns a copy of the struct, which is copied field by field. Memory for
the returned struct is allocated using glib's slice allocator. The
original struct is freed with guestfs_free_<struct>().
RStructList is converted as an array of structs, which are individually
converted the same way as RStruct, i.e. everything is copied. The
returned array is a newly allocated NULL-terminated array. The
originally returned value is freed with guestfs_free_<struct>_list().
RBufferOut is returned as a guint8 array, whose length is specified by a
size_r field. GObject uses both these fields to construct a single array
object where language bindings allow. The value returned by RBufferOut
is not copied.
Structs:
********
A parallel struct is created for each libguestfs struct type. A boxed
type is created for each parallel struct. It's field types are all
mapped trivially to gobject basic types (e.g. gchar *, gint32) except
FBuffer. FBuffer is mapped as:
guint8 *<field>
guint32 <field>_size
Unfortunately I can see no way to attach annotation to these fields, so
the bindings do not appreciate that these fields are related. I'm not
happy with this at all, so I may try manual tweaking of the .gir to see
if we can turn these into a single returned array where possible.
Required arguments:
*******************
Required arguments to methods are all mapped trivially to gobject basic
types. They are all passed directly to libguestfs. StringList and
DeviceList both remain null-terminated arrays. BufferIn has separate
array and length components, which are combined into a single array
using annotations where language bindings permit.
Optional arguments:
*******************
Optional arguments are implemented as a separate gobject whose name is
is Guestfs<camel api name>. This gobject has defined properties for each
optional argument accepted by the api. All properties are initially
undefined. Property types are mapped as:
OBool -> GuestfsTristate
OInt, OInt64 -> gint/gint64. -1 is used internally as a magic value
to represent undefined.
OString -> gchar *. NULL represents undefined.
GuestfsTristate is a new boxed enum type with values FALSE, TRUE and
UNSET. In the javascript bindings at least, passing in 'true' or 'false'
here works as expected. To set the UNSET value, you have to explicitly
use GuestfsTristate.UNSET.
OInt and OInt64 have a similar problem to boolean, in that there's no
way to represent unset in the fundamental type. The -1 = undefined
scheme is an internal detail and need not be part of the API. I did
create a patch to make the undefined number explicit for each optional
argument which required it. However I decided to hold off on it until we
actually create an api where this would be a problem, as it makes the
api definition in the generator slightly uglier and more complex.
Where no optional arguments are required, the user can pass in the
binding language's equivalent of NULL. GObject has a placeholder for
default values, but there are not yet implemented. When they are, we can
define the default value of optargs to be null, meaning they can be
entirely omitted when not required.
Cancellation:
*************
Certain apis are cancellable. These all take a GCancellable as the final
argument before GError **. This can be passed NULL if cancellation is
not required. While I have written cancellation, I have not yet tested
it *at all* other than it compiles and works correctly when NULL is
passed in.
We recently made Cancellable an explicit flag whereas before it was
implicit if the api had a FileIn or FileOut argument. This means it is
now possible to break the GObject api without breaking the C api with
the addition of a Cancellable flag. What potential solutions are there
to this problem? I can see:
• Live with breaking the GObject api if it ever comes up.
• Never add Cancellable to an existing api.
• Automatically add a GCancellable argument to all GObject apis, just in
case.
Events API
**********
The libguestfs events API is not yet bound. I'll add this at a later stage.
Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team
GPG ID: D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
12 years, 10 months
Re: [Libguestfs] CamelName patch
by Matthew Booth
On 01/19/2012 08:43 PM, Richard W.M. Jones wrote:
> I don't remember this commit coming up for review, although it seems
> to have been pushed upstream:
Well spotted! I was just about to point out that you did review it, when
I noticed I'd mixed this one up with a similar one. You reviewed the
other one. I have pushed this one accidentally.
> commit 83c20f02dc0e97b098e9de837839a3f4a4416129
> Author: Matthew Booth<mbooth(a)redhat.com>
> Date: Fri Jan 13 10:00:30 2012 +0000
>
> generator: Add CamelName flag
>
> We can make a good guess at camel case names for most APIs. For example,
> add_drive_opts can be automatically transformed to AddDriveOpts. However, ot
> apis don't produce a satisfactory name when transformed automatically. For
> example, we would want md_create to produce MDCreate rather than MdCreate.
>
> This change adds a CamelName flag which allows a camel case name to be speci
> explicitly when the automatic transformation isn't satisfactory.
>
>
> It seems to have a couple of problems: firstly it would change the
> Java bindings. In fact it doesn't do that because (secondly) the
> CamelName flag has no effect.
You're right that it has no effect. It should have been part of the
gobject series, which does use it.
Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team
GPG ID: D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
12 years, 10 months
[PATCH 1/3] daemon: pwrite/pread: Don't double close on error path.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
In Linux, close (fd) closes the file descriptor even if it returns an
error.
---
daemon/file.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/daemon/file.c b/daemon/file.c
index e0f8794..91746e0 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -483,7 +483,6 @@ pread_fd (int fd, int count, int64_t offset, size_t *size_r,
if (close (fd) == -1) {
reply_with_perror ("close: %s", display_path);
- close (fd);
free (buf);
return NULL;
}
@@ -539,7 +538,6 @@ pwrite_fd (int fd, const char *content, size_t size, int64_t offset,
if (close (fd) == -1) {
reply_with_perror ("close: %s", display_path);
- close (fd);
return -1;
}
--
1.7.6
12 years, 10 months
[PATCH 1/4] ocaml: Add -Wno-missing-field-initializers to avoid a warning.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
---
configure.ac | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index fa97479..6e42423 100644
--- a/configure.ac
+++ b/configure.ac
@@ -141,6 +141,10 @@ if test "$gl_gcc_warnings" = yes; then
# Work around warning in src/inspect.c. This seems to be a bug in gcc 4.5.1.
gl_WARN_ADD([-Wno-strict-overflow])
+ # Missing field initializers is not a bug in C. Adding this to $nw above
+ # did not work, so force it here instead.
+ gl_WARN_ADD([-Wno-missing-field-initializers])
+
gl_WARN_ADD([-fdiagnostics-show-option])
AC_SUBST([WARN_CFLAGS])
--
1.7.6
12 years, 10 months
GObject bindings
by Matthew Booth
This is the first iteration of the GObject bindings. I have 'kicked the tyres'
on these, meaning I have ensured that a bunch of basic manual tests work as
expected. I'm in the process of adding more comprehensive tests.
Here's an example simple javascript program which uses these bindings:
===
const Guestfs = imports.gi.Guestfs;
print('Starting');
var g = new Guestfs.Session();
var o = new Guestfs.AddDriveOpts({format: 'raw', iface: 'virtio'});
g.add_drive_opts('tests/guests/fedora.img', null);
g.launch();
r = g.inspect_os();
m = g.inspect_get_mountpoints(r[0]);
print(m['/boot']);
print('Finished');
===
Run this file as ./run gjs gobject-test.js
12 years, 10 months
[PATCH] New tool: virt-format
by Richard W.M. Jones
Rather than me explaining over again what it does, I've included the
man page below.
Rich.
----------------------------------------------------------------------
virt-format(1) Virtualization Support virt-format(1)
NAME
virt-format - Erase and make a blank disk
SYNOPSIS
virt-format [--options] -a disk.img [-a disk.img ...]
DESCRIPTION
Virt-format takes an existing disk file (or it can be a host partition,
LV etc), erases all data on it, and formats it as a blank disk. It can
optionally create partition tables, empty filesystems, logical volumes
and more.
To create a disk containing data, you may be better to use
virt-make-fs(1). If you are creating a blank disk to use in
guestfish(1), you should instead use the guestfish -N option.
Normal usage would be something like this:
virt-format -a disk.qcow
or this:
virt-format -a /dev/VG/LV
"disk.qcow" or "/dev/VG/LV" must exist already. Any data on these
disks will be erased by these commands. These commands will create a
single empty MBR partition covering the whole disk, with no filesystem
inside it.
Additional parameters can be used to control the creation of
partitions, filesystems, etc. The most commonly used options are:
--filesystem=[ext3|ntfs|vfat|...]
Create an empty filesystem ("ext3", "ntfs" etc) inside the
partition.
--lvm[=/dev/VG/LV]
Create a Linux LVM2 logical volume on the disk. When used with
--filesystem, the filesystem is created inside the LV.
For more information about these and other options, see "OPTIONS"
below.
The format of the disk is normally auto-detected, but you can also
force it by using the --format option (q.v.). In situations where you
do not trust the existing content of the disk, then it is advisable to
use this option to avoid possible exploits.
OPTIONS
--help
Display brief help.
-a file
--add file
Add file, a disk image, host partition, LV, external USB disk, etc.
The format of the disk image is auto-detected. To override this
and force a particular format use the --format=.. option.
Any existing data on the disk is erased.
--filesystem=ext3|ntfs|vfat|...
Create an empty filesystem of the specified type. Many filesystem
types are supported by libguestfs.
--filesystem=none
Create no filesystem. This is the default.
--format=raw|qcow2|..
--format
The default for the -a option is to auto-detect the format of the
disk image. Using this forces the disk format for -a options which
follow on the command line. Using --format with no argument
switches back to auto-detection for subsequent -a options.
For example:
virt-format --format=raw -a disk.img
forces raw format (no auto-detection) for "disk.img".
virt-format --format=raw -a disk.img --format -a another.img
forces raw format (no auto-detection) for "disk.img" and reverts to
auto-detection for "another.img".
If you have untrusted raw-format guest disk images, you should use
this option to specify the disk format. This avoids a possible
security problem with malicious guests (CVE-2010-3851).
--lvm=/dev/VG/LV
Create a Linux LVM2 logical volume called "/dev/VG/LV". You can
change the name of the volume group and logical volume.
--lvm
Create a Linux LVM2 logical volume with the default name
("/dev/VG/LV").
--lvm=none
Create no logical volume. This is the default.
--partition=gpt
Create a GPT partition instead of MBR. This is useful for disks
which are 2TB or larger in size.
--partition
--partition=mbr
Create an MBR partition. This is the default.
--partition=none
Create no partition table. Note that Windows may not be able to
see these disks.
-v
--verbose
Enable verbose messages for debugging.
-V
--version
Display version number and exit.
--wipe
Normally virt-format does not wipe data from the disk (because that
takes a long time). Thus if there is data on the disk, it is only
hidden and partially overwritten by virt-format, and it might be
recovered by disk editing tools.
If you use this option, virt-format writes zeroes over the whole
disk so that previous data is not recoverable.
-x Enable tracing of libguestfs API calls.
EXIT STATUS
This program returns 0 on success, or 1 on failure.
SEE ALSO
guestfs(3), guestfish(1), virt-filesystems(1), virt-make-fs(1),
virt-rescue(1), virt-resize(1), <http://libguestfs.org/>.
AUTHOR
Richard W.M. Jones <http://people.redhat.com/~rjones/>
COPYRIGHT
Copyright (C) 2012 Red Hat Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
libguestfs-1.15.16 2012-01-17 virt-format(1)
12 years, 10 months
GObject bindings (generated source)
by Matthew Booth
I've attached the generated gobject bindings for direct review.
Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team
GPG ID: D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
12 years, 10 months