On 03/02/2017 06:37 AM, Daniel P. Berrange wrote: > Some of the migration parameters are strings, which default to NULL, > eg tls-hostname and tls-creds. > > The mgmt app will set the tls-creds parameter on both source and target > QEMU instances, in order to trigger use of TLS for migration. > > After performing a TLS encrypted migration though, migration might be > used for other reasons - for example, to save the QEMU state to a file. > We need TLS turned off when doing this, but the migrate-set-parameters > QAPI command does not provide any facility to clear/reset parameters > to their default state. > > If you simply omit the tls_creds parameter in migrate-set-parameters, > then 'has_tls_creds' will be false and so no action will be taken. JSON > allows a parameter to have a nil value, but the QEMU JSON visitor will > reject that when deserializing into a QObject. > > The migration code has no need to distinguish "" vs NULL for the TLS > hostname or TLS credentials object name, since "" is invalid in both > cases. This enables clearing of tls-hostname and tls-creds by > treating "" as equivalent to NULL.
It's also worth documenting in the .json file that "" is special-cased. But the C code change looks okay (with your explanation on v1 that the has_* parameters are not used internally). > > Signed-off-by: Daniel P. Berrange <berra...@redhat.com> > --- > migration/migration.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/migration/migration.c b/migration/migration.c > index c6ae69d..a8cb56e 100644 > --- a/migration/migration.c > +++ b/migration/migration.c > @@ -872,11 +872,19 @@ void qmp_migrate_set_parameters(MigrationParameters > *params, Error **errp) > } > if (params->has_tls_creds) { > g_free(s->parameters.tls_creds); > - s->parameters.tls_creds = g_strdup(params->tls_creds); > + if (*params->tls_creds == '\0') { > + s->parameters.tls_creds = NULL; > + } else { > + s->parameters.tls_creds = g_strdup(params->tls_creds); > + } > } > if (params->has_tls_hostname) { > g_free(s->parameters.tls_hostname); > - s->parameters.tls_hostname = g_strdup(params->tls_hostname); > + if (*params->tls_hostname == '\0') { > + s->parameters.tls_hostname = NULL; > + } else { > + s->parameters.tls_hostname = g_strdup(params->tls_hostname); > + } > } > if (params->has_max_bandwidth) { > s->parameters.max_bandwidth = params->max_bandwidth; > -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature