Libguestfs gobject bindings
I'm currently working on gobject bindings for libguestfs. I haven't got as far as compiling anything yet, but I've attached the C header for initial 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
On Thu, Jan 12, 2012 at 11:59:22AM +0000, Matthew Booth wrote:
I'm currently working on gobject bindings for libguestfs. I haven't got as far as compiling anything yet, but I've attached the C header for initial review. typedef struct _GuestfsPV GuestfsPV; struct _GuestfsPV { gchar *pv_name; /* The next field is NOT nul-terminated, be careful when printing it: */ gchar pv_uuid[32];
How about a: #define GUESTFS_LVM_UUID_BUFLEN 32 and use that throughout
gchar *pv_fmt; guint64 pv_size; guint64 dev_size; guint64 pv_free; guint64 pv_used; gchar *pv_attr; gint64 pv_pe_count; gint64 pv_pe_alloc_count; gchar *pv_tags; guint64 pe_start; gint64 pv_mda_count; guint64 pv_mda_free; }; GType guestfs_lvm_pv_get_type(void);
typedef struct _GuestfsVG GuestfsVG; struct _GuestfsVG { gchar *vg_name; /* The next field is NOT nul-terminated, be careful when printing it: */ gchar vg_uuid[32]; gchar *vg_fmt; gchar *vg_attr; guint64 vg_size; guint64 vg_free; gchar *vg_sysid; guint64 vg_extent_size; gint64 vg_extent_count; gint64 vg_free_count; gint64 max_lv; gint64 max_pv; gint64 pv_count; gint64 lv_count; gint64 snap_count; gint64 vg_seqno; gchar *vg_tags; gint64 vg_mda_count; guint64 vg_mda_free; }; GType guestfs_lvm_vg_get_type(void);
typedef struct _GuestfsLV GuestfsLV; struct _GuestfsLV { gchar *lv_name; /* The next field is NOT nul-terminated, be careful when printing it: */ gchar lv_uuid[32]; gchar *lv_attr; gint64 lv_major; gint64 lv_minor; gint64 lv_kernel_major; gint64 lv_kernel_minor; guint64 lv_size; gint64 seg_count; gchar *origin; /* The next field is [0..100] or -1 meaning 'not present': */ gfloat snap_percent; /* The next field is [0..100] or -1 meaning 'not present': */ gfloat copy_percent; gchar *move_pv; gchar *lv_tags; gchar *mirror_log; gchar *modules; };
/* GuestfsMount9P */ #define GUESTFS_TYPE_MOUNT_9P (guestfs_mount_9p_get_type()) #define GUESTFS_MOUNT_9P(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GUESTFS_TYPE_MOUNT_9P, GuestfsMount9P)) #define GUESTFS_MOUNT_9P_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GUESTFS_TYPE_MOUNT_9P, GuestfsMount9PClass)) #define GUESTFS_IS_MOUNT_9P(obj) (G_TYPE_CHECK_INSTANCE_TYPE((klass), GUESTFS_TYPE_MOUNT_9P)) #define GUESTFS_IS_MOUNT_9P_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GUESTFS_TYPE_MOUNT_9P)) #define GUESTFS_MOUNT_9P_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GUESTFS_TYPE_MOUNT_9P, GuestfsMount9PClass))
typedef struct _GuestfsMount9P GuestfsMount9P; typedef struct _GuestfsMount9PPrivate GuestfsMount9PPrivate; typedef struct _GuestfsMount9PClass GuestfsMount9PClass;
struct _GuestfsMount9P { GObject parent; GuestfsMount9PPrivate *priv; };
struct _GuestfsMount9PClass { GObjectClass parent_class; };
GType guestfs_mount_9p_get_type(void); GuestfsMount9P *guestfs_mount_9p_new(void);
/* GuestfsNTFSResizeOpts */ #define GUESTFS_TYPE_NTFSRESIZE_OPTS (guestfs_ntfsresize_opts_get_type()) #define GUESTFS_NTFSRESIZE_OPTS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GUESTFS_TYPE_NTFSRESIZE_OPTS, GuestfsNTFSResizeOpts)) #define GUESTFS_NTFSRESIZE_OPTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GUESTFS_TYPE_NTFSRESIZE_OPTS, GuestfsNTFSResizeOptsClass)) #define GUESTFS_IS_NTFSRESIZE_OPTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((klass), GUESTFS_TYPE_NTFSRESIZE_OPTS)) #define GUESTFS_IS_NTFSRESIZE_OPTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GUESTFS_TYPE_NTFSRESIZE_OPTS)) #define GUESTFS_NTFSRESIZE_OPTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GUESTFS_TYPE_NTFSRESIZE_OPTS, GuestfsNTFSResizeOptsClass))
typedef struct _GuestfsNTFSResizeOpts GuestfsNTFSResizeOpts; typedef struct _GuestfsNTFSResizeOptsPrivate GuestfsNTFSResizeOptsPrivate; typedef struct _GuestfsNTFSResizeOptsClass GuestfsNTFSResizeOptsClass;
struct _GuestfsNTFSResizeOpts { GObject parent; GuestfsNTFSResizeOptsPrivate *priv; };
struct _GuestfsNTFSResizeOptsClass { GObjectClass parent_class; };
GType guestfs_ntfsresize_opts_get_type(void); GuestfsNTFSResizeOpts *guestfs_ntfsresize_opts_new(void);
/* GuestfsBTRFSFilesystemResize */ #define GUESTFS_TYPE_BTRFS_FILESYSTEM_RESIZE (guestfs_btrfs_filesystem_resize_get_type()) #define GUESTFS_BTRFS_FILESYSTEM_RESIZE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GUESTFS_TYPE_BTRFS_FILESYSTEM_RESIZE, GuestfsBTRFSFilesystemResize)) #define GUESTFS_BTRFS_FILESYSTEM_RESIZE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GUESTFS_TYPE_BTRFS_FILESYSTEM_RESIZE, GuestfsBTRFSFilesystemResizeClass)) #define GUESTFS_IS_BTRFS_FILESYSTEM_RESIZE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((klass), GUESTFS_TYPE_BTRFS_FILESYSTEM_RESIZE)) #define GUESTFS_IS_BTRFS_FILESYSTEM_RESIZE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GUESTFS_TYPE_BTRFS_FILESYSTEM_RESIZE)) #define GUESTFS_BTRFS_FILESYSTEM_RESIZE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GUESTFS_TYPE_BTRFS_FILESYSTEM_RESIZE, GuestfsBTRFSFilesystemResizeClass))
typedef struct _GuestfsBTRFSFilesystemResize GuestfsBTRFSFilesystemResize; typedef struct _GuestfsBTRFSFilesystemResizePrivate GuestfsBTRFSFilesystemResizePrivate; typedef struct _GuestfsBTRFSFilesystemResizeClass GuestfsBTRFSFilesystemResizeClass;
struct _GuestfsBTRFSFilesystemResize { GObject parent; GuestfsBTRFSFilesystemResizePrivate *priv; };
struct _GuestfsBTRFSFilesystemResizeClass { GObjectClass parent_class; };
GType guestfs_btrfs_filesystem_resize_get_type(void); GuestfsBTRFSFilesystemResize *guestfs_btrfs_filesystem_resize_new(void);
Obviously all these methods should have 'guestfs_session_' as a prefix
/* Generated methods */ gboolean test0(GuestfsSession *session, const gchar *str, const gchar *optstr, GSList *strlist, gboolean b, gint32 integer, gint64 integer64, const gchar *filein, const gchar *fileout, GByteArray *bufferin, GError **err); gint32 test0rint(GuestfsSession *session, const gchar *val, GError **err); gint32 test0rinterr(GuestfsSession *session, , GError **err); gint64 test0rint64(GuestfsSession *session, const gchar *val, GError **err); gint64 test0rint64err(GuestfsSession *session, , GError **err); gboolean test0rbool(GuestfsSession *session, const gchar *val, GError **err); gboolean test0rboolerr(GuestfsSession *session, , GError **err); gchar *test0rconststring(GuestfsSession *session, const gchar *val, GError **err); gchar *test0rconststringerr(GuestfsSession *session, , GError **err); gchar *test0rconstoptstring(GuestfsSession *session, const gchar *val); gchar *test0rconstoptstringerr(GuestfsSession *session, ); gchar *test0rstring(GuestfsSession *session, const gchar *val, GError **err); gchar *test0rstringerr(GuestfsSession *session, , GError **err); GSList *test0rstringlist(GuestfsSession *session, const gchar *val, GError **err); GSList *test0rstringlisterr(GuestfsSession *session, , GError **err); GuestfsPV *test0rstruct(GuestfsSession *session, const gchar *val, GError **err); GuestfsPV *test0rstructerr(GuestfsSession *session, , GError **err); GSList *test0rstructlist(GuestfsSession *session, const gchar *val, GError **err); GSList *test0rstructlisterr(GuestfsSession *session, , GError **err); GHashTable *test0rhashtable(GuestfsSession *session, const gchar *val, GError **err); GHashTable *test0rhashtableerr(GuestfsSession *session, , GError **err); gboolean launch(GuestfsSession *session, , GError **err); gboolean wait_ready(GuestfsSession *session, , GError **err); gboolean kill_subprocess(GuestfsSession *session, , GError **err); gboolean add_drive(GuestfsSession *session, const gchar *filename, GError **err); gboolean add_cdrom(GuestfsSession *session, const gchar *filename, GError **err); gboolean add_drive_ro(GuestfsSession *session, const gchar *filename, GError **err); gboolean config(GuestfsSession *session, const gchar *qemuparam, const gchar *qemuvalue, GError **err); gboolean set_qemu(GuestfsSession *session, const gchar *qemu, GError **err); gchar *get_qemu(GuestfsSession *session, , GError **err); gboolean set_path(GuestfsSession *session, const gchar *searchpath, GError **err); gchar *get_path(GuestfsSession *session, , GError **err); gboolean set_append(GuestfsSession *session, const gchar *append, GError **err); gchar *get_append(GuestfsSession *session, ); gboolean set_autosync(GuestfsSession *session, gboolean autosync, GError **err); gboolean get_autosync(GuestfsSession *session, , GError **err); gboolean set_verbose(GuestfsSession *session, gboolean verbose, GError **err); gboolean get_verbose(GuestfsSession *session, , GError **err); gboolean is_ready(GuestfsSession *session, , GError **err); gboolean is_config(GuestfsSession *session, , GError **err); gboolean is_launching(GuestfsSession *session, , GError **err); gboolean is_busy(GuestfsSession *session, , GError **err); gint32 get_state(GuestfsSession *session, , GError **err); gboolean set_memsize(GuestfsSession *session, gint32 memsize, GError **err); gint32 get_memsize(GuestfsSession *session, , GError **err); gint32 get_pid(GuestfsSession *session, , GError **err); GuestfsVersion *version(GuestfsSession *session, , GError **err); gboolean set_selinux(GuestfsSession *session, gboolean selinux, GError **err); gboolean get_selinux(GuestfsSession *session, , GError **err); gboolean set_trace(GuestfsSession *session, gboolean trace, GError **err); gboolean get_trace(GuestfsSession *session, , GError **err); gboolean set_direct(GuestfsSession *session, gboolean direct, GError **err); gboolean get_direct(GuestfsSession *session, , GError **err); gboolean set_recovery_proc(GuestfsSession *session, gboolean recoveryproc, GError **err); gboolean get_recovery_proc(GuestfsSession *session, , GError **err); gboolean add_drive_with_if(GuestfsSession *session, const gchar *filename, const gchar *iface, GError **err); gboolean add_drive_ro_with_if(GuestfsSession *session, const gchar *filename, const gchar *iface, GError **err); gchar *file_architecture(GuestfsSession *session, const gchar *filename, GError **err); GSList *inspect_os(GuestfsSession *session, , GError **err); gchar *inspect_get_type(GuestfsSession *session, const gchar *root, GError **err); gchar *inspect_get_arch(GuestfsSession *session, const gchar *root, GError **err); gchar *inspect_get_distro(GuestfsSession *session, const gchar *root, GError **err); gint32 inspect_get_major_version(GuestfsSession *session, const gchar *root, GError **err); gint32 inspect_get_minor_version(GuestfsSession *session, const gchar *root, GError **err); gchar *inspect_get_product_name(GuestfsSession *session, const gchar *root, GError **err); GHashTable *inspect_get_mountpoints(GuestfsSession *session, const gchar *root, GError **err); GSList *inspect_get_filesystems(GuestfsSession *session, const gchar *root, GError **err); gboolean set_network(GuestfsSession *session, gboolean network, GError **err); gboolean get_network(GuestfsSession *session, , GError **err); GHashTable *list_filesystems(GuestfsSession *session, , GError **err); gboolean add_drive_opts(GuestfsSession *session, const gchar *filename, GuestfsAddDriveOpts *optargs, GError **err); gchar *inspect_get_windows_systemroot(GuestfsSession *session, const gchar *root, GError **err); GSList *inspect_get_roots(GuestfsSession *session, , GError **err); GSList *debug_cmdline(GuestfsSession *session, , GError **err); GSList *debug_drives(GuestfsSession *session, , GError **err); gint32 add_domain(GuestfsSession *session, const gchar *dom, GuestfsAddDomain *optargs, GError **err); gchar *inspect_get_package_format(GuestfsSession *session, const gchar *root, GError **err); gchar *inspect_get_package_management(GuestfsSession *session, const gchar *root, GError **err); GSList *inspect_list_applications(GuestfsSession *session, const gchar *root, GError **err); gchar *inspect_get_hostname(GuestfsSession *session, const gchar *root, GError **err); gchar *inspect_get_format(GuestfsSession *session, const gchar *root, GError **err); gboolean inspect_is_live(GuestfsSession *session, const gchar *root, GError **err); gboolean inspect_is_netinst(GuestfsSession *session, const gchar *root, GError **err); gboolean inspect_is_multipart(GuestfsSession *session, const gchar *root, GError **err); gboolean set_attach_method(GuestfsSession *session, const gchar *attachmethod, GError **err); gchar *get_attach_method(GuestfsSession *session, , GError **err); gchar *inspect_get_product_variant(GuestfsSession *session, const gchar *root, GError **err); gchar *inspect_get_windows_current_control_set(GuestfsSession *session, const gchar *root, GError **err); GHashTable *inspect_get_drive_mappings(GuestfsSession *session, const gchar *root, GError **err); GByteArray *inspect_get_icon(GuestfsSession *session, const gchar *root, GuestfsInspectGetIcon *optargs, GError **err); gboolean set_pgroup(GuestfsSession *session, gboolean pgroup, GError **err); gboolean get_pgroup(GuestfsSession *session, , GError **err); gboolean set_smp(GuestfsSession *session, gint32 smp, GError **err); gint32 get_smp(GuestfsSession *session, , GError **err); gboolean mount(GuestfsSession *session, const gchar *device, const gchar *mountpoint, GError **err); gboolean sync(GuestfsSession *session, , GError **err); gboolean touch(GuestfsSession *session, const gchar *path, GError **err); gchar *cat(GuestfsSession *session, const gchar *path, GError **err); gchar *ll(GuestfsSession *session, const gchar *directory, GError **err); GSList *ls(GuestfsSession *session, const gchar *directory, GError **err); GSList *list_devices(GuestfsSession *session, , GError **err); GSList *list_partitions(GuestfsSession *session, , GError **err); GSList *pvs(GuestfsSession *session, , GError **err); GSList *vgs(GuestfsSession *session, , GError **err); GSList *lvs(GuestfsSession *session, , GError **err); GSList *pvs_full(GuestfsSession *session, , GError **err); GSList *vgs_full(GuestfsSession *session, , GError **err); GSList *lvs_full(GuestfsSession *session, , GError **err); GSList *read_lines(GuestfsSession *session, const gchar *path, GError **err); gboolean aug_init(GuestfsSession *session, const gchar *root, gint32 flags, GError **err); gboolean aug_close(GuestfsSession *session, , GError **err); gint32 aug_defvar(GuestfsSession *session, const gchar *name, const gchar *expr, GError **err); GuestfsIntBool *aug_defnode(GuestfsSession *session, const gchar *name, const gchar *expr, const gchar *val, GError **err); gchar *aug_get(GuestfsSession *session, const gchar *augpath, GError **err); gboolean aug_set(GuestfsSession *session, const gchar *augpath, const gchar *val, GError **err); gboolean aug_insert(GuestfsSession *session, const gchar *augpath, const gchar *label, gboolean before, GError **err); gint32 aug_rm(GuestfsSession *session, const gchar *augpath, GError **err); gboolean aug_mv(GuestfsSession *session, const gchar *src, const gchar *dest, GError **err); GSList *aug_match(GuestfsSession *session, const gchar *augpath, GError **err); gboolean aug_save(GuestfsSession *session, , GError **err); gboolean aug_load(GuestfsSession *session, , GError **err); GSList *aug_ls(GuestfsSession *session, const gchar *augpath, GError **err); gboolean rm(GuestfsSession *session, const gchar *path, GError **err); gboolean rmdir(GuestfsSession *session, const gchar *path, GError **err); gboolean rm_rf(GuestfsSession *session, const gchar *path, GError **err); gboolean mkdir(GuestfsSession *session, const gchar *path, GError **err); gboolean mkdir_p(GuestfsSession *session, const gchar *path, GError **err); gboolean chmod(GuestfsSession *session, gint32 mode, const gchar *path, GError **err); gboolean chown(GuestfsSession *session, gint32 owner, gint32 group, const gchar *path, GError **err); gboolean exists(GuestfsSession *session, const gchar *path, GError **err); gboolean is_file(GuestfsSession *session, const gchar *path, GError **err); gboolean is_dir(GuestfsSession *session, const gchar *path, GError **err); gboolean pvcreate(GuestfsSession *session, const gchar *device, GError **err); gboolean vgcreate(GuestfsSession *session, const gchar *volgroup, GSList *physvols, GError **err); gboolean lvcreate(GuestfsSession *session, const gchar *logvol, const gchar *volgroup, gint32 mbytes, GError **err); gboolean mkfs(GuestfsSession *session, const gchar *fstype, const gchar *device, GError **err); gboolean sfdisk(GuestfsSession *session, const gchar *device, gint32 cyls, gint32 heads, gint32 sectors, GSList *lines, GError **err); gboolean write_file(GuestfsSession *session, const gchar *path, const gchar *content, gint32 size, GError **err); gboolean umount(GuestfsSession *session, const gchar *pathordevice, GError **err); GSList *mounts(GuestfsSession *session, , GError **err); gboolean umount_all(GuestfsSession *session, , GError **err); gboolean lvm_remove_all(GuestfsSession *session, , GError **err); gchar *file(GuestfsSession *session, const gchar *path, GError **err); gchar *command(GuestfsSession *session, GSList *arguments, GError **err); GSList *command_lines(GuestfsSession *session, GSList *arguments, GError **err); GuestfsStat *stat(GuestfsSession *session, const gchar *path, GError **err); GuestfsStat *lstat(GuestfsSession *session, const gchar *path, GError **err); GuestfsStatVFS *statvfs(GuestfsSession *session, const gchar *path, GError **err); GHashTable *tune2fs_l(GuestfsSession *session, const gchar *device, GError **err); gboolean blockdev_setro(GuestfsSession *session, const gchar *device, GError **err); gboolean blockdev_setrw(GuestfsSession *session, const gchar *device, GError **err); gboolean blockdev_getro(GuestfsSession *session, const gchar *device, GError **err); gint32 blockdev_getss(GuestfsSession *session, const gchar *device, GError **err); gint32 blockdev_getbsz(GuestfsSession *session, const gchar *device, GError **err); gboolean blockdev_setbsz(GuestfsSession *session, const gchar *device, gint32 blocksize, GError **err); gint64 blockdev_getsz(GuestfsSession *session, const gchar *device, GError **err); gint64 blockdev_getsize64(GuestfsSession *session, const gchar *device, GError **err); gboolean blockdev_flushbufs(GuestfsSession *session, const gchar *device, GError **err); gboolean blockdev_rereadpt(GuestfsSession *session, const gchar *device, GError **err); gboolean upload(GuestfsSession *session, const gchar *filename, const gchar *remotefilename, GError **err); gboolean download(GuestfsSession *session, const gchar *remotefilename, const gchar *filename, GError **err); gchar *checksum(GuestfsSession *session, const gchar *csumtype, const gchar *path, GError **err); gboolean tar_in(GuestfsSession *session, const gchar *tarfile, const gchar *directory, GError **err); gboolean tar_out(GuestfsSession *session, const gchar *directory, const gchar *tarfile, GError **err); gboolean tgz_in(GuestfsSession *session, const gchar *tarball, const gchar *directory, GError **err); gboolean tgz_out(GuestfsSession *session, const gchar *directory, const gchar *tarball, GError **err); gboolean mount_ro(GuestfsSession *session, const gchar *device, const gchar *mountpoint, GError **err); gboolean mount_options(GuestfsSession *session, const gchar *options, const gchar *device, const gchar *mountpoint, GError **err); gboolean mount_vfs(GuestfsSession *session, const gchar *options, const gchar *vfstype, const gchar *device, const gchar *mountpoint, GError **err); gchar *debug(GuestfsSession *session, const gchar *subcmd, GSList *extraargs, GError **err); gboolean lvremove(GuestfsSession *session, const gchar *device, GError **err); gboolean vgremove(GuestfsSession *session, const gchar *vgname, GError **err); gboolean pvremove(GuestfsSession *session, const gchar *device, GError **err); gboolean set_e2label(GuestfsSession *session, const gchar *device, const gchar *label, GError **err); gchar *get_e2label(GuestfsSession *session, const gchar *device, GError **err); gboolean set_e2uuid(GuestfsSession *session, const gchar *device, const gchar *uuid, GError **err); gchar *get_e2uuid(GuestfsSession *session, const gchar *device, GError **err); gint32 fsck(GuestfsSession *session, const gchar *fstype, const gchar *device, GError **err); gboolean zero(GuestfsSession *session, const gchar *device, GError **err); gboolean grub_install(GuestfsSession *session, const gchar *root, const gchar *device, GError **err); gboolean cp(GuestfsSession *session, const gchar *src, const gchar *dest, GError **err); gboolean cp_a(GuestfsSession *session, const gchar *src, const gchar *dest, GError **err); gboolean mv(GuestfsSession *session, const gchar *src, const gchar *dest, GError **err); gboolean drop_caches(GuestfsSession *session, gint32 whattodrop, GError **err); gchar *dmesg(GuestfsSession *session, , GError **err); gboolean ping_daemon(GuestfsSession *session, , GError **err); gboolean equal(GuestfsSession *session, const gchar *file1, const gchar *file2, GError **err); GSList *strings(GuestfsSession *session, const gchar *path, GError **err); GSList *strings_e(GuestfsSession *session, const gchar *encoding, const gchar *path, GError **err); gchar *hexdump(GuestfsSession *session, const gchar *path, GError **err); gboolean zerofree(GuestfsSession *session, const gchar *device, GError **err); gboolean pvresize(GuestfsSession *session, const gchar *device, GError **err); gboolean sfdisk_N(GuestfsSession *session, const gchar *device, gint32 partnum, gint32 cyls, gint32 heads, gint32 sectors, const gchar *line, GError **err); gchar *sfdisk_l(GuestfsSession *session, const gchar *device, GError **err); gchar *sfdisk_kernel_geometry(GuestfsSession *session, const gchar *device, GError **err); gchar *sfdisk_disk_geometry(GuestfsSession *session, const gchar *device, GError **err); gboolean vg_activate_all(GuestfsSession *session, gboolean activate, GError **err); gboolean vg_activate(GuestfsSession *session, gboolean activate, GSList *volgroups, GError **err); gboolean lvresize(GuestfsSession *session, const gchar *device, gint32 mbytes, GError **err); gboolean resize2fs(GuestfsSession *session, const gchar *device, GError **err); GSList *find(GuestfsSession *session, const gchar *directory, GError **err); gboolean e2fsck_f(GuestfsSession *session, const gchar *device, GError **err); gboolean sleep(GuestfsSession *session, gint32 secs, GError **err); gint32 ntfs_3g_probe(GuestfsSession *session, gboolean rw, const gchar *device, GError **err); gchar *sh(GuestfsSession *session, const gchar *command, GError **err); GSList *sh_lines(GuestfsSession *session, const gchar *command, GError **err); GSList *glob_expand(GuestfsSession *session, const gchar *pattern, GError **err); gboolean scrub_device(GuestfsSession *session, const gchar *device, GError **err); gboolean scrub_file(GuestfsSession *session, const gchar *file, GError **err); gboolean scrub_freespace(GuestfsSession *session, const gchar *dir, GError **err); gchar *mkdtemp(GuestfsSession *session, const gchar *template, GError **err); gint32 wc_l(GuestfsSession *session, const gchar *path, GError **err); gint32 wc_w(GuestfsSession *session, const gchar *path, GError **err); gint32 wc_c(GuestfsSession *session, const gchar *path, GError **err); GSList *head(GuestfsSession *session, const gchar *path, GError **err); GSList *head_n(GuestfsSession *session, gint32 nrlines, const gchar *path, GError **err); GSList *tail(GuestfsSession *session, const gchar *path, GError **err); GSList *tail_n(GuestfsSession *session, gint32 nrlines, const gchar *path, GError **err); gchar *df(GuestfsSession *session, , GError **err); gchar *df_h(GuestfsSession *session, , GError **err);
Some missing parameters here & in a few other cases.
gint64 du(GuestfsSession *session, const gchar *path, GError **err); GSList *initrd_list(GuestfsSession *session, const gchar *path, GError **err); gboolean mount_loop(GuestfsSession *session, const gchar *file, const gchar *mountpoint, GError **err); gboolean mkswap(GuestfsSession *session, const gchar *device, GError **err); gboolean mkswap_L(GuestfsSession *session, const gchar *label, const gchar *device, GError **err); gboolean mkswap_U(GuestfsSession *session, const gchar *uuid, const gchar *device, GError **err); gboolean mknod(GuestfsSession *session, gint32 mode, gint32 devmajor, gint32 devminor, const gchar *path, GError **err); gboolean mkfifo(GuestfsSession *session, gint32 mode, const gchar *path, GError **err); gboolean mknod_b(GuestfsSession *session, gint32 mode, gint32 devmajor, gint32 devminor, const gchar *path, GError **err); gboolean mknod_c(GuestfsSession *session, gint32 mode, gint32 devmajor, gint32 devminor, const gchar *path, GError **err); gint32 umask(GuestfsSession *session, gint32 mask, GError **err); GSList *readdir(GuestfsSession *session, const gchar *dir, GError **err); gboolean sfdiskM(GuestfsSession *session, const gchar *device, GSList *lines, GError **err); gchar *zfile(GuestfsSession *session, const gchar *meth, const gchar *path, GError **err); GSList *getxattrs(GuestfsSession *session, const gchar *path, GError **err); GSList *lgetxattrs(GuestfsSession *session, const gchar *path, GError **err); gboolean setxattr(GuestfsSession *session, const gchar *xattr, const gchar *val, gint32 vallen, const gchar *path, GError **err); gboolean lsetxattr(GuestfsSession *session, const gchar *xattr, const gchar *val, gint32 vallen, const gchar *path, GError **err); gboolean removexattr(GuestfsSession *session, const gchar *xattr, const gchar *path, GError **err); gboolean lremovexattr(GuestfsSession *session, const gchar *xattr, const gchar *path, GError **err); GHashTable *mountpoints(GuestfsSession *session, , GError **err); gboolean mkmountpoint(GuestfsSession *session, const gchar *exemptpath, GError **err); gboolean rmmountpoint(GuestfsSession *session, const gchar *exemptpath, GError **err); GByteArray *read_file(GuestfsSession *session, const gchar *path, GError **err); GSList *grep(GuestfsSession *session, const gchar *regex, const gchar *path, GError **err); GSList *egrep(GuestfsSession *session, const gchar *regex, const gchar *path, GError **err); GSList *fgrep(GuestfsSession *session, const gchar *pattern, const gchar *path, GError **err); GSList *grepi(GuestfsSession *session, const gchar *regex, const gchar *path, GError **err); GSList *egrepi(GuestfsSession *session, const gchar *regex, const gchar *path, GError **err); GSList *fgrepi(GuestfsSession *session, const gchar *pattern, const gchar *path, GError **err); GSList *zgrep(GuestfsSession *session, const gchar *regex, const gchar *path, GError **err); GSList *zegrep(GuestfsSession *session, const gchar *regex, const gchar *path, GError **err); GSList *zfgrep(GuestfsSession *session, const gchar *pattern, const gchar *path, GError **err); GSList *zgrepi(GuestfsSession *session, const gchar *regex, const gchar *path, GError **err); GSList *zegrepi(GuestfsSession *session, const gchar *regex, const gchar *path, GError **err); GSList *zfgrepi(GuestfsSession *session, const gchar *pattern, const gchar *path, GError **err); gchar *realpath(GuestfsSession *session, const gchar *path, GError **err); gboolean ln(GuestfsSession *session, const gchar *target, const gchar *linkname, GError **err); gboolean ln_f(GuestfsSession *session, const gchar *target, const gchar *linkname, GError **err); gboolean ln_s(GuestfsSession *session, const gchar *target, const gchar *linkname, GError **err); gboolean ln_sf(GuestfsSession *session, const gchar *target, const gchar *linkname, GError **err); gchar *readlink(GuestfsSession *session, const gchar *path, GError **err); gboolean fallocate(GuestfsSession *session, const gchar *path, gint32 len, GError **err); gboolean swapon_device(GuestfsSession *session, const gchar *device, GError **err); gboolean swapoff_device(GuestfsSession *session, const gchar *device, GError **err); gboolean swapon_file(GuestfsSession *session, const gchar *file, GError **err); gboolean swapoff_file(GuestfsSession *session, const gchar *file, GError **err); gboolean swapon_label(GuestfsSession *session, const gchar *label, GError **err); gboolean swapoff_label(GuestfsSession *session, const gchar *label, GError **err); gboolean swapon_uuid(GuestfsSession *session, const gchar *uuid, GError **err); gboolean swapoff_uuid(GuestfsSession *session, const gchar *uuid, GError **err); gboolean mkswap_file(GuestfsSession *session, const gchar *path, GError **err); gboolean inotify_init(GuestfsSession *session, gint32 maxevents, GError **err); gint64 inotify_add_watch(GuestfsSession *session, const gchar *path, gint32 mask, GError **err); gboolean inotify_rm_watch(GuestfsSession *session, gint32 wd, GError **err); GSList *inotify_read(GuestfsSession *session, , GError **err); GSList *inotify_files(GuestfsSession *session, , GError **err); gboolean inotify_close(GuestfsSession *session, , GError **err); gboolean setcon(GuestfsSession *session, const gchar *context, GError **err); gchar *getcon(GuestfsSession *session, , GError **err); gboolean mkfs_b(GuestfsSession *session, const gchar *fstype, gint32 blocksize, const gchar *device, GError **err); gboolean mke2journal(GuestfsSession *session, gint32 blocksize, const gchar *device, GError **err); gboolean mke2journal_L(GuestfsSession *session, gint32 blocksize, const gchar *label, const gchar *device, GError **err); gboolean mke2journal_U(GuestfsSession *session, gint32 blocksize, const gchar *uuid, const gchar *device, GError **err); gboolean mke2fs_J(GuestfsSession *session, const gchar *fstype, gint32 blocksize, const gchar *device, const gchar *journal, GError **err); gboolean mke2fs_JL(GuestfsSession *session, const gchar *fstype, gint32 blocksize, const gchar *device, const gchar *label, GError **err); gboolean mke2fs_JU(GuestfsSession *session, const gchar *fstype, gint32 blocksize, const gchar *device, const gchar *uuid, GError **err); gboolean modprobe(GuestfsSession *session, const gchar *modulename, GError **err); gchar *echo_daemon(GuestfsSession *session, GSList *words, GError **err); gboolean find0(GuestfsSession *session, const gchar *directory, const gchar *files, GError **err); gchar *case_sensitive_path(GuestfsSession *session, const gchar *path, GError **err); gchar *vfs_type(GuestfsSession *session, const gchar *device, GError **err); gboolean truncate(GuestfsSession *session, const gchar *path, GError **err); gboolean truncate_size(GuestfsSession *session, const gchar *path, gint64 size, GError **err); gboolean utimens(GuestfsSession *session, const gchar *path, gint64 atsecs, gint64 atnsecs, gint64 mtsecs, gint64 mtnsecs, GError **err); gboolean mkdir_mode(GuestfsSession *session, const gchar *path, gint32 mode, GError **err); gboolean lchown(GuestfsSession *session, gint32 owner, gint32 group, const gchar *path, GError **err); GSList *lstatlist(GuestfsSession *session, const gchar *path, GSList *names, GError **err); GSList *lxattrlist(GuestfsSession *session, const gchar *path, GSList *names, GError **err); GSList *readlinklist(GuestfsSession *session, const gchar *path, GSList *names, GError **err); GByteArray *pread(GuestfsSession *session, const gchar *path, gint32 count, gint64 offset, GError **err); gboolean part_init(GuestfsSession *session, const gchar *device, const gchar *parttype, GError **err); gboolean part_add(GuestfsSession *session, const gchar *device, const gchar *prlogex, gint64 startsect, gint64 endsect, GError **err); gboolean part_disk(GuestfsSession *session, const gchar *device, const gchar *parttype, GError **err); gboolean part_set_bootable(GuestfsSession *session, const gchar *device, gint32 partnum, gboolean bootable, GError **err); gboolean part_set_name(GuestfsSession *session, const gchar *device, gint32 partnum, const gchar *name, GError **err); GSList *part_list(GuestfsSession *session, const gchar *device, GError **err); gchar *part_get_parttype(GuestfsSession *session, const gchar *device, GError **err); gboolean fill(GuestfsSession *session, gint32 c, gint32 len, const gchar *path, GError **err); gboolean available(GuestfsSession *session, GSList *groups, GError **err); gboolean dd(GuestfsSession *session, const gchar *src, const gchar *dest, GError **err); gint64 filesize(GuestfsSession *session, const gchar *file, GError **err); gboolean lvrename(GuestfsSession *session, const gchar *logvol, const gchar *newlogvol, GError **err); gboolean vgrename(GuestfsSession *session, const gchar *volgroup, const gchar *newvolgroup, GError **err); GByteArray *initrd_cat(GuestfsSession *session, const gchar *initrdpath, const gchar *filename, GError **err); gchar *pvuuid(GuestfsSession *session, const gchar *device, GError **err); gchar *vguuid(GuestfsSession *session, const gchar *vgname, GError **err); gchar *lvuuid(GuestfsSession *session, const gchar *device, GError **err); GSList *vgpvuuids(GuestfsSession *session, const gchar *vgname, GError **err); GSList *vglvuuids(GuestfsSession *session, const gchar *vgname, GError **err); gboolean copy_size(GuestfsSession *session, const gchar *src, const gchar *dest, gint64 size, GError **err); gboolean zero_device(GuestfsSession *session, const gchar *device, GError **err); gboolean txz_in(GuestfsSession *session, const gchar *tarball, const gchar *directory, GError **err); gboolean txz_out(GuestfsSession *session, const gchar *directory, const gchar *tarball, GError **err); gboolean ntfsresize(GuestfsSession *session, const gchar *device, GError **err); gboolean vgscan(GuestfsSession *session, , GError **err); gboolean part_del(GuestfsSession *session, const gchar *device, gint32 partnum, GError **err); gboolean part_get_bootable(GuestfsSession *session, const gchar *device, gint32 partnum, GError **err); gint32 part_get_mbr_id(GuestfsSession *session, const gchar *device, gint32 partnum, GError **err); gboolean part_set_mbr_id(GuestfsSession *session, const gchar *device, gint32 partnum, gint32 idbyte, GError **err); gchar *checksum_device(GuestfsSession *session, const gchar *csumtype, const gchar *device, GError **err); gboolean lvresize_free(GuestfsSession *session, const gchar *lv, gint32 percent, GError **err); gboolean aug_clear(GuestfsSession *session, const gchar *augpath, GError **err); gint32 get_umask(GuestfsSession *session, , GError **err); gboolean debug_upload(GuestfsSession *session, const gchar *filename, const gchar *tmpname, gint32 mode, GError **err); gboolean base64_in(GuestfsSession *session, const gchar *base64file, const gchar *filename, GError **err); gboolean base64_out(GuestfsSession *session, const gchar *filename, const gchar *base64file, GError **err); gboolean checksums_out(GuestfsSession *session, const gchar *csumtype, const gchar *directory, const gchar *sumsfile, GError **err); gboolean fill_pattern(GuestfsSession *session, const gchar *pattern, gint32 len, const gchar *path, GError **err); gboolean write(GuestfsSession *session, const gchar *path, GByteArray *content, GError **err); gint32 pwrite(GuestfsSession *session, const gchar *path, GByteArray *content, gint64 offset, GError **err); gboolean resize2fs_size(GuestfsSession *session, const gchar *device, gint64 size, GError **err); gboolean pvresize_size(GuestfsSession *session, const gchar *device, gint64 size, GError **err); gboolean ntfsresize_size(GuestfsSession *session, const gchar *device, gint64 size, GError **err); GSList *available_all_groups(GuestfsSession *session, , GError **err); gboolean fallocate64(GuestfsSession *session, const gchar *path, gint64 len, GError **err); gchar *vfs_label(GuestfsSession *session, const gchar *device, GError **err); gchar *vfs_uuid(GuestfsSession *session, const gchar *device, GError **err); gboolean lvm_set_filter(GuestfsSession *session, GSList *devices, GError **err); gboolean lvm_clear_filter(GuestfsSession *session, , GError **err); gboolean luks_open(GuestfsSession *session, const gchar *device, const gchar *key, const gchar *mapname, GError **err); gboolean luks_open_ro(GuestfsSession *session, const gchar *device, const gchar *key, const gchar *mapname, GError **err); gboolean luks_close(GuestfsSession *session, const gchar *device, GError **err); gboolean luks_format(GuestfsSession *session, const gchar *device, const gchar *key, gint32 keyslot, GError **err); gboolean luks_format_cipher(GuestfsSession *session, const gchar *device, const gchar *key, gint32 keyslot, const gchar *cipher, GError **err); gboolean luks_add_key(GuestfsSession *session, const gchar *device, const gchar *key, const gchar *newkey, gint32 keyslot, GError **err); gboolean luks_kill_slot(GuestfsSession *session, const gchar *device, const gchar *key, gint32 keyslot, GError **err); gboolean is_lv(GuestfsSession *session, const gchar *device, GError **err); gchar *findfs_uuid(GuestfsSession *session, const gchar *uuid, GError **err); gchar *findfs_label(GuestfsSession *session, const gchar *label, GError **err); gboolean is_chardev(GuestfsSession *session, const gchar *path, GError **err); gboolean is_blockdev(GuestfsSession *session, const gchar *path, GError **err); gboolean is_fifo(GuestfsSession *session, const gchar *path, GError **err); gboolean is_symlink(GuestfsSession *session, const gchar *path, GError **err); gboolean is_socket(GuestfsSession *session, const gchar *path, GError **err); gchar *part_to_dev(GuestfsSession *session, const gchar *partition, GError **err); gboolean upload_offset(GuestfsSession *session, const gchar *filename, const gchar *remotefilename, gint64 offset, GError **err); gboolean download_offset(GuestfsSession *session, const gchar *remotefilename, const gchar *filename, gint64 offset, gint64 size, GError **err); gint32 pwrite_device(GuestfsSession *session, const gchar *device, GByteArray *content, gint64 offset, GError **err); GByteArray *pread_device(GuestfsSession *session, const gchar *device, gint32 count, gint64 offset, GError **err); gchar *lvm_canonical_lv_name(GuestfsSession *session, const gchar *lvname, GError **err); gboolean mkfs_opts(GuestfsSession *session, const gchar *fstype, const gchar *device, GuestfsMkfsOpts *optargs, GError **err); GByteArray *getxattr(GuestfsSession *session, const gchar *path, const gchar *name, GError **err); GByteArray *lgetxattr(GuestfsSession *session, const gchar *path, const gchar *name, GError **err); gboolean resize2fs_M(GuestfsSession *session, const gchar *device, GError **err); gboolean internal_autosync(GuestfsSession *session, , GError **err); gboolean is_zero(GuestfsSession *session, const gchar *path, GError **err); gboolean is_zero_device(GuestfsSession *session, const gchar *device, GError **err); GSList *list_9p(GuestfsSession *session, , GError **err); gboolean mount_9p(GuestfsSession *session, const gchar *mounttag, const gchar *mountpoint, GuestfsMount9P *optargs, GError **err); GSList *list_dm_devices(GuestfsSession *session, , GError **err); gboolean ntfsresize_opts(GuestfsSession *session, const gchar *device, GuestfsNTFSResizeOpts *optargs, GError **err); gboolean btrfs_filesystem_resize(GuestfsSession *session, const gchar *mountpoint, GuestfsBTRFSFilesystemResize *optargs, GError **err); gboolean write_append(GuestfsSession *session, const gchar *path, GByteArray *content, GError **err); gboolean compress_out(GuestfsSession *session, const gchar *ctype, const gchar *file, const gchar *zfile, GuestfsCompressOut *optargs, GError **err); gboolean compress_device_out(GuestfsSession *session, const gchar *ctype, const gchar *device, const gchar *zdevice, GuestfsCompressDeviceOut *optargs, GError **err); gint32 part_to_partnum(GuestfsSession *session, const gchar *partition, GError **err); gboolean copy_device_to_device(GuestfsSession *session, const gchar *src, const gchar *dest, GuestfsCopyDeviceToDevice *optargs, GError **err); gboolean copy_device_to_file(GuestfsSession *session, const gchar *src, const gchar *dest, GuestfsCopyDeviceToFile *optargs, GError **err); gboolean copy_file_to_device(GuestfsSession *session, const gchar *src, const gchar *dest, GuestfsCopyFileToDevice *optargs, GError **err); gboolean copy_file_to_file(GuestfsSession *session, const gchar *src, const gchar *dest, GuestfsCopyFileToFile *optargs, GError **err); gboolean tune2fs(GuestfsSession *session, const gchar *device, GuestfsTune2FS *optargs, GError **err); gboolean md_create(GuestfsSession *session, const gchar *name, GSList *devices, GuestfsMDCreate *optargs, GError **err); GSList *list_md_devices(GuestfsSession *session, , GError **err); GHashTable *md_detail(GuestfsSession *session, const gchar *md, GError **err); gboolean md_stop(GuestfsSession *session, const gchar *md, GError **err); GHashTable *blkid(GuestfsSession *session, const gchar *device, GError **err);
For the vast majority of these, or at least, any which take non-trivial execution time, I think it would be important to add _async variants, following the GIO design pattern. eg void guest_session_tune2fs_async(GuestfsSession *session, const gchar *device, GuestfsTune2FS *optargs, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean guest_session_tune2fs_finish(GAsyncResult *result, GError **error); This is a style that is widely preferred by people writing modern GTK applications, since it avoids the need to use threads in GUI apps. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
On 01/13/2012 10:58 AM, Daniel P. Berrange wrote:
On Thu, Jan 12, 2012 at 11:59:22AM +0000, Matthew Booth wrote:
I'm currently working on gobject bindings for libguestfs. I haven't got as far as compiling anything yet, but I've attached the C header for initial review. typedef struct _GuestfsPV GuestfsPV; struct _GuestfsPV { gchar *pv_name; /* The next field is NOT nul-terminated, be careful when printing it: */ gchar pv_uuid[32];
How about a:
#define GUESTFS_LVM_UUID_BUFLEN 32
and use that throughout
I don't think this one is massively important, because you can always use sizeof pv_uuid as an equivalent constant. As the API is automatically generated, these are always going to be consistent. I'd also make this change in the C header and use it here. Rich?
Obviously all these methods should have 'guestfs_session_' as a prefix
Whoops :)
/* Generated methods */ gboolean test0(GuestfsSession *session, const gchar *str, const gchar *optstr, GSList *strlist, gboolean b, gint32 integer, gint64 integer64, const gchar *filein, const gchar *fileout, GByteArray *bufferin, GError **err); gint32 test0rint(GuestfsSession *session, const gchar *val, GError **err); gint32 test0rinterr(GuestfsSession *session, , GError **err); gint64 test0rint64(GuestfsSession *session, const gchar *val, GError **err); gint64 test0rint64err(GuestfsSession *session, , GError **err); gboolean test0rbool(GuestfsSession *session, const gchar *val, GError **err); gboolean test0rboolerr(GuestfsSession *session, , GError **err); gchar *test0rconststring(GuestfsSession *session, const gchar *val, GError **err); gchar *test0rconststringerr(GuestfsSession *session, , GError **err); gchar *test0rconstoptstring(GuestfsSession *session, const gchar *val);
gint32 wc_c(GuestfsSession *session, const gchar *path, GError **err); GSList *head(GuestfsSession *session, const gchar *path, GError **err); GSList *head_n(GuestfsSession *session, gint32 nrlines, const gchar *path, GError **err); GSList *tail(GuestfsSession *session, const gchar *path, GError **err); GSList *tail_n(GuestfsSession *session, gint32 nrlines, const gchar *path, GError **err); gchar *df(GuestfsSession *session, , GError **err); gchar *df_h(GuestfsSession *session, , GError **err);
Some missing parameters here& in a few other cases.
Fixed, thanks.
For the vast majority of these, or at least, any which take non-trivial execution time, I think it would be important to add _async variants, following the GIO design pattern. eg
void guest_session_tune2fs_async(GuestfsSession *session, const gchar *device, GuestfsTune2FS *optargs, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean guest_session_tune2fs_finish(GAsyncResult *result, GError **error);
This is a style that is widely preferred by people writing modern GTK applications, since it avoids the need to use threads in GUI apps.
Sounds like a good idea. Can I assume that I can safely add this at a later date without taking it into account at this stage? If so, I'll come back to this once I have a working binding. Incidentally, I'm also playing with changes to functions with return or take array. I've decided to drop GSList in favour of a NULL-terminated array as returned by guestfs. For BufferIn and RBufferOut I've dropped the GByteArray in favour of a guint8 * with an additional length parameter. My concern is around memory handling in the bindings. An RStringList function returns a NULL-terminated char **. If I cast that to gchar ** and return it as-is, will bindings correctly garbage collect 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
On Fri, Jan 13, 2012 at 11:33:33AM +0000, Matthew Booth wrote:
On 01/13/2012 10:58 AM, Daniel P. Berrange wrote:
On Thu, Jan 12, 2012 at 11:59:22AM +0000, Matthew Booth wrote:
I'm currently working on gobject bindings for libguestfs. I haven't got as far as compiling anything yet, but I've attached the C header for initial review. typedef struct _GuestfsPV GuestfsPV; struct _GuestfsPV { gchar *pv_name; /* The next field is NOT nul-terminated, be careful when printing it: */ gchar pv_uuid[32];
How about a:
#define GUESTFS_LVM_UUID_BUFLEN 32
and use that throughout
I don't think this one is massively important, because you can always use sizeof pv_uuid as an equivalent constant. As the API is automatically generated, these are always going to be consistent.
sizeof() works fine for C, but not for languages. If you add the constant, then it'll get exposed to the languages automatically.
For the vast majority of these, or at least, any which take non-trivial execution time, I think it would be important to add _async variants, following the GIO design pattern. eg
void guest_session_tune2fs_async(GuestfsSession *session, const gchar *device, GuestfsTune2FS *optargs, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean guest_session_tune2fs_finish(GAsyncResult *result, GError **error);
This is a style that is widely preferred by people writing modern GTK applications, since it avoids the need to use threads in GUI apps.
Sounds like a good idea. Can I assume that I can safely add this at a later date without taking it into account at this stage? If so, I'll come back to this once I have a working binding.
Yes, it is easy to add in later. The only issue would be if you wanted to add in 'GCancellable' to the existing blocking APIs. I imagine there's no easy way to allow cancellation of API calls at the libguestfs level, so it is probably not worth it.
Incidentally, I'm also playing with changes to functions with return or take array. I've decided to drop GSList in favour of a NULL-terminated array as returned by guestfs. For BufferIn and RBufferOut I've dropped the GByteArray in favour of a guint8 * with an additional length parameter.
Hmm, it is probably better to use GInputStream & GOutputStream for any bulk I/O APIs. That way apps have the flexibility to give you a GFileInputStream, or a GMemoryInputStream as they see fit, rather than forcing them to have it all in memory.
My concern is around memory handling in the bindings. An RStringList function returns a NULL-terminated char **. If I cast that to gchar ** and return it as-is, will bindings correctly garbage collect it?
Every parameter and return value as a 'transfer' annotation which controls memory management. For objects it is either 'none' (receiver of object must not free it), or 'full' (receiver of object must free it). For lists/hashes there is extra values, to cope with the scenario where the receiver must free the List/Hash, but not the values stored in it. See: https://live.gnome.org/GObjectIntrospection/Annotations Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
On Fri, Jan 13, 2012 at 11:40:40AM +0000, Daniel P. Berrange wrote:
On Fri, Jan 13, 2012 at 11:33:33AM +0000, Matthew Booth wrote:
On 01/13/2012 10:58 AM, Daniel P. Berrange wrote:
On Thu, Jan 12, 2012 at 11:59:22AM +0000, Matthew Booth wrote:
I'm currently working on gobject bindings for libguestfs. I haven't got as far as compiling anything yet, but I've attached the C header for initial review. typedef struct _GuestfsPV GuestfsPV; struct _GuestfsPV { gchar *pv_name; /* The next field is NOT nul-terminated, be careful when printing it: */ gchar pv_uuid[32];
How about a:
#define GUESTFS_LVM_UUID_BUFLEN 32
and use that throughout
I don't think this one is massively important, because you can always use sizeof pv_uuid as an equivalent constant. As the API is automatically generated, these are always going to be consistent.
I think keep the definition in the gobject header.
sizeof() works fine for C, but not for languages. If you add the constant, then it'll get exposed to the languages automatically.
For the vast majority of these, or at least, any which take non-trivial execution time, I think it would be important to add _async variants, following the GIO design pattern. eg
void guest_session_tune2fs_async(GuestfsSession *session, const gchar *device, GuestfsTune2FS *optargs, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean guest_session_tune2fs_finish(GAsyncResult *result, GError **error);
This is a style that is widely preferred by people writing modern GTK applications, since it avoids the need to use threads in GUI apps.
Tricky to actually implement this though, without either creating a hidden thread somewhere, or substantially rearchitecting the libguestfs C API. virt-manager & guestfs-browser use libguestfs by creating a separate thread and sending it instructions. It's not that hard to implement, so for the moment I'd say forget about providing async functions.
Sounds like a good idea. Can I assume that I can safely add this at a later date without taking it into account at this stage? If so, I'll come back to this once I have a working binding.
Yes, it is easy to add in later.
The only issue would be if you wanted to add in 'GCancellable' to the existing blocking APIs. I imagine there's no easy way to allow cancellation of API calls at the libguestfs level, so it is probably not worth it.
Actually, this is possible for some (by no means all) calls: http://libguestfs.org/guestfs.3.html#cancelling_long_transfers You can also kill the qemu subprocess, although you risk losing any state you were writing to the disk.
Incidentally, I'm also playing with changes to functions with return or take array. I've decided to drop GSList in favour of a NULL-terminated array as returned by guestfs. For BufferIn and RBufferOut I've dropped the GByteArray in favour of a guint8 * with an additional length parameter.
Hmm, it is probably better to use GInputStream & GOutputStream for any bulk I/O APIs. That way apps have the flexibility to give you a GFileInputStream, or a GMemoryInputStream as they see fit, rather than forcing them to have it all in memory.
First of all, BufferIn and RBufferOut are "small" buffers, always less than 4MB. RBufferOut is already in memory, so feeding it into a stream is pointless. The issue is more likely to apply to FileIn and FileOut. These won't map very easily to GInputStream/GOutputStream, at least not without a hidden thread. BTW all of the above is handled better in wrappi :-)
My concern is around memory handling in the bindings. An RStringList function returns a NULL-terminated char **. If I cast that to gchar ** and return it as-is, will bindings correctly garbage collect it?
Every parameter and return value as a 'transfer' annotation which controls memory management. For objects it is either 'none' (receiver of object must not free it), or 'full' (receiver of object must free it).
For lists/hashes there is extra values, to cope with the scenario where the receiver must free the List/Hash, but not the values stored in it. See:
The caller must free the strings and the array. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
On Fri, Jan 13, 2012 at 12:15:08PM +0000, Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 11:40:40AM +0000, Daniel P. Berrange wrote:
On Fri, Jan 13, 2012 at 11:33:33AM +0000, Matthew Booth wrote:
On 01/13/2012 10:58 AM, Daniel P. Berrange wrote:
On Thu, Jan 12, 2012 at 11:59:22AM +0000, Matthew Booth wrote:
I'm currently working on gobject bindings for libguestfs. I haven't got as far as compiling anything yet, but I've attached the C header for initial review. typedef struct _GuestfsPV GuestfsPV; struct _GuestfsPV { gchar *pv_name; /* The next field is NOT nul-terminated, be careful when printing it: */ gchar pv_uuid[32];
How about a:
#define GUESTFS_LVM_UUID_BUFLEN 32
and use that throughout
I don't think this one is massively important, because you can always use sizeof pv_uuid as an equivalent constant. As the API is automatically generated, these are always going to be consistent.
I think keep the definition in the gobject header.
sizeof() works fine for C, but not for languages. If you add the constant, then it'll get exposed to the languages automatically.
For the vast majority of these, or at least, any which take non-trivial execution time, I think it would be important to add _async variants, following the GIO design pattern. eg
void guest_session_tune2fs_async(GuestfsSession *session, const gchar *device, GuestfsTune2FS *optargs, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean guest_session_tune2fs_finish(GAsyncResult *result, GError **error);
This is a style that is widely preferred by people writing modern GTK applications, since it avoids the need to use threads in GUI apps.
Tricky to actually implement this though, without either creating a hidden thread somewhere, or substantially rearchitecting the libguestfs C API.
GIO provides all the infrastructure you need to do this, via the GSimpleAsyncResult object, and its g_simple_async_result_run_in_thread method.
virt-manager & guestfs-browser use libguestfs by creating a separate thread and sending it instructions. It's not that hard to implement, so for the moment I'd say forget about providing async functions.
GTK doesn't play nice with threads though, so you have to deal with message passing back & forth between threads. With the way the GIO framework works, threads are always hidden, so your app code just deals with signals which always occurs in the main thread & can thus use GTK safely.
The only issue would be if you wanted to add in 'GCancellable' to the existing blocking APIs. I imagine there's no easy way to allow cancellation of API calls at the libguestfs level, so it is probably not worth it.
Actually, this is possible for some (by no means all) calls: http://libguestfs.org/guestfs.3.html#cancelling_long_transfers You can also kill the qemu subprocess, although you risk losing any state you were writing to the disk.
Ok, then for any of APIs which support this cancellation mode, I'd strongly suggest adding the GCancellable * argument to the existing method definitions. Regards, Daniiel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
On Fri, Jan 13, 2012 at 12:28:50PM +0000, Daniel P. Berrange wrote:
GIO provides all the infrastructure you need to do this, via the GSimpleAsyncResult object, and its g_simple_async_result_run_in_thread method.
So it does; we could use that. Might want to only offer this for functions that are truly long-running. I doubt anyone will be happy with launching threads to handle guestfs_set_verbose et al. We could flag long-running functions. cf. 'Progress' flag in generator/generator_actions.ml -- which brings me on to the subject of if we need to do anything special for long-running functions that generate progress messages? And second question: event API? error handling in the GObject API (does GObject have any concept of exceptions)?
virt-manager & guestfs-browser use libguestfs by creating a separate thread and sending it instructions. It's not that hard to implement, so for the moment I'd say forget about providing async functions.
GTK doesn't play nice with threads though, so you have to deal with message passing back & forth between threads. With the way the GIO framework works, threads are always hidden, so your app code just deals with signals which always occurs in the main thread & can thus use GTK safely.
Right ... virt-manager & guestfs-browser take care of this. I still think it's not too hard, but I have no objection to offering people a choice of methods (using g_simple_async_result_run_in_thread).
The only issue would be if you wanted to add in 'GCancellable' to the existing blocking APIs. I imagine there's no easy way to allow cancellation of API calls at the libguestfs level, so it is probably not worth it.
Actually, this is possible for some (by no means all) calls: http://libguestfs.org/guestfs.3.html#cancelling_long_transfers You can also kill the qemu subprocess, although you risk losing any state you were writing to the disk.
Ok, then for any of APIs which support this cancellation mode, I'd strongly suggest adding the GCancellable * argument to the existing method definitions.
Yes. We should add a note to the generator flags for functions that do support this. Currently it's just FileIn/FileOut functions, but it could be worth having a flag in case we extend this in future. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
On 01/13/2012 12:50 PM, Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 12:28:50PM +0000, Daniel P. Berrange wrote:
GIO provides all the infrastructure you need to do this, via the GSimpleAsyncResult object, and its g_simple_async_result_run_in_thread method.
So it does; we could use that. Might want to only offer this for functions that are truly long-running. I doubt anyone will be happy with launching threads to handle guestfs_set_verbose et al.
We could flag long-running functions. cf. 'Progress' flag in generator/generator_actions.ml -- which brings me on to the subject of if we need to do anything special for long-running functions that generate progress messages?
For the first pass I'll just ensure that cancellable functions take a GCancellable argument.
And second question: event API?
This is on the todo list. error handling in the GObject API
(does GObject have any concept of exceptions)?
Yes. Note that every function except those which return RConstOptString has a GError ** argument. This represents a GObject exception, and bindings will turn them into exactly that.
virt-manager& guestfs-browser use libguestfs by creating a separate thread and sending it instructions. It's not that hard to implement, so for the moment I'd say forget about providing async functions.
GTK doesn't play nice with threads though, so you have to deal with message passing back& forth between threads. With the way the GIO framework works, threads are always hidden, so your app code just deals with signals which always occurs in the main thread& can thus use GTK safely.
Right ... virt-manager& guestfs-browser take care of this. I still think it's not too hard, but I have no objection to offering people a choice of methods (using g_simple_async_result_run_in_thread).
The only issue would be if you wanted to add in 'GCancellable' to the existing blocking APIs. I imagine there's no easy way to allow cancellation of API calls at the libguestfs level, so it is probably not worth it.
Actually, this is possible for some (by no means all) calls: http://libguestfs.org/guestfs.3.html#cancelling_long_transfers You can also kill the qemu subprocess, although you risk losing any state you were writing to the disk.
Ok, then for any of APIs which support this cancellation mode, I'd strongly suggest adding the GCancellable * argument to the existing method definitions.
Yes. We should add a note to the generator flags for functions that do support this. Currently it's just FileIn/FileOut functions, but it could be worth having a flag in case we extend this in future.
I'll add that flag as part of this series. 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
On Fri, Jan 13, 2012 at 12:50:30PM +0000, Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 12:28:50PM +0000, Daniel P. Berrange wrote:
GIO provides all the infrastructure you need to do this, via the GSimpleAsyncResult object, and its g_simple_async_result_run_in_thread method.
So it does; we could use that. Might want to only offer this for functions that are truly long-running. I doubt anyone will be happy with launching threads to handle guestfs_set_verbose et al.
We could flag long-running functions. cf. 'Progress' flag in generator/generator_actions.ml -- which brings me on to the subject of if we need to do anything special for long-running functions that generate progress messages?
I'd be inclined to define a GObject interface GuestfsProgress * with 3 virtual methods: void (*progress_start)(GuestfsProgress *prog); void (*progress_tick)(GuestfsProgress *prog, gfloat *percent); void (*progress_finish)(GuestfsProgress *prog); Applications wishing to have progress info would create an implementation of this interface. Then, either GuestfsSession would want a global method like guestfs_session_set_progress(GuestfsSession *s, GuestfsProgress *prog); Or, you could make each individual long running API, would accept an optional GuestfsProgress *prog parameter. The latter is probably better if we consider that with async methods, you might invoke several methods in a row & want to handle progress separately for each on their own.
And second question: event API? error handling in the GObject API (does GObject have any concept of exceptions)?
Events will want to be turned into GObject signals I presume. At the C level every API that can fail has a GError ** argument. This gets translated to whatever error mechanism a language has, usually exceptions. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
On Fri, Jan 13, 2012 at 01:18:43PM +0000, Daniel P. Berrange wrote:
The latter is probably better if we consider that with async methods, you might invoke several methods in a row & want to handle progress separately for each on their own.
^ This bit can't be done with the libguestfs API, since it only allows one call at a time per handle.
And second question: event API? error handling in the GObject API (does GObject have any concept of exceptions)?
Events will want to be turned into GObject signals I presume.
Yup, and signals can carry state (like events) so that all seems to fit.
At the C level every API that can fail has a GError ** argument. This gets translated to whatever error mechanism a language has, usually exceptions.
Understood, thanks. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
On Fri, Jan 13, 2012 at 01:29:28PM +0000, Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 01:18:43PM +0000, Daniel P. Berrange wrote:
The latter is probably better if we consider that with async methods, you might invoke several methods in a row & want to handle progress separately for each on their own.
^ This bit can't be done with the libguestfs API, since it only allows one call at a time per handle.
Actually I don't think invalidates the per-method design I suggest. The GObject wrapper could be used from multiple threads concurrently, even if the API calls are ultimately serialized on the wire. Lets consider two libguestfs methods 'foo' and 'bar', both of which are long running and can generate progress information. Now thread A in the foreground invokes 'foo' and wants to print progress display on the terminal. At any time thread 'B' might invoke 'bar' and *not* want to pollute the terminal with any output. A: guestfs_session_set_progress(s, new GuestProgessCosnole() guestfs_session_foo(s) guestfs_session_set_progress(s, None) B: guestfs_session_bar(s) Obviously you'd have to add extra serialization in the application to avoid a race here, even though libguestfs itself serializes all calls. If you allowed A: guestfs_session_foo(s, new GuestProgessConsole()) B: guestfs_session_bar(s, None) then the application does nto have to worry about serialization itself. I think this becomes even more important when you have asynchronous versions of the commands. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange -
Matthew Booth -
Richard W.M. Jones