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

[libvirt] [libvirt-gconfig PATCHv2 23/32] More GVirConfigDeviceDisk setters



--
v2: fix gvir_config_device_disk_set_source
    use g_return_if_fail to test function args for sanity
---
 libvirt-gconfig/libvirt-gconfig-device-disk.c |   78 ++++++++++++++++++++++++-
 libvirt-gconfig/libvirt-gconfig-device-disk.h |   10 +++
 libvirt-gconfig/libvirt-gconfig.sym           |    7 ++-
 3 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.c b/libvirt-gconfig/libvirt-gconfig-device-disk.c
index e34e9a0..acfd1ab 100644
--- a/libvirt-gconfig/libvirt-gconfig-device-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-device-disk.c
@@ -39,7 +39,7 @@ extern gboolean debugFlag;
 
 struct _GVirConfigDeviceDiskPrivate
 {
-    gboolean unused;
+    GVirConfigDeviceDiskType type;
 };
 
 G_DEFINE_TYPE(GVirConfigDeviceDisk, gvir_config_device_disk, GVIR_TYPE_CONFIG_DEVICE);
@@ -96,6 +96,7 @@ void gvir_config_device_disk_set_type(GVirConfigDeviceDisk *disk,
                                           type);
     g_return_if_fail(type_str != NULL);
     xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str);
+    disk->priv->type = type;
 }
 
 void gvir_config_device_disk_set_guest_device_type(GVirConfigDeviceDisk *disk,
@@ -129,3 +130,78 @@ void gvir_config_device_disk_set_snapshot_type(GVirConfigDeviceDisk *disk,
     g_return_if_fail(type_str != NULL);
     xmlNewProp(node, (xmlChar*)"snapshot", (xmlChar*)type_str);
 }
+
+void gvir_config_device_disk_set_source(GVirConfigDeviceDisk *disk,
+                                        const char *source)
+{
+    xmlNodePtr source_node;
+    const char *attribute_name;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DEVICE_DISK(disk));
+    source_node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(disk),
+                                                   "source");
+    g_return_if_fail(source_node != NULL);
+
+    switch (disk->priv->type) {
+        case GVIR_CONFIG_DEVICE_DISK_FILE:
+            attribute_name = "file";
+            break;
+        case GVIR_CONFIG_DEVICE_DISK_BLOCK:
+            attribute_name = "dev";
+            break;
+        case GVIR_CONFIG_DEVICE_DISK_DIR:
+            attribute_name = "dir";
+            break;
+        case GVIR_CONFIG_DEVICE_DISK_NETWORK:
+            attribute_name = "protocol";
+            break;
+        default:
+            g_return_if_reached();
+    }
+    xmlNewProp(source_node, (xmlChar*)attribute_name, (xmlChar*)source);
+}
+
+void gvir_config_device_disk_set_driver_name(GVirConfigDeviceDisk *disk,
+                                             const char *driver_name)
+{
+    xmlNodePtr node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DEVICE_DISK(disk));
+    node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(disk), "driver");
+    g_return_if_fail(node != NULL);
+    xmlNewProp(node, (xmlChar*)"name", (xmlChar*)driver_name);
+
+}
+
+void gvir_config_device_disk_set_driver_type(GVirConfigDeviceDisk *disk,
+                                             const char *driver_type)
+{
+    xmlNodePtr node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DEVICE_DISK(disk));
+    node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(disk), "driver");
+    g_return_if_fail(node != NULL);
+    xmlNewProp(node, (xmlChar*)"type", (xmlChar*)driver_type);
+}
+
+void gvir_config_device_disk_set_target_bus(GVirConfigDeviceDisk *disk,
+                                            const char *bus)
+{
+    xmlNodePtr node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DEVICE_DISK(disk));
+    node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(disk), "target");
+    g_return_if_fail(node != NULL);
+    xmlNewProp(node, (xmlChar*)"bus", (xmlChar*)bus);
+}
+
+void gvir_config_device_disk_set_target_dev(GVirConfigDeviceDisk *disk,
+                                            const char *dev)
+{
+    xmlNodePtr node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DEVICE_DISK(disk));
+    node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(disk), "target");
+    g_return_if_fail(node != NULL);
+    xmlNewProp(node, (xmlChar*)"dev", (xmlChar*)dev);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.h b/libvirt-gconfig/libvirt-gconfig-device-disk.h
index e597815..ac89d9b 100644
--- a/libvirt-gconfig/libvirt-gconfig-device-disk.h
+++ b/libvirt-gconfig/libvirt-gconfig-device-disk.h
@@ -87,6 +87,16 @@ void gvir_config_device_disk_set_guest_device_type(GVirConfigDeviceDisk *disk,
                                                    GVirConfigDeviceDiskGuestDeviceType type);
 void gvir_config_device_disk_set_snapshot_type(GVirConfigDeviceDisk *disk,
                                                GVirConfigDeviceDiskSnapshotType type);
+void gvir_config_device_disk_set_source(GVirConfigDeviceDisk *disk,
+                                        const char *source);
+void gvir_config_device_disk_set_driver_name(GVirConfigDeviceDisk *disk,
+                                             const char *driver_name);
+void gvir_config_device_disk_set_driver_type(GVirConfigDeviceDisk *disk,
+                                             const char *driver_type);
+void gvir_config_device_disk_set_target_bus(GVirConfigDeviceDisk *disk,
+                                            const char *bus);
+void gvir_config_device_disk_set_target_dev(GVirConfigDeviceDisk *disk,
+                                            const char *dev);
 
 G_END_DECLS
 
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 35dc3c7..e33ecf5 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -20,8 +20,13 @@ LIBVIRT_GOBJECT_0.0.1 {
 	gvir_config_device_disk_type_get_type;
 	gvir_config_device_disk_new;
 	gvir_config_device_disk_new_from_xml;
-	gvir_config_device_disk_set_snapshot_type;
+	gvir_config_device_disk_set_driver_name;
+	gvir_config_device_disk_set_driver_type;
 	gvir_config_device_disk_set_guest_device_type;
+	gvir_config_device_disk_set_snapshot_type;
+	gvir_config_device_disk_set_source;
+	gvir_config_device_disk_set_target_bus;
+	gvir_config_device_disk_set_target_dev;
 	gvir_config_device_disk_set_type;
 
 	gvir_config_domain_get_type;
-- 
1.7.7.3


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