public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Markus Ebner <info@ebner-markus.de>
To: pve-devel@lists.proxmox.com
Cc: Markus Ebner <info@ebner-markus.de>
Subject: [PATCH qemu-server v2 2/3] agent: file-read: Allow maintaining base64-encoding of content
Date: Wed, 25 Feb 2026 12:28:48 +0100	[thread overview]
Message-ID: <20260225112851.124188-3-info@ebner-markus.de> (raw)
In-Reply-To: <20260225112851.124188-1-info@ebner-markus.de>

The previous implementation always decoded the base64-encoded content
received from the qemu-guest-agent file-read call. Since JSON strings
must be comliant unicode text, binary data got escaped using unicode
escape sequences, using the pattern: \u00XX - with XX being the hex
value of the byte to encode. For certain binary files, this lead to a
massively inflated payload size of the API response.

Comparison on my test system:
For a 4MiB test-file generated using
dd if=/dev/urandom bs=4M count=1

- Reading it with decode=1 transfers 8.61MiB and takes 5700ms on avg.
- Reading it with decode=0 transfers 5.59MiB and takes 3300ms on avg.

To be backwards compatible, the decode parameter defaults to 1.

Signed-off-by: Markus Ebner <info@ebner-markus.de>
---
 src/PVE/API2/Qemu/Agent.pm | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/Qemu/Agent.pm b/src/PVE/API2/Qemu/Agent.pm
index f32e1dc2..1f5962e9 100644
--- a/src/PVE/API2/Qemu/Agent.pm
+++ b/src/PVE/API2/Qemu/Agent.pm
@@ -472,6 +472,15 @@ __PACKAGE__->register_method({
                 default => $MAX_READ_SIZE,
                 description => "Number of bytes to read.",
             },
+            decode => {
+                type => 'boolean',
+                optional => 1,
+                default => 1,
+                description => "Data received from the QEMU Guest-Agent is base64 encoded."
+                    . " If this is set to true, the data is decoded."
+                    . " Otherwise the content is forwarded with base64 encoding."
+                    . " Defaults to true.",
+            },
             file => {
                 type => 'string',
                 description => 'The path to the file',
@@ -496,6 +505,7 @@ __PACKAGE__->register_method({
     code => sub {
         my ($param) = @_;
         my $count = int($param->{count} // $MAX_READ_SIZE);
+        my $decode = $param->{decode} // 1;
 
         my $vmid = $param->{vmid};
         my $conf = PVE::QemuConfig->load_config($vmid);
@@ -515,7 +525,10 @@ __PACKAGE__->register_method({
                 mon_cmd($vmid, "guest-file-read", handle => $qgafh, count => int($chunk_size));
             check_agent_error($read, "can't read from file");
 
-            $content .= decode_base64($read->{'buf-b64'});
+            my $chunk = $read->{'buf-b64'};
+            $chunk = decode_base64($chunk) if $decode;
+            $content .= $chunk;
+
             $bytes_read += $read->{count};
             $eof = $read->{eof} // 0;
         }
-- 
2.53.0




  parent reply	other threads:[~2026-02-25 12:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 11:28 [PATCH qemu-server v2 0/3] Extend qga file-read with chunked access for large files Markus Ebner
2026-02-25 11:28 ` [PATCH qemu-server v2 1/3] agent: file-read: Allow specifying max number of bytes to read Markus Ebner
2026-02-26 12:04   ` Fiona Ebner
2026-02-25 11:28 ` Markus Ebner [this message]
2026-02-26 12:04   ` [PATCH qemu-server v2 2/3] agent: file-read: Allow maintaining base64-encoding of content Fiona Ebner
2026-02-25 11:28 ` [PATCH qemu-server v2 3/3] agent: file-read: Allow specifying byte offset to start reading at Markus Ebner
2026-02-26 12:04   ` Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260225112851.124188-3-info@ebner-markus.de \
    --to=info@ebner-markus.de \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal