Currently, there is no possibility for user to specify desired behaviour of
output to file - truncate or append. This patch adds an ability to explicitly
specify that user wants to preserve file's content on reopen.
Signed-off-by: Dmitry Mishin <dim(a)virtuozzo.com>
---
src/conf/domain_conf.c | 18 ++++++++++++++----
src/conf/domain_conf.h | 1 +
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5200c27..ea854a7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1722,9 +1722,10 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
virDomainChrSourceDefClear(dest);
switch (src->type) {
+ case VIR_DOMAIN_CHR_TYPE_FILE:
+ dest->data.file.append = src->data.file.append;
case VIR_DOMAIN_CHR_TYPE_PTY:
case VIR_DOMAIN_CHR_TYPE_DEV:
- case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
if (VIR_STRDUP(dest->data.file.path, src->data.file.path) < 0)
return -1;
@@ -1796,9 +1797,12 @@ virDomainChrSourceDefIsEqual(const virDomainChrSourceDef *src,
return false;
switch ((virDomainChrType)src->type) {
+ case VIR_DOMAIN_CHR_TYPE_FILE:
+ return src->data.file.append == tgt->data.file.append &&
+ STREQ_NULLABLE(src->data.file.path, tgt->data.file.path);
+ break;
case VIR_DOMAIN_CHR_TYPE_PTY:
case VIR_DOMAIN_CHR_TYPE_DEV:
- case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
return STREQ_NULLABLE(src->data.file.path, tgt->data.file.path);
break;
@@ -9468,9 +9472,10 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
case VIR_DOMAIN_CHR_TYPE_LAST:
break;
+ case VIR_DOMAIN_CHR_TYPE_FILE:
+ def->data.file.append = mode != NULL && STRNEQ(mode,
"append");
case VIR_DOMAIN_CHR_TYPE_PTY:
case VIR_DOMAIN_CHR_TYPE_DEV:
- case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
if (!path &&
def->type != VIR_DOMAIN_CHR_TYPE_PTY) {
@@ -20051,10 +20056,15 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
case VIR_DOMAIN_CHR_TYPE_DEV:
case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
+ /* 'append' makes sense only for files */
+ if (def->type != VIR_DOMAIN_CHR_TYPE_FILE)
+ def->data.file.append = false;
if (def->type != VIR_DOMAIN_CHR_TYPE_PTY ||
(def->data.file.path &&
!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))) {
- virBufferEscapeString(buf, "<source path='%s'",
+ virBufferAsprintf(buf, "<source %s",
+ def->data.file.append ? "mode='append' " :
"");
+ virBufferEscapeString(buf, "path='%s'",
def->data.file.path);
virDomainSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags);
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 952d3cc..9d69c16 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1176,6 +1176,7 @@ struct _virDomainChrSourceDef {
/* no <source> for null, vc, stdio */
struct {
char *path;
+ bool append;
} file; /* pty, file, pipe, or device */
struct {
char *master;
--
1.8.3.1