[libvirt] [PATCH v4] automatic create tap device with network type ethernet

Vasiliy Tolstov v.tolstov at selfip.ru
Tue Dec 9 09:43:29 UTC 2014


V3 have unconditional running script , v4 check for net->script before
running script
09 дек. 2014 г. 11:47 пользователь "Michal Privoznik" <mprivozn at redhat.com>
написал:

> On 08.12.2014 11:48, Vasiliy Tolstov wrote:
>
>> If user not specify network type ethernet, assume that user
>> needs simple tap device created with libvirt.
>> This patch does not need to run external script to create tap device or
>> add root to qemu process. Also libvirt runs script after device creating,
>> if user provide it.
>>
>> Difference with v3 that script runs only if it provided.
>>
>> Signed-off-by: Vasiliy Tolstov <v.tolstov at selfip.ru>
>> ---
>>   src/qemu/qemu_command.c | 119 ++++++++++++++++++++++++++++++
>> +++++-------------
>>   src/qemu/qemu_hotplug.c |  10 +---
>>   src/qemu/qemu_process.c |   4 ++
>>   3 files changed, 93 insertions(+), 40 deletions(-)
>>
>> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
>> index 1831323..78614d5 100644
>> --- a/src/qemu/qemu_command.c
>> +++ b/src/qemu/qemu_command.c
>> @@ -276,6 +276,40 @@ static int
>> qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
>>       return *tapfd < 0 ? -1 : 0;
>>   }
>>
>> +/**
>> + * qemuExecuteEthernetScript:
>> + * @ifname: the interface name
>> + * @script: the script name
>> +
>> + * This function executes script for new tap device created by libvirt.
>> + *
>> + * Returns 0 in case of success or -1 on failure
>> + */
>> +static int qemuExecuteEthernetScript(const char *ifname, const char
>> *script)
>> +{
>> +    virCommandPtr cmd;
>> +    int ret;
>> +
>> +    cmd = virCommandNew(script);
>> +    virCommandAddArgFormat(cmd, "%s", ifname);
>> +    virCommandClearCaps(cmd);
>> +#ifdef CAP_NET_ADMIN
>> +    virCommandAllowCap(cmd, CAP_NET_ADMIN);
>> +#endif
>> +    virCommandAddEnvPassCommon(cmd);
>> +
>> +    if (virCommandRun(cmd, NULL) < 0) {
>> +      ret = -1;
>> +    } else {
>> +      ret = 0;
>> +    }
>> +
>> + cleanup:
>> +    virCommandFree(cmd);
>> +    return ret;
>> +}
>> +
>> +
>>   int
>>   qemuNetworkIfaceConnect(virDomainDefPtr def,
>>                           virConnectPtr conn,
>> @@ -313,7 +347,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
>>       } else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
>>           if (VIR_STRDUP(brname, virDomainNetGetActualBridgeName(net)) <
>> 0)
>>               return ret;
>> -    } else {
>> +    } else if (actualType != VIR_DOMAIN_NET_TYPE_ETHERNET) {
>>           virReportError(VIR_ERR_INTERNAL_ERROR,
>>                          _("Network type %d is not supported"),
>>                          virDomainNetGetActualType(net));
>> @@ -335,30 +369,44 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
>>           tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
>>       }
>>
>> -    if (cfg->privileged) {
>> -        if (virNetDevTapCreateInBridgePort(brname, &net->ifname,
>> &net->mac,
>> -                                           def->uuid, tunpath, tapfd,
>> *tapfdSize,
>> -
>> virDomainNetGetActualVirtPortProfile(net),
>> -                                           virDomainNetGetActualVlan(net)
>> ,
>> -                                           tap_create_flags) < 0) {
>> +    if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) {
>> +        if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, *tapfdSize,
>> +                               tap_create_flags) < 0) {
>>
>
> It seems like your MTA mangled the patch. Moreover, how is this different
> to v3 that I've sent?
>
> Michal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20141209/f4635134/attachment-0001.htm>


More information about the libvir-list mailing list