Re: [PATCH v1 3/4] xenconfig: channels conversion support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Joao Martins wrote:
> On 09/20/2016 04:04 AM, Jim Fehlig wrote:
>> On 09/16/2016 05:43 PM, Joao Martins wrote:
>>> Add support for formating/parsing libxl channels.
>>>
>>> Syntax on xen libxl goes as following:
>>> channel=["connection=pty|socket,path=/path/to/socket,name=XXX",...]
>>>
>>> Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx>
>>> ---
>>>  src/xenconfig/xen_xl.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++++
>>>  1 file changed, 176 insertions(+)
>>>
>>> diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
>>> index 7774dfc..eea24b9 100644
>>> --- a/src/xenconfig/xen_xl.c
>>> +++ b/src/xenconfig/xen_xl.c
>>> @@ -685,6 +685,93 @@ xenParseXLUSB(virConfPtr conf, virDomainDefPtr def)
>>>      return 0;
>>>  }
>>>  
>>> +static int
>>> +xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
>>> +{
>>> +    virConfValuePtr list = virConfGetValue(conf, "channel");
>>> +    virDomainChrDefPtr channel = NULL;
>>> +    char *name = NULL;
>>> +    char *path = NULL;
>>> +
>>> +    if (list && list->type == VIR_CONF_LIST) {
>>> +        list = list->list;
>>> +        while (list) {
>>> +            char type[10];
>>> +            char *key;
>>> +
>>> +            if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
>>> +                goto skipchannel;
>>> +
>>> +            key = list->str;
>>> +            while (key) {
>>> +                char *data;
>>> +                char *nextkey = strchr(key, ',');
>>> +
>>> +                if (!(data = strchr(key, '=')))
>>> +                    goto skipchannel;
>>> +                data++;
>>> +
>>> +                if (STRPREFIX(key, "connection=")) {
>>> +                    int len = nextkey ? (nextkey - data) : sizeof(type) - 1;
>>> +                    if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
>>> +                        virReportError(VIR_ERR_INTERNAL_ERROR,
>>> +                                       _("connection %s too big"), data);
>>> +                        goto skipchannel;
>>> +                    }
>>> +                } else if (STRPREFIX(key, "name=")) {
>>> +                    int len = nextkey ? (nextkey - data) : strlen(data);
>>> +                    VIR_FREE(name);
>>> +                    if (VIR_STRNDUP(name, data, len) < 0)
>>> +                        goto cleanup;
>>> +                } else if (STRPREFIX(key, "path=")) {
>>> +                    int len = nextkey ? (nextkey - data) : strlen(data);
>>> +                    VIR_FREE(path);
>>> +                    if (VIR_STRNDUP(path, data, len) < 0)
>>> +                        goto cleanup;
>>> +                }
>>> +
>>> +                while (nextkey && (nextkey[0] == ',' ||
>>> +                                   nextkey[0] == ' ' ||
>>> +                                   nextkey[0] == '\t'))
>>> +                    nextkey++;
>>> +                key = nextkey;
>>> +            }
>>> +
>>> +            if (!(channel = virDomainChrDefNew()))
>>> +                goto cleanup;
>>> +
>>> +            if (STRPREFIX(type, "socket")) {
>>> +                channel->source.type = VIR_DOMAIN_CHR_TYPE_UNIX;
>>> +                channel->source.data.nix.path = path;
>>> +                channel->source.data.nix.listen = 1;
>>> +            } else if (STRPREFIX(type, "pty")) {
>>> +                channel->source.type = VIR_DOMAIN_CHR_TYPE_PTY;
>>> +                VIR_FREE(path);
>>> +            } else {
>>> +                goto cleanup;
>>> +            }
>>> +
>>> +            channel->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL;
>>> +            channel->targetType = VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN;
>>> +            channel->target.name = name;
>>> +
>>> +            if (VIR_APPEND_ELEMENT(def->channels, def->nchannels, channel) < 0)
>>> +                goto cleanup;
>>> +
>>> +        skipchannel:
>>> +            list = list->next;
>>> +        }
>>> +    }
>>> +
>>> +    return 0;
>>> +
>>> + cleanup:
>>> +    virDomainChrDefFree(channel);
>>> +    VIR_FREE(path);
>>> +    VIR_FREE(name);
>>> +    return -1;
>>> +}
>>> +
>>>  virDomainDefPtr
>>>  xenParseXL(virConfPtr conf,
>>>             virCapsPtr caps,
>>> @@ -720,6 +807,9 @@ xenParseXL(virConfPtr conf,
>>>      if (xenParseXLUSBController(conf, def) < 0)
>>>          goto cleanup;
>>>  
>>> +    if (xenParseXLChannel(conf, def) < 0)
>>> +        goto cleanup;
>>> +
>>>      if (virDomainDefPostParse(def, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
>>>                                xmlopt) < 0)
>>>          goto cleanup;
>>> @@ -1347,6 +1437,89 @@ xenFormatXLUSB(virConfPtr conf,
>>>      return -1;
>>>  }
>>>  
>>> +static int
>>> +xenFormatXLChannel(virConfValuePtr list, virDomainChrDefPtr channel)
>>> +{
>>> +    virBuffer buf = VIR_BUFFER_INITIALIZER;
>>> +    int sourceType = channel->source.type;
>>> +    virConfValuePtr val, tmp;
>>> +
>>> +    /* connection */
>>> +    virBufferAddLit(&buf, "connection=");
>>> +    switch (sourceType) {
>>> +        case VIR_DOMAIN_CHR_TYPE_PTY:
>>> +            virBufferAddLit(&buf, "pty,");
>>> +            break;
>>> +        case VIR_DOMAIN_CHR_TYPE_UNIX:
>>> +            virBufferAddLit(&buf, "socket,");
>>> +            break;
>>> +        default:
>>> +            goto cleanup;
>>> +    }
>>> +
>>> +    /* path */
>>> +    if (sourceType == VIR_DOMAIN_CHR_TYPE_UNIX)
>>> +        virBufferAsprintf(&buf, "path=%s,", channel->source.data.nix.path);
>> Can this be added to the VIR_DOMAIN_CHR_TYPE_UNIX case above?
> Yeap, it should have been that way in the first place. I will amend this to the
> case above.
> 
> Btw I assume that I'll have to regenerate the path for inactive XMLs that don't
> have the <source> path included, right?

I didn't look too closely, but it appears the qemu driver will only generate the
source path once. I think the same path could be reused as long as it doesn't
include components that will change, such as domid.

Regards,
Jim

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]