[PATCHv2 2/3] conf: Add new 'append' attribute for chardevs with file source

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
---
 docs/schemas/domaincommon.rng |  5 +++++
 src/conf/domain_conf.c        | 28 ++++++++++++++++++++++++----
 src/conf/domain_conf.h        |  1 +
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 4804c69..eae1213 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3252,6 +3252,11 @@
         <optional>
           <attribute name="slave"/>
         </optional>
+        <optional>
+          <attribute name="append">
+            <ref name="virOnOff"/>
+          </attribute>
+        </optional>
         <zeroOrMore>
           <ref name='devSeclabel'/>
         </zeroOrMore>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5200c27..87571cd 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;
@@ -9371,6 +9375,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
     char *channel = NULL;
     char *master = NULL;
     char *slave = NULL;
+    char *append = NULL;
     int remaining = 0;
 
     while (cur != NULL) {
@@ -9380,9 +9385,11 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
                     mode = virXMLPropString(cur, "mode");
 
                 switch ((virDomainChrType) def->type) {
+                case VIR_DOMAIN_CHR_TYPE_FILE:
+                    if (!append)
+                        append = virXMLPropString(cur, "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:
                 case VIR_DOMAIN_CHR_TYPE_UNIX:
                     /* PTY path is only parsed from live xml.  */
@@ -9468,9 +9475,15 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
     case VIR_DOMAIN_CHR_TYPE_LAST:
         break;
 
+    case VIR_DOMAIN_CHR_TYPE_FILE:
+        if (append &&
+            (def->data.file.append = virTristateSwitchTypeFromString(append)) <= 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Invalid append attribute value '%s'"), append);
+            goto error;
+        }
     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) {
@@ -9611,6 +9624,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
     VIR_FREE(connectService);
     VIR_FREE(path);
     VIR_FREE(channel);
+    VIR_FREE(append);
 
     return remaining;
 
@@ -20051,11 +20065,17 @@ 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 = 0;
         if (def->type != VIR_DOMAIN_CHR_TYPE_PTY ||
             (def->data.file.path &&
              !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))) {
             virBufferEscapeString(buf, "<source path='%s'",
                                   def->data.file.path);
+            if (def->data.file.append)
+                virBufferAsprintf(buf, " append='%s'",
+                    virTristateSwitchTypeToString(def->data.file.append));
             virDomainSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags);
         }
         break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 952d3cc..ae6d546 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;
+            int append; /* enum virTristateSwitch */
         } file; /* pty, file, pipe, or device */
         struct {
             char *master;
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]