diff options
author | Eric Blake <eblake@redhat.com> | 2016-02-09 14:27:16 -0700 |
---|---|---|
committer | Michael Roth <mdroth@linux.vnet.ibm.com> | 2016-02-25 09:48:50 -0600 |
commit | 0b4b49387cce8358783a493004b77c1603b34b5c (patch) | |
tree | debae516d511132c0a7155aa62148c26615666af /qga/commands-posix.c | |
parent | 774ae4254d3910f1c94ad6ed44d14cbea0e6a2f2 (diff) | |
download | qemu-0b4b49387cce8358783a493004b77c1603b34b5c.zip qemu-0b4b49387cce8358783a493004b77c1603b34b5c.tar.gz qemu-0b4b49387cce8358783a493004b77c1603b34b5c.tar.bz2 |
qga: Support enum names in guest-file-seek
Magic constants are a pain to use, especially when we run the
risk that our choice of '1' for QGA_SEEK_CUR might differ from
the host or guest's choice of SEEK_CUR. Better is to use an
enum value, via a qapi alternate type for back-compatibility.
With this,
{"command":"guest-file-seek", "arguments":{"handle":1,
"offset":0, "whence":"cur"}}
becomes a synonym for the older
{"command":"guest-file-seek", "arguments":{"handle":1,
"offset":0, "whence":1}}
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga/commands-posix.c')
-rw-r--r-- | qga/commands-posix.c | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 9589b2d..9f51fae 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -550,31 +550,24 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64, } struct GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset, - int64_t whence_code, Error **errp) + GuestFileWhence *whence_code, + Error **errp) { GuestFileHandle *gfh = guest_file_handle_find(handle, errp); GuestFileSeek *seek_data = NULL; FILE *fh; int ret; int whence; + Error *err = NULL; if (!gfh) { return NULL; } /* We stupidly exposed 'whence':'int' in our qapi */ - switch (whence_code) { - case QGA_SEEK_SET: - whence = SEEK_SET; - break; - case QGA_SEEK_CUR: - whence = SEEK_CUR; - break; - case QGA_SEEK_END: - whence = SEEK_END; - break; - default: - error_setg(errp, "invalid whence code %"PRId64, whence_code); + whence = ga_parse_whence(whence_code, &err); + if (err) { + error_propagate(errp, err); return NULL; } |