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>
This commit is contained in:
Eric Blake 2016-02-09 14:27:16 -07:00 committed by Michael Roth
parent 774ae4254d
commit 0b4b49387c
6 changed files with 70 additions and 40 deletions

View file

@ -473,3 +473,24 @@ done:
return ge;
}
/* Convert GuestFileWhence (either a raw integer or an enum value) into
* the guest's SEEK_ constants. */
int ga_parse_whence(GuestFileWhence *whence, Error **errp)
{
/* Exploit the fact that we picked values to match QGA_SEEK_*. */
if (whence->type == QTYPE_QSTRING) {
whence->type = QTYPE_QINT;
whence->u.value = whence->u.name;
}
switch (whence->u.value) {
case QGA_SEEK_SET:
return SEEK_SET;
case QGA_SEEK_CUR:
return SEEK_CUR;
case QGA_SEEK_END:
return SEEK_END;
}
error_setg(errp, "invalid whence code %"PRId64, whence->u.value);
return -1;
}