Blob Blame History Raw
From bdb788fcced810b45d7c02882c80114477576a46 Mon Sep 17 00:00:00 2001
From: Christophe Fergeau <cfergeau@redhat.com>
Date: Mon, 22 Sep 2014 14:11:07 +0200
Subject: [PATCH] cdrom: Allow empty filename when serializing to XML

Removing a CDROM image from a VM is achieved by updating the current VM
file to be "". The code currently forbid NULL filenames in update
requests, this commit removes this limitation so that it's possible to
remove a CD image from a VM through libgovirt.
---
 govirt/ovirt-cdrom.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/govirt/ovirt-cdrom.c b/govirt/ovirt-cdrom.c
index 020159c..d852403 100644
--- a/govirt/ovirt-cdrom.c
+++ b/govirt/ovirt-cdrom.c
@@ -151,13 +151,16 @@ static gboolean ovirt_cdrom_init_from_xml(OvirtResource *resource,
 static char *ovirt_cdrom_to_xml(OvirtResource *resource)
 {
     OvirtCdrom *cdrom;
+    const char *file;
 
     g_return_val_if_fail(OVIRT_IS_CDROM(resource), NULL);
     cdrom = OVIRT_CDROM(resource);
-    g_return_val_if_fail(cdrom->priv->file != NULL, NULL);
+    file = cdrom->priv->file;
+    if (file == NULL) {
+        file = "";
+    }
 
-    return g_strdup_printf("<cdrom>\n\t<file id=\"%s\"/>\n</cdrom>",
-                           cdrom->priv->file);
+    return g_strdup_printf("<cdrom>\n\t<file id=\"%s\"/>\n</cdrom>", file);
 }