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(a)redhat.com>
---
docs/formatdomain.html.in | 14 ++++++++++++++
docs/schemas/domaincommon.rng | 12 ++++++++++++
src/conf/domain_conf.c | 30 ++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 2 ++
4 files changed, 58 insertions(+)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 5016772..cdf5291 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5274,6 +5274,20 @@ qemu-kvm -net nic,model=? /dev/null
</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>
+ ...
+ <log file="/var/log/libvirt/qemu/guestname-serial0.log"
append="off"/>
+ ...</pre>
+
+ <p>
Each character device element has an optional
sub-element <code><address></code> which can tie the
device to a
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 67af93a..b49d9eb 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3276,6 +3276,18 @@
</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
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 79758d4..ae241e8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1768,6 +1768,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
@@ -9396,6 +9398,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;
@@ -9483,6 +9487,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");
@@ -9641,6 +9650,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);
@@ -9651,6 +9670,8 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
VIR_FREE(path);
VIR_FREE(channel);
VIR_FREE(append);
+ VIR_FREE(logappend);
+ VIR_FREE(logfile);
return remaining;
@@ -20087,6 +20108,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;
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 1de3be3..2b2f75b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1204,6 +1204,8 @@ struct _virDomainChrSourceDef {
char *channel;
} spiceport;
} data;
+ char *logfile;
+ int logappend;
};
/* A complete character device, both host and domain views. */
--
2.5.0