qemu-ga: add guest-network-set-interface command
cover qemu-ga: add guest-network-set-interface command
Nowadays, qemu has supported physical NIC hotplug for high network throughput. but it's in conflict with live migration feature, to keep network connectivity, we could to create bond device interface which provides a mechanism for enslaving multiple network interfaces into a single "bond" interface. the active-backup mode can be used for an automatic switch. so this patch is adding a guest-network-set-interface command for creating bond device. so the management can easy to create a bond device dynamically when guest running.
we can specify:
add interface:
{"execute":"guest-network-set-interface", "arguments":
{"interface": {"type":"bond", "name":"bond0", "onboot":"onboot",
"options":"mode=active-backup primary=eth1 miimon=100 updelay=10 use_carrier=ioctl", "ip-address": {"ip-address":"192.168.122.89", "ip-address-type":"ipv4", "prefix":24, "gateway":"192.168.122.1"}, "subInterfaces":[{"name":"eth0"}, {"name":"eth1"}]}}}
delete interface:
{"execute":"guest-network-delete-interface", "arguments":{"name":"bond0"}}
Note:
this patch has introduces netcf lib for create interfaces. because the netcf provides a convenient facility for programs that want to shield themselves from the intricacies of networking setup.
on different environment, creating bonding device is distinct. On Fedora/Redhat, that requires modifying the files ifcfg-eth0, ifcfg-eth1 and ifcfg-bond0 in /etc/sysconfig/network-scripts; on Debian, it requires changing several entries in /etc/network/interfaces.
Chen Fan (2):
qemu-agent: add guest-network-set-interface command
qemu-agent: add guest-network-delete-interface command
configure | 16 +++ qga/commands-posix.c | 312 +++++++++++++++++++++++++++++++++++++++++++++++++++ qga/commands-win32.c | 13 +++ qga/qapi-schema.json | 65 +++++++++++ 4 files changed, 406 insertions(+)
Signature · 1 line
1.9.3
RFC 1/2 qemu-agent: add guest-network-set-interface command
Nowadays, qemu has supported physical NIC hotplug for high network throughput. but it's in conflict with live migration feature, to keep network connectivity, we could to create bond device interface which provides a mechanism for enslaving multiple network interfaces into a single "bond" interface. the active-backup mode can be used for an automatic switch. so this patch is adding a guest-network-set-interface command for creating bond device. so the management can easy to create a bond device dynamically when guest running.
--- configure | 16 ++++ qga/commands-posix.c | 261 +++++++++++++++++++++++++++++++++++++++++++++++++++ qga/commands-win32.c | 7 ++ qga/qapi-schema.json | 54 +++++++++++ 4 files changed, 338 insertions(+)
configure +16 -0
@@ -3618,6 +3618,18 @@ if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \ fi ########################################## +# Do we need netcf +netcf=no +cat > $TMPC << EOF +#include <netcf.h> +int main(void) { return 0; } +EOF +if compile_prog "" "-lnetcf" ; then + netcf=yes + libs_qga="$libs_qga -lnetcf" +fi + +########################################## # spice probe if test "$spice" != "no" ; then cat > $TMPC << EOF
@@ -4697,6 +4709,10 @@ if test "$spice" = "yes" ; then echo "CONFIG_SPICE=y" >> $config_host_mak fi +if test "$netcf" = "yes" ; then + echo "CONFIG_NETCF=y" >> $config_host_mak +fi + if test "$smartcard_nss" = "yes" ; then echo "CONFIG_SMARTCARD_NSS=y" >> $config_host_mak echo "NSS_LIBS=$nss_libs" >> $config_host_mak
qga/commands-posix.c +261 -0
273 lines not on this page · raw message
qga/commands-win32.c +7 -0
@@ -446,6 +446,13 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)return -1 ; } +int64_t qmp_guest_network_set_interface (GuestNetworkInterface2 *interface, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} +/* add unsupported commands to the blacklist */ GList *ga_command_blacklist_init (GList *blacklist) {
qga/qapi-schema.json +54 -0
72 lines not on this page · raw message
Signature · 1 line
1.9.3
RFC 2/2 qemu-agent: add guest-network-delete-interface command
In reply to Chen FanAdd a corresponding command to guest-network-set-interface.
--- qga/commands-posix.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ qga/commands-win32.c | 6 ++++++ qga/qapi-schema.json | 11 +++++++++++ 3 files changed, 68 insertions(+)
qga/commands-posix.c +51 -0
@@ -1971,6 +1971,51 @@ int64_t qmp_guest_network_set_interface(GuestNetworkInterface2 *interface,return 0 ; } + +int64_t qmp_guest_network_delete_interface (const char *name,Error **errp) +{ +struct netcf_if *iface; +int ret =-1 ; +unsigned int flags =0 ; + +/* open netcf */ +if (netcf ==NULL ) { +if (ncf_init (&netcf,NULL ) !=0 ) { +error_setg (errp,"netcf init failed" ); +return ret; + } + } + + iface =ncf_lookup_by_name (netcf, name); +if (!iface) { +error_setg (errp,"couldn't find interface named '%s'" , name); +return ret; + } + +if (ncf_if_status (iface, &flags) <0 ) { +error_setg (errp,"netcf interface get status failed" ); + goto cleanup; + } + +if (flags &NETCF_IFACE_ACTIVE ) { + ret =ncf_if_down (iface); +if (ret <0 ) { +error_setg (errp,"netcf interface stop failed" ); + goto cleanup; + } + } + + ret =ncf_if_undefine (iface); +if (ret <0 ) { +error_setg (errp,"netcf interface delete failed" ); + goto cleanup; + } + + ret =0 ; +cleanup: +ncf_if_free (iface); +return ret; +}#else int64_t qmp_guest_network_set_interface (GuestNetworkInterface2 *interface,Error **errp)
@@ -1978,6 +2023,12 @@ int64_t qmp_guest_network_set_interface(GuestNetworkInterface2 *interface,error_set (errp,QERR_UNSUPPORTED ); return -1; } + +int64_t qmp_guest_network_delete_interface (const char *name,Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +}#endif #define SYSCONF_EXACT (name, errp) sysconf_exact((name), #name, (errp))
qga/commands-win32.c +6 -0
@@ -453,6 +453,12 @@ int64_t qmp_guest_network_set_interface(GuestNetworkInterface2 *interface,return -1 ; } +int64_t qmp_guest_network_delete_interface (const char *name,Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} +/* add unsupported commands to the blacklist */ GList *ga_command_blacklist_init (GList *blacklist) {
qga/qapi-schema.json +11 -0
@@ -642,6 +642,17 @@ 'returns': 'int' } ## +# @guest-network-delete-interface: +# +# @name: interface name. +# +# Since: 2.3 +## +{ 'command': 'guest-network-delete-interface', + 'data' : {'name': 'str' }, + 'returns': 'int' } + +## # @GuestLogicalProcessor: # # @logical-id: Arbitrary guest-specific unique identifier of the VCPU.
Signature · 1 line
1.9.3