On Mon, Sep 10, 2012 at 03:58:26PM +0200, Michal Privoznik wrote: > Let users add either files or devices as disks to domains. > --- > libvirt-designer/libvirt-designer-domain.c | 259 ++++++++++++++++++++++++++++ > libvirt-designer/libvirt-designer-domain.h | 7 + > libvirt-designer/libvirt-designer.sym | 3 + > 3 files changed, 269 insertions(+), 0 deletions(-) > > diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c > index a8cabde..8e649d7 100644 > --- a/libvirt-designer/libvirt-designer-domain.c > +++ b/libvirt-designer/libvirt-designer-domain.c > +static GVirConfigDomainDisk * > +gvir_designer_domain_add_disk_full(GVirDesignerDomain *design, > + GVirConfigDomainDiskType type, > + const char *path, > + const char *format, > + gchar *target, > + GError **error) > +{ > + GVirDesignerDomainPrivate *priv = design->priv; > + GVirConfigDomainDisk *disk = NULL; > + GVirConfigDomainDiskBus bus; > + gchar *target_gen = NULL; > + const gchar *bus_str = NULL; > + GList *bus_str_list = NULL, *item = NULL; > + > + /* Guess preferred disk bus */ > + bus_str = gvir_designer_domain_get_preferred_disk_bus_type(design, error); > + if (!bus_str) { > + /* And fallback if fails */ > + bus_str_list = gvir_designer_domain_get_supported_disk_bus_types(design); > + if (!bus_str_list) { > + if (!*error) > + g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0, > + "Unable to find any disk bus type"); > + goto error; > + } > + > + item = g_list_first(bus_str_list); > + bus_str = item->data; > + if (!bus_str) > + goto error; > + } > + > + g_clear_error(error); > + > + disk = gvir_config_domain_disk_new(); > + gvir_config_domain_disk_set_type(disk, type); > + gvir_config_domain_disk_set_source(disk, path); > + gvir_config_domain_disk_set_driver_name(disk, "qemu"); Opps, don't want to hardcode use of qemu here - need to make this conditional based on the <domain type='...'/> value. > + if (format) > + gvir_config_domain_disk_set_driver_type(disk, format); > + if (g_str_equal(bus_str, "ide")) { > + bus = GVIR_CONFIG_DOMAIN_DISK_BUS_IDE; > + } else if (g_str_equal(bus_str, "virtio") || > + g_str_equal(bus_str, "pci")) { > + bus = GVIR_CONFIG_DOMAIN_DISK_BUS_VIRTIO; > + } else if (g_str_equal(bus_str, "sata")) { > + bus = GVIR_CONFIG_DOMAIN_DISK_BUS_SATA; > + } else { > + g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0, > + "unsupported disk bus type '%s'", bus_str); > + goto error; > + } > + > + gvir_config_domain_disk_set_target_bus(disk, bus); > + > + if (!target) { > + target = target_gen = gvir_designer_domain_next_disk_target(design, bus); > + if (!target_gen) { > + g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0, > + "unable to generate target name for bus '%s'", bus_str); > + goto error; > + } > + } > + gvir_config_domain_disk_set_target_dev(disk, target); > + > + g_list_free(bus_str_list); > + g_free(target_gen); > + > + gvir_config_domain_add_device(priv->config, GVIR_CONFIG_DOMAIN_DEVICE(disk)); > + > + return disk; > + > +error: > + g_free(target_gen); > + g_list_free(bus_str_list); > + if (disk) > + g_object_unref(disk); > + return NULL; > +} > +/** Minor note - my preference is to leave 2 blank lines between functions. > + * gvir_designer_domain_add_disk_file: > + * @design: (transfer none): the domain designer instance > + * @filepath: (transfer none): the path to a file > + * @format: (transfer none): disk format > + * > + * Add a new disk to the domain. > + * > + * Returns: (transfer none): the pointer to new disk. > + * If something fails NULL is returned and @error is set. > + */ > +GVirConfigDomainDisk *gvir_designer_domain_add_disk_file(GVirDesignerDomain *design, > + const char *filepath, > + const char *format, > + GError **error) > +{ > + g_return_val_if_fail(GVIR_DESIGNER_IS_DOMAIN(design), NULL); > + > + GVirConfigDomainDisk *ret = NULL; > + > + ret = gvir_designer_domain_add_disk_full(design, > + GVIR_CONFIG_DOMAIN_DISK_FILE, > + filepath, > + format, > + NULL, > + error); > + return ret; > +} I know you've pushed this series already, so fine to just post followup fixes as needed or push directly. 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 :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list