Skip to contentSkip to conversation

qemu-char: append opt to stop truncation of serial file

PATCH Superseded Denis V. Lunev 3 participants 3 messages Dec 3, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-char: append opt to stop truncation of serial file

From: Olga Krishtal <[email protected]>

Our QA teams wants to preserve serial output of the guest in between QEMU runs to perform post-analysis.

By default this behavior is off (file is truncated each time QEMU is started or device is plugged).

CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
CC Paolo Bonzini <[email protected]>
---
 qapi-schema.json |  7 ++++++-
 qemu-char.c      | 12 +++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)
qapi-schema.json +6 -1
index 8b1a423..802c138 100644
@@ -3020,11 +3020,16 @@
 #
 # @in:  #optional The name of the input file
 # @out: The name of the output file
+# @append: #optional Open the file in append mode to preserve the content in
+#          between QEMU runs.
+#
+#          Since: 2.6
 #
 # Since: 1.4
 ##
 { 'struct': 'ChardevFile', 'data': { '*in' : 'str',
-                                   'out' : 'str' } }
+                                   'out' : 'str',
+                                   '*append': 'bool' } }
 
 ##
 # @ChardevHostdev:
qemu-char.c +11 -1
index 5448b0f..58454e2 100644
@@ -3479,6 +3479,7 @@ static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend,
     }
     backend->u.file = g_new0(ChardevFile, 1);
     backend->u.file->out = g_strdup(path);
+    backend->u.file->append = qemu_opt_get_bool(opts, "append", false);
 }
 
 static void qemu_chr_parse_stdio(QemuOpts *opts, ChardevBackend *backend,
@@ -4036,6 +4037,9 @@ QemuOptsList qemu_chardev_opts = {
         },{
             .name = "chardev",
             .type = QEMU_OPT_STRING,
+        },{
+            .name = "append",
+            .type = QEMU_OPT_BOOL,
         },
         { /* end of list */ }
     },
@@ -4096,7 +4100,13 @@ static CharDriverState *qmp_chardev_open_file(const char *id,
     ChardevFile *file = backend->u.file;
     int flags, in = -1, out;
 
-    flags = O_WRONLY | O_TRUNC | O_CREAT | O_BINARY;
+    flags = O_WRONLY | O_CREAT | O_BINARY;
+    if (file->append) {
+        flags |= O_APPEND;
+    } else {
+        flags |= O_TRUNC;
+    }
+
     out = qmp_chardev_open_file_source(file->out, flags, errp);
     if (out < 0) {
         return NULL;
Signature · 1 line
2.1.4
#1 lore raw
Quoted 67 lines · Denis V. Lunev

From: Olga Krishtal <[email protected]>

Our QA teams wants to preserve serial output of the guest in between QEMU runs to perform post-analysis.

By default this behavior is off (file is truncated each time QEMU is started or device is plugged).

CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
CC Paolo Bonzini <[email protected]>
---
  qapi-schema.json |  7 ++++++-
  qemu-char.c      | 12 +++++++++++-
  2 files changed, 17 insertions(+), 2 deletions(-)
qapi-schema.json +6 -1
index 8b1a423..802c138 100644
@@ -3020,11 +3020,16 @@
  #
  # @in:  #optional The name of the input file
  # @out: The name of the output file
+# @append: #optional Open the file in append mode to preserve the content in
+#          between QEMU runs.
+#
+#          Since: 2.6
  #
  # Since: 1.4
  ##
  { 'struct': 'ChardevFile', 'data': { '*in' : 'str',
-                                   'out' : 'str' } }
+                                   'out' : 'str',
+                                   '*append': 'bool' } }
 
  ##
  # @ChardevHostdev:
qemu-char.c +4 -1
index 5448b0f..58454e2 100644
@@ -3479,6 +3479,7 @@ static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend,
      }
      backend->u.file = g_new0(ChardevFile, 1);
      backend->u.file->out = g_strdup(path);
+    backend->u.file->append = qemu_opt_get_bool(opts, "append", false);
  }
 
  static void qemu_chr_parse_stdio(QemuOpts *opts, ChardevBackend *backend,
@@ -4036,6 +4037,9 @@ QemuOptsList qemu_chardev_opts = {
          },{
              .name = "chardev",
              .type = QEMU_OPT_STRING,
+        },{
+            .name = "append",
+            .type = QEMU_OPT_BOOL,
          },
          { /* end of list */ }
      },
@@ -4096,7 +4100,13 @@ static CharDriverState *qmp_chardev_open_file(const char *id,
      ChardevFile *file = backend->u.file;
      int flags, in = -1, out;
 
-    flags = O_WRONLY | O_TRUNC | O_CREAT | O_BINARY;

qemu-char.c static CharDriverState *qmp_chardev_open_file(const char *id, · line 4112

Quoted 10 lines
qemu-char.c +7 -0
+    flags = O_WRONLY | O_CREAT | O_BINARY;
+    if (file->append) {
+        flags |= O_APPEND;
+    } else {
+        flags |= O_TRUNC;
+    }
+
      out = qmp_chardev_open_file_source(file->out, flags, errp);
      if (out < 0) {
          return NULL;

pls disregard. Originator e-mails are wrong. Sorry :(

#2 lore raw
In reply to Denis V. Lunev
Quoted 23 lines · Denis V. Lunev

From: Olga Krishtal <[email protected]>

Our QA teams wants to preserve serial output of the guest in between QEMU runs to perform post-analysis.

By default this behavior is off (file is truncated each time QEMU is started or device is plugged).

CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
CC Paolo Bonzini <[email protected]>
---
 qapi-schema.json |  7 ++++++-
 qemu-char.c      | 12 +++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)
qapi-schema.json +0 -0
index 8b1a423..802c138 100644

qapi-schema.json line 3026

Quoted 7 lines
qapi-schema.json +4 -0
@@ -3020,11 +3020,16 @@
 #
 # @in:  #optional The name of the input file
 # @out: The name of the output file
+# @append: #optional Open the file in append mode to preserve the content in
+#          between QEMU runs.
+#
+#          Since: 2.6

The 'Since' tag is wrong. Also, the wording might sound better as:

# @append: #optional Open the file in append mode (default false to

           truncate) (Since 2.6)

qapi-schema.json line 3028

Quoted 2 lines
qapi-schema.json +0 -0
 #
 # Since: 1.4

The way you wrote it makes it look like the since 2.6 and since 1.4 tags both apply to the overall struct, which is not true.

Quoted 13 lines
qapi-schema.json +2 -1
 ##
 { 'struct': 'ChardevFile', 'data': { '*in' : 'str',
-                                   'out' : 'str' } }
+                                   'out' : 'str',
+                                   '*append': 'bool' } }
 
 ##
 # @ChardevHostdev:
qemu-char.c +0 -0
index 5448b0f..58454e2 100644

qemu-char.c static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend, · line 3482

Quoted 4 lines
qemu-char.c +1 -0
@@ -3479,6 +3479,7 @@ static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend,
     }
     backend->u.file = g_new0(ChardevFile, 1);
     backend->u.file->out = g_strdup(path);
+    backend->u.file->append = qemu_opt_get_bool(opts, "append", false);

You also need to set backend->u.file->has_append. (Because you are always initializing it, with a default of false, you can set has_append to true, rather than worrying about whether the user provided an "append" option.)

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org