mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
API: add VIR_TYPED_PARAM_STRING
This allows strings to be transported between client and server
in the context of name-type-value virTypedParameter functions.
For compatibility,
o new clients will not send strings to old servers, based on
a feature check
o new servers will not send strings to old clients without the
flag VIR_TYPED_PARAM_STRING_OKAY; this will be enforced at
the RPC layer in the next patch, so that drivers need not
worry about it in general. The one exception is that
virDomainGetSchedulerParameters lacks a flags argument, so
it must not return a string; drivers that forward that
function on to virDomainGetSchedulerParametersFlags will
have to pay attention to the flag.
o the flag VIR_TYPED_PARAM_STRING_OKAY is set automatically,
based on a feature check (so far, no driver implements it),
so clients do not have to worry about it
Future patches can then enable the feature on a per-driver basis.
This patch also ensures that drivers can blindly strdup() field
names (previously, a malicious client could stuff 80 non-NUL bytes
into field and cause a read overrun).
* src/libvirt_internal.h (VIR_DRV_FEATURE_TYPED_PARAM_STRING): New
driver feature.
* src/libvirt.c (virTypedParameterValidateSet)
(virTypedParameterSanitizeGet): New helper functions.
(virDomainSetMemoryParameters, virDomainSetBlkioParameters)
(virDomainSetSchedulerParameters)
(virDomainSetSchedulerParametersFlags)
(virDomainGetMemoryParameters, virDomainGetBlkioParameters)
(virDomainGetSchedulerParameters)
(virDomainGetSchedulerParametersFlags, virDomainBlockStatsFlags):
Use them.
* src/util/util.h (virTypedParameterArrayClear): New helper
function.
* src/util/util.c (virTypedParameterArrayClear): Implement it.
* src/libvirt_private.syms (util.h): Export it.
Based on an initial patch by Hu Tao, with feedback from
Daniel P. Berrange.
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
@@ -200,11 +200,14 @@ typedef virDomainControlInfo *virDomainControlInfoPtr;
|
||||
* current domain state. VIR_DOMAIN_AFFECT_LIVE requires a running
|
||||
* domain, and VIR_DOMAIN_AFFECT_CONFIG requires a persistent domain
|
||||
* (whether or not it is running).
|
||||
*
|
||||
* These enums should not conflict with those of virTypedParameterFlags.
|
||||
*/
|
||||
typedef enum {
|
||||
VIR_DOMAIN_AFFECT_CURRENT = 0, /* Affect current domain state. */
|
||||
VIR_DOMAIN_AFFECT_LIVE = 1 << 0, /* Affect running domain state. */
|
||||
VIR_DOMAIN_AFFECT_CONFIG = 1 << 1, /* Affect persistent domain state. */
|
||||
/* 1 << 2 is reserved for virTypedParameterFlags */
|
||||
} virDomainModificationImpact;
|
||||
|
||||
/**
|
||||
@@ -489,9 +492,35 @@ typedef enum {
|
||||
VIR_TYPED_PARAM_LLONG = 3, /* long long case */
|
||||
VIR_TYPED_PARAM_ULLONG = 4, /* unsigned long long case */
|
||||
VIR_TYPED_PARAM_DOUBLE = 5, /* double case */
|
||||
VIR_TYPED_PARAM_BOOLEAN = 6 /* boolean(character) case */
|
||||
VIR_TYPED_PARAM_BOOLEAN = 6, /* boolean(character) case */
|
||||
VIR_TYPED_PARAM_STRING = 7, /* string case */
|
||||
} virTypedParameterType;
|
||||
|
||||
/**
|
||||
* virTypedParameterFlags:
|
||||
*
|
||||
* Flags related to libvirt APIs that use virTypedParameter.
|
||||
*
|
||||
* These enums should not conflict with those of virDomainModificationImpact.
|
||||
*/
|
||||
typedef enum {
|
||||
/* 1 << 0 is reserved for virDomainModificationImpact */
|
||||
/* 1 << 1 is reserved for virDomainModificationImpact */
|
||||
|
||||
/* Older servers lacked the ability to handle string typed
|
||||
* parameters. Attempts to set a string parameter with an older
|
||||
* server will fail at the client, but attempts to retrieve
|
||||
* parameters must not return strings from a new server to an
|
||||
* older client, so this flag exists to identify newer clients to
|
||||
* newer servers. This flag is automatically set when needed, so
|
||||
* the user does not have to worry about it; however, manually
|
||||
* setting the flag can be used to reject servers that cannot
|
||||
* return typed strings, even if no strings would be returned.
|
||||
*/
|
||||
VIR_TYPED_PARAM_STRING_OKAY = 1 << 2,
|
||||
|
||||
} virTypedParameterFlags;
|
||||
|
||||
/**
|
||||
* VIR_TYPED_PARAM_FIELD_LENGTH:
|
||||
*
|
||||
@@ -520,6 +549,7 @@ struct _virTypedParameter {
|
||||
unsigned long long int ul; /* type is ULLONG */
|
||||
double d; /* type is DOUBLE */
|
||||
char b; /* type is BOOLEAN */
|
||||
char *s; /* type is STRING, may not be NULL */
|
||||
} value; /* parameter value */
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user