A wrapper function for setting the guest cid via ioctl. Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx> --- configure.ac | 8 ++++++++ src/libvirt_private.syms | 1 + src/util/virnetdev.c | 30 ++++++++++++++++++++++++++++++ src/util/virnetdev.h | 4 ++++ 4 files changed, 43 insertions(+) diff --git a/configure.ac b/configure.ac index cc005ea9e8..b869a17afe 100644 --- a/configure.ac +++ b/configure.ac @@ -641,6 +641,14 @@ if test "$with_linux" = "yes"; then [[#include <linux/devlink.h>]]) fi +dnl +dnl check for VHOST_VSOCK_SET_GUEST_CID +dnl +if test "$with_linux" = "yes"; then + AC_CHECK_DECLS([VHOST_VSOCK_SET_GUEST_CID], [], [], + [[#include <linux/vhost.h>]]) +fi + dnl Allow perl/python overrides AC_PATH_PROGS([PYTHON], [python3 python2 python]) if test -z "$PYTHON"; then diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b4c86b60cc..204ac3806a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2287,6 +2287,7 @@ virNetDevSetRcvMulti; virNetDevSetupControl; virNetDevSysfsFile; virNetDevValidateConfig; +virNetDevVsockSetGuestCid; # util/virnetdevbandwidth.h diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index b250af9e2c..6ac2080821 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -50,6 +50,10 @@ # undef HAVE_STRUCT_IFREQ #endif +#if HAVE_DECL_VHOST_VSOCK_SET_GUEST_CID +# include <linux/vhost.h> +#endif + #if defined(SIOCETHTOOL) && defined(HAVE_STRUCT_IFREQ) # include <linux/types.h> # include <linux/ethtool.h> @@ -3605,3 +3609,29 @@ virNetDevRunEthernetScript(const char *ifname, const char *script) virCommandFree(cmd); return ret; } + +#if HAVE_DECL_VHOST_VSOCK_SET_GUEST_CID +int +virNetDevVsockSetGuestCid(int fd, + unsigned int guest_cid) +{ + uint64_t val = guest_cid; + + if (ioctl(fd, VHOST_VSOCK_SET_GUEST_CID, &val) < 0) { + virReportSystemError(errno, "%s", + _("failed to set guest cid")); + return -1; + } + + return 0; +} +#else +int +virNetDevVsockSetGuestCid(int fd ATTRIBUTE_UNUSED, + unsigned int guest_cid ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("vsock is not supported")); + return -1; +} +#endif diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 71eaf45e30..836603b65d 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -313,4 +313,8 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link, int virNetDevRunEthernetScript(const char *ifname, const char *script) ATTRIBUTE_NOINLINE; + +int +virNetDevVsockSetGuestCid(int fd, + unsigned int guest_cid); #endif /* __VIR_NETDEV_H__ */ -- 2.16.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list