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:
parent
0ad64e20d8
commit
d5a49e5d4c
@ -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 &&
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user