[libvirt] [PATCH 07/12] qemu: command: Refactor creation of RNG device commandline

Ján Tomko jtomko at redhat.com
Mon Feb 9 15:54:00 UTC 2015


On Fri, Feb 06, 2015 at 04:32:21PM +0100, Peter Krempa wrote:
> As the RNG device is using an -object as backend refactor the code to
> use the JSON to commandline generator so that we can reuse the code
> later in hotplug.
> ---
>  src/qemu/qemu_command.c | 108 +++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 84 insertions(+), 24 deletions(-)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 6380621..9179c1f 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -6154,15 +6154,33 @@ qemuBuildSclpDevStr(virDomainChrDefPtr dev)
> 
> 
>  static int
> -qemuBuildRNGBackendArgs(virCommandPtr cmd,
> -                        virDomainRNGDefPtr dev,
> -                        virQEMUCapsPtr qemuCaps)
> +qemuBuildRNGBackendChrdevStr(virDomainRNGDefPtr rng,
> +                             virQEMUCapsPtr qemuCaps,
> +                             char **chr)
>  {
> -    virBuffer buf = VIR_BUFFER_INITIALIZER;
> -    char *backend = NULL;
> +    *chr = NULL;
> +
> +    if (rng->backend != VIR_DOMAIN_RNG_BACKEND_EGD)
> +        return 0;

Making this a switch ((virDomainRNGBackend)) would check if all the
enum values are handled.

> +
> +    if (!(*chr = qemuBuildChrChardevStr(rng->source.chardev,
> +                                        rng->info.alias, qemuCaps)))
> +        return -1;
> +

> @@ -10146,16 +10186,36 @@ qemuBuildCommandLine(virConnectPtr conn,
>      }
> 
>      for (i = 0; i < def->nrngs; i++) {
> -        char *devstr;
> +        virDomainRNGDefPtr rng = def->rngs[i];
> +        char *tmp;
> +
> +        if (!rng->info.alias) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                           _("RNG device is missing alias"));
> +            goto error;
> +        }

Is it possible for the alias to be NULL at this point?
But it's still better to check twice than crash. :)

Jan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150209/cd057d5b/attachment-0001.sig>


More information about the libvir-list mailing list