]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Add one interface to add default input devices
authorLi Zhang <zhlcindy@linux.vnet.ibm.com>
Mon, 17 Feb 2014 10:17:52 +0000 (18:17 +0800)
committerJán Tomko <jtomko@redhat.com>
Wed, 19 Feb 2014 08:16:30 +0000 (09:16 +0100)
Use it for the default mouse.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms

index 362ba20516e7959024de989cea2056250bc8301a..939b4231b19b012ac836990b8d458b952f300c5b 100644 (file)
@@ -11051,6 +11051,35 @@ virDomainDefMaybeAddController(virDomainDefPtr def,
 }
 
 
+int
+virDomainDefMaybeAddInput(virDomainDefPtr def,
+                          int type,
+                          int bus)
+{
+    size_t i;
+    virDomainInputDefPtr input;
+
+    for (i = 0; i < def->ninputs; i++) {
+        if (def->inputs[i]->type == type &&
+            def->inputs[i]->bus == bus)
+            return 0;
+    }
+
+    if (VIR_ALLOC(input) < 0)
+        return -1;
+
+    input->type = type;
+    input->bus = bus;
+
+    if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) {
+        VIR_FREE(input);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 /* Parse a memory element located at XPATH within CTXT, and store the
  * result into MEM.  If REQUIRED, then the value must exist;
  * otherwise, the value is optional.  The value is in blocks of 1024.
@@ -12464,25 +12493,15 @@ virDomainDefParseXML(xmlDocPtr xml,
 
     /* If graphics are enabled, there's an implicit PS2 mouse */
     if (def->ngraphics > 0) {
-        virDomainInputDefPtr input;
+        int input_bus = VIR_DOMAIN_INPUT_BUS_XEN;
 
-        if (VIR_ALLOC(input) < 0) {
-            goto error;
-        }
-        if (STREQ(def->os.type, "hvm")) {
-            input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE;
-            input->bus = VIR_DOMAIN_INPUT_BUS_PS2;
-        } else {
-            input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE;
-            input->bus = VIR_DOMAIN_INPUT_BUS_XEN;
-        }
+        if (STREQ(def->os.type, "hvm"))
+            input_bus = VIR_DOMAIN_INPUT_BUS_PS2;
 
-        if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) {
-            virDomainInputDefFree(input);
+        if (virDomainDefMaybeAddInput(def,
+                                      VIR_DOMAIN_INPUT_TYPE_MOUSE,
+                                      input_bus) < 0)
             goto error;
-        }
-        def->inputs[def->ninputs] = input;
-        def->ninputs++;
     }
 
 
index 22a927ee7c9eace1b38ba67cba2785bbcd11ab22..bef4a3d4b80282bcd56d9d6bc138dfbfffae9ce7 100644 (file)
@@ -2806,6 +2806,10 @@ virDomainDefMaybeAddController(virDomainDefPtr def,
                                int type,
                                int idx,
                                int model);
+int
+virDomainDefMaybeAddInput(virDomainDefPtr def,
+                          int type,
+                          int bus);
 
 char *virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps);
 
index 2eead3d6def7d6a3bf2484460909da0ca310bfde..ec786e4b70620d6493fc1945e6147e9fc0d05742 100644 (file)
@@ -165,6 +165,7 @@ virDomainDefGenSecurityLabelDef;
 virDomainDefGetDefaultEmulator;
 virDomainDefGetSecurityLabelDef;
 virDomainDefMaybeAddController;
+virDomainDefMaybeAddInput;
 virDomainDefNew;
 virDomainDefParseFile;
 virDomainDefParseNode;