[libvirt] [PATCHv2 3/8] conf: Add support for RNG device configuration in XML

Eric Blake eblake at redhat.com
Fri Feb 22 23:33:14 UTC 2013


On 02/21/2013 07:47 AM, Peter Krempa wrote:
> This patch adds basic configuration support for the RNG device suporting

s/suporting/supporting/

> the virtio model with the "random" and "egd" backend types as described
> in the schema in the previous patch.
> ---
> 
> Notes:
>     Version 2:
>     - fix a ton of memory leaks (I assumed that virXMLGetProp returns static strings)
>     - Add new device type to even more places
>     - Fix error message c&p error
>     - Fix memleak in RNGDef free func

> +    case VIR_DOMAIN_RNG_BACKEND_EGD:
> +        {
> +            char *type = virXMLPropString(backends[0], "type");
> +            if (!type) {
> +                virReportError(VIR_ERR_XML_ERROR, "%s",
> +                               _("missing EGD backend type"));
> +                goto error;
> +            }
> +
> +
> +            if (VIR_ALLOC(def->source.chardev) < 0) {
> +                virReportOOMError();
> +                goto error;
> +            }

Memleak on 'type'.

> @@ -10601,6 +10734,22 @@ virDomainDefParseXML(virCapsPtr caps,
>          }
>      }
> 
> +    /* Parse the RNG device */
> +    if ((n = virXPathNodeSet("./devices/rng", ctxt, &nodes)) < 0)
> +        goto error;
> +
> +    if (n > 1) {
> +        virReportError(VIR_ERR_XML_ERROR, "%s",
> +                       _("only a single RNG device is supported"));

Is this an inherent limit of qemu?  For that matter, is it an inherent
limit, and no hypervisor can ever support more than one?  In the bare
metal case, can't you plug in multiple rng hardware dongles?


> +static int
> +virDomainRNGDefFormat(virBufferPtr buf,
> +                      virDomainRNGDefPtr def,
> +                      unsigned int flags)
> +{
> +    const char *model = virDomainRNGModelTypeToString(def->model);
> +    const char *backend = virDomainRNGBackendTypeToString(def->backend);
> +
> +    virBufferAsprintf(buf, "    <rng model='%s'>\n", model);
> +    virBufferAsprintf(buf, "      <backend model='%s'", backend);
> +
> +    switch ((enum virDomainRNGBackend) def->backend) {
> +    case VIR_DOMAIN_RNG_BACKEND_RANDOM:
> +        if (def->source.file)
> +            virBufferAsprintf(buf, ">%s</backend>\n", def->source.file);

Must use virBufferEscape(), as a random file name could contain
characters that are special to XML.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130222/ccd12d7c/attachment-0001.sig>


More information about the libvir-list mailing list