提交 d5a49e5d 编写于 作者: J Ján Tomko

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.
上级 0ad64e20
...@@ -387,33 +387,6 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg, ...@@ -387,33 +387,6 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
return *tapfd < 0 ? -1 : 0; 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: /* qemuInterfaceEthernetConnect:
* @def: the definition of the VM * @def: the definition of the VM
...@@ -515,7 +488,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, ...@@ -515,7 +488,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
if (net->script && if (net->script &&
qemuExecuteEthernetScript(net->ifname, net->script) < 0) virNetDevRunEthernetScript(net->ifname, net->script) < 0)
goto cleanup; goto cleanup;
if (cfg->macFilter && if (cfg->macFilter &&
......
...@@ -3370,3 +3370,32 @@ virNetDevGetFeatures(const char *ifname ATTRIBUTE_UNUSED, ...@@ -3370,3 +3370,32 @@ virNetDevGetFeatures(const char *ifname ATTRIBUTE_UNUSED,
return 0; return 0;
} }
#endif #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;
}
...@@ -230,4 +230,6 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link, ...@@ -230,4 +230,6 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link,
const char *file) const char *file)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_RETURN_CHECK;
int virNetDevRunEthernetScript(const char *ifname, const char *script);
#endif /* __VIR_NETDEV_H__ */ #endif /* __VIR_NETDEV_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册