]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: allow use of a logfile with chardev backends
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 11 Dec 2015 16:58:13 +0000 (16:58 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 10 Mar 2016 15:33:17 +0000 (15:33 +0000)
Extend the chardev source XML so that there is a new optional
<log/> element, which is applicable to all character device
backend types. For example, to log output of a TCP backed
serial port

    <serial type='tcp'>
      <source mode='connect' host='127.0.0.1' service='9999'/>
      <protocol type='raw'/>
      <log file='/var/log/libvirt/qemu/demo-serial0.log' append='on'/>
      <target port='0'/>
    </serial>

Not all hypervisors will support use of logfiles.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h

index 4e4922806b0d252e1043518e058cb3027fc71883..41f24889c20e8f169391f2dee59bfe25317028e1 100644 (file)
@@ -5283,6 +5283,20 @@ qemu-kvm -net nic,model=? /dev/null
       "on" and "off" (default). <span class="since">Since 1.3.1</span>.
     </p>
 
+    <p>
+      Regardless of the<code>type</code>, character devices can
+      have an optional log file associated with them. This is
+      expressed via a <code>log</code> sub-element, with a
+      <code>file</code> attribute. There can also be a <code>append</code>
+      attribute which takes teh same values described above.
+      <span class="since">1.3.3</span>.
+    </p>
+
+    <pre>
+  ...
+  &lt;log file="/var/log/libvirt/qemu/guestname-serial0.log" append="off"/&gt;
+  ...</pre>
+
     <p>
       Each character device element has an optional
       sub-element <code>&lt;address&gt;</code> which can tie the
index 6ca937c07a3935fe2185c85e09c7fa757c846695..8c6287d8bff59010734dc701caf86a1f3a25ad2d 100644 (file)
         </optional>
       </element>
     </optional>
+    <optional>
+      <element name="log">
+        <attribute name="file">
+          <ref name="absFilePath"/>
+        </attribute>
+        <optional>
+          <attribute name="append">
+            <ref name="virOnOff"/>
+          </attribute>
+        </optional>
+      </element>
+    </optional>
   </define>
   <!--
       The description for a console
index 1aed318b674d5cbd0dd279dae1660e4bbbf2cf58..566f7eca8ec65ac6bacee191ed273b45f4fee814 100644 (file)
@@ -1826,6 +1826,8 @@ virDomainChrSourceDefClear(virDomainChrSourceDefPtr def)
         VIR_FREE(def->data.spiceport.channel);
         break;
     }
+
+    VIR_FREE(def->logfile);
 }
 
 /* Deep copies the contents of src into dest.  Return -1 and report
@@ -9538,6 +9540,8 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
     char *connectHost = NULL;
     char *connectService = NULL;
     char *path = NULL;
+    char *logfile = NULL;
+    char *logappend = NULL;
     char *mode = NULL;
     char *protocol = NULL;
     char *channel = NULL;
@@ -9625,6 +9629,11 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
                     }
                     ctxt->node = saved_node;
                 }
+            } else if (xmlStrEqual(cur->name, BAD_CAST "log")) {
+                if (!logfile)
+                    logfile = virXMLPropString(cur, "file");
+                if (!logappend)
+                    logappend = virXMLPropString(cur, "append");
             } else if (xmlStrEqual(cur->name, BAD_CAST "protocol")) {
                 if (!protocol)
                     protocol = virXMLPropString(cur, "type");
@@ -9783,6 +9792,16 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
         break;
     }
 
+    def->logfile = logfile;
+    logfile = NULL;
+
+    if (logappend != NULL &&
+        (def->logappend = virTristateSwitchTypeFromString(logappend)) <= 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Invalid append attribute value '%s'"), logappend);
+        goto error;
+    }
+
  cleanup:
     VIR_FREE(mode);
     VIR_FREE(protocol);
@@ -9793,6 +9812,8 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
     VIR_FREE(path);
     VIR_FREE(channel);
     VIR_FREE(append);
+    VIR_FREE(logappend);
+    VIR_FREE(logfile);
 
     return remaining;
 
@@ -20300,6 +20321,15 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
 
     }
 
+    if (def->logfile) {
+        virBufferEscapeString(buf, "<log file='%s'", def->logfile);
+        if (def->logappend != VIR_TRISTATE_SWITCH_ABSENT) {
+            virBufferAsprintf(buf, " append='%s'",
+                              virTristateSwitchTypeToString(def->logappend));
+        }
+        virBufferAddLit(buf, "/>\n");
+    }
+
     return 0;
 }
 
index 832ca4f20c24e32acec090a5baae15feb3d76232..01f73a040fffe973c18083256c0a46ddf3ce8fef 100644 (file)
@@ -1204,6 +1204,8 @@ struct _virDomainChrSourceDef {
             char *channel;
         } spiceport;
     } data;
+    char *logfile;
+    int logappend;
 };
 
 /* A complete character device, both host and domain views.  */