This is just a wrapper for virCommand that takes two strings and runs them. Move it to virnetdev.c for easier mocking. --- src/qemu/qemu_interface.c | 29 +---------------------------- src/util/virnetdev.c | 29 +++++++++++++++++++++++++++++ src/util/virnetdev.h | 2 ++ 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 74c9ca8..a4e9d86 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -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 && diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index a505b6c..bb17b84 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -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; +} diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 240fff7..dcc81a6 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -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__ */ -- 2.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list