aboutsummaryrefslogtreecommitdiff
path: root/qga/commands.c
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé <philmd@redhat.com>2020-04-14 15:30:43 +0200
committerMichael Roth <mdroth@linux.vnet.ibm.com>2020-04-15 09:15:53 -0500
commitead83a136d54f7faa315922aff26fa11d216909f (patch)
tree9780b832182caa810e72a4b45e99c2a38f31ab16 /qga/commands.c
parent5d3586b834633c8ac462d4741b85b4036cbc0f93 (diff)
downloadqemu-ead83a136d54f7faa315922aff26fa11d216909f.zip
qemu-ead83a136d54f7faa315922aff26fa11d216909f.tar.gz
qemu-ead83a136d54f7faa315922aff26fa11d216909f.tar.bz2
qga: Extract qmp_guest_file_read() to common commands.c
Extract the common code shared by both POSIX/Win32 implementations. Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga/commands.c')
-rw-r--r--qga/commands.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/qga/commands.c b/qga/commands.c
index 4471a9f..5611117 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -18,6 +18,7 @@
#include "qemu/base64.h"
#include "qemu/cutils.h"
#include "qemu/atomic.h"
+#include "commands-common.h"
/* Maximum captured guest-exec out_data/err_data - 16MB */
#define GUEST_EXEC_MAX_OUTPUT (16*1024*1024)
@@ -547,3 +548,28 @@ error:
g_free(info);
return NULL;
}
+
+GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
+ int64_t count, Error **errp)
+{
+ GuestFileHandle *gfh = guest_file_handle_find(handle, errp);
+ GuestFileRead *read_data;
+
+ if (!gfh) {
+ return NULL;
+ }
+ if (!has_count) {
+ count = QGA_READ_COUNT_DEFAULT;
+ } else if (count < 0 || count >= UINT32_MAX) {
+ error_setg(errp, "value '%" PRId64 "' is invalid for argument count",
+ count);
+ return NULL;
+ }
+
+ read_data = guest_file_read_unsafe(gfh, count, errp);
+ if (!read_data) {
+ slog("guest-file-write failed, handle: %" PRId64, handle);
+ }
+
+ return read_data;
+}