1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemuExecuteEthernetScript: move to util

This is just a wrapper for virCommand that takes two strings
and runs them.

Move it to virnetdev.c for easier mocking.
This commit is contained in:
Ján Tomko 2016-04-13 10:33:36 +02:00
parent 0ad64e20d8
commit d5a49e5d4c
3 changed files with 32 additions and 28 deletions

View File

@ -387,33 +387,6 @@ 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);
ret = virCommandRun(cmd, NULL);
virCommandFree(cmd);
return ret;
}
/* qemuInterfaceEthernetConnect:
* @def: the definition of the VM
@ -515,7 +488,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
if (net->script &&
qemuExecuteEthernetScript(net->ifname, net->script) < 0)
virNetDevRunEthernetScript(net->ifname, net->script) < 0)
goto cleanup;
if (cfg->macFilter &&

View File

@ -3370,3 +3370,32 @@ virNetDevGetFeatures(const char *ifname ATTRIBUTE_UNUSED,
return 0;
}
#endif
/**
* virNetDevRunEthernetScript:
* @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
*/
int
virNetDevRunEthernetScript(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);
ret = virCommandRun(cmd, NULL);
virCommandFree(cmd);
return ret;
}

View File

@ -230,4 +230,6 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link,
const char *file)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_RETURN_CHECK;
int virNetDevRunEthernetScript(const char *ifname, const char *script);
#endif /* __VIR_NETDEV_H__ */