all lists on 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 v3 3/3] agent: file-read: Allow specifying byte offset to start reading at
Date: Thu, 26 Feb 2026 13:31:19 +0100	[thread overview]
Message-ID: <20260226123122.60418-4-info@ebner-markus.de> (raw)
In-Reply-To: <20260226123122.60418-1-info@ebner-markus.de>

The previous implementation only allowed reads of fixed size starting
at byte offset 0. This made the Proxmox's agent/file-read unsuitable
for reading large files.
The new offset parameter allows specifying a byte offset position
relative to the start of the file (offset 0) from which the following
read should be performed. The implementation's behavior follows the
lseek semantics - directly following qemu-guest-agent's behavior:

- fseek() does not perform validation against the file size
- Seeking beyond the end of the file is not an error but explicitly
  allowed and specified behavior
- Subsequent fread() calls at positions beyond the file size return
  zero bytes

Additionally, this is equivalent to the behavior of POSIX pread().
Reading a large file block-by-block thus becomes (pseudo-code):
let content = [];
while(response.truncated) {
    response = proxmox.agent_file_read(offset = content.length);
    content .= response.content;
}

To be backwards compatible, offset defaults to 0.

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

diff --git a/src/PVE/API2/Qemu/Agent.pm b/src/PVE/API2/Qemu/Agent.pm
index 49dbef09..a4234968 100644
--- a/src/PVE/API2/Qemu/Agent.pm
+++ b/src/PVE/API2/Qemu/Agent.pm
@@ -485,6 +485,13 @@ __PACKAGE__->register_method({
                 type => 'string',
                 description => 'The path to the file',
             },
+            offset => {
+                type => 'integer',
+                optional => 1,
+                minimum => 0,
+                default => 0,
+                description => "Offset to start reading at",
+            },
         },
     },
     returns => {
@@ -506,6 +513,7 @@ __PACKAGE__->register_method({
         my ($param) = @_;
         my $count = $param->{count} // $MAX_READ_SIZE;
         my $decode = $param->{decode} // 1;
+        my $offset = $param->{offset} // 0;
 
         my $vmid = $param->{vmid};
         my $conf = PVE::QemuConfig->load_config($vmid);
@@ -513,6 +521,16 @@ __PACKAGE__->register_method({
         my $qgafh =
             agent_cmd($vmid, $conf, "file-open", { path => $param->{file} }, "can't open file");
 
+        if ($offset > 0) {
+            my $seek = mon_cmd(
+                $vmid, "guest-file-seek",
+                handle => $qgafh,
+                offset => int($offset),
+                whence => 'set',
+            );
+            check_agent_error($seek, "can't seek to offset position");
+        }
+
         my $bytes_read = 0;
         my $eof = 0;
         my $read_size = 1024 * 1024;
-- 
2.53.0




  parent reply	other threads:[~2026-02-26 12:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26 12:31 [PATCH qemu-server v3 0/3] Extend qga file-read with chunked access for large files Markus Ebner
2026-02-26 12:31 ` [PATCH qemu-server v3 1/3] agent: file-read: Allow specifying max number of bytes to read Markus Ebner
2026-02-26 12:31 ` [PATCH qemu-server v3 2/3] agent: file-read: Allow maintaining base64-encoding of content Markus Ebner
2026-02-26 12:31 ` Markus Ebner [this message]
2026-02-26 12:42 ` applied: [PATCH qemu-server v3 0/3] Extend qga file-read with chunked access for large files 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=20260226123122.60418-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal