[libvirt] [PATCH 1/1] Support libnl-3 as well as libnl-1

configure.ac: Check for libnl-3. If found, find libnl-route-3. If not found, do the original check to look for libnl-1. src/util/virnetlink.c: support libnl3 api. I could play games to make the patch smaller, but this would just hide what is actually needing to be done at the expense of clarity. src/Makefile.am and daemon/Makefile.am: Add LIBNL_ROUTE3_{LIBS,CFLAGS} Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h, which is the reason why the LIBNL_CFLAGS need to be added to a bunch of places where they weren't needed with libnl1. Those spots probaby don't actually need to also have LIBNL*LIBS added, but while I may be looking at it wrong, it seemed right to do so. I haven't gotten as far as to compile this into a package on ubuntu, but the source does build with libnl-3 as well as with libnl-1. Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> --- configure.ac | 24 ++++++++++++----- daemon/Makefile.am | 5 +++- src/Makefile.am | 25 ++++++++++++------ src/util/virnetlink.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index a819898..ab40e1d 100644 --- a/configure.ac +++ b/configure.ac @@ -2626,19 +2626,29 @@ AM_CONDITIONAL([WITH_VIRTUALPORT], [test "$with_virtualport" = "yes"]) dnl netlink library +LIBNL_ROUTE3_CFLAGS="" +LIBNL_ROUTE3_LIBS="" LIBNL_CFLAGS="" LIBNL_LIBS="" have_libnl=no if test "$with_linux" = "yes"; then - PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + PKG_CHECK_MODULES([LIBNL],[libnl-3.0],[ have_libnl=yes - AC_DEFINE_UNQUOTED([HAVE_LIBNL], 1, [whether the netlink library is available]) - ], [ - if test "$with_macvtap" = "yes"; then - AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) - fi - ]) + AC_DEFINE([HAVE_LIBNL3], [1], [Use libnl-3.0]) + AC_DEFINE([HAVE_LIBNL], [1], [whether the netlink library is available]) + PKG_CHECK_MODULES([LIBNL_ROUTE3],[libnl-route-3.0]) + ], + PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + have_libnl=yes + AC_DEFINE_UNQUOTED([HAVE_LIBNL], 1, [whether the netlink library is available]) + AC_DEFINE_UNQUOTED([HAVE_LIBNL1], 1, [whether the netlink v1 library is available]) + ], [ + if test "$with_macvtap" = "yes"; then + AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) + fi + ]) + ) fi AM_CONDITIONAL([HAVE_LIBNL], [test "$have_libnl" = "yes"]) diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 24cce8f..8074803 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -95,6 +95,7 @@ libvirtd_SOURCES = $(DAEMON_SOURCES) libvirtd_CFLAGS = \ $(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) $(SASL_CFLAGS) \ $(XDR_CFLAGS) $(POLKIT_CFLAGS) $(DBUS_CFLAGS) \ + $(LIBNL_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) \ $(WARN_CFLAGS) \ $(COVERAGE_CFLAGS) \ -DQEMUD_PID_FILE="\"$(QEMUD_PID_FILE)\"" \ @@ -109,7 +110,9 @@ libvirtd_LDADD = \ $(GNUTLS_LIBS) \ $(SASL_LIBS) \ $(DBUS_LIBS) \ - $(POLKIT_LIBS) + $(POLKIT_LIBS) \ + $(LIBNL_LIBS) \ + $(LIBNL_ROUTE3_LIBS) if WITH_DTRACE_PROBES libvirtd_LDADD += ../src/probes.o diff --git a/src/Makefile.am b/src/Makefile.am index e48dfa5..c159c1e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -576,10 +576,10 @@ libvirt_util_la_SOURCES = \ $(UTIL_SOURCES) libvirt_util_la_CFLAGS = $(CAPNG_CFLAGS) $(YAJL_CFLAGS) $(LIBNL_CFLAGS) \ $(AM_CFLAGS) $(AUDIT_CFLAGS) $(DEVMAPPER_CFLAGS) \ - $(DBUS_CFLAGS) + $(DBUS_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) libvirt_util_la_LIBADD = $(CAPNG_LIBS) $(YAJL_LIBS) $(LIBNL_LIBS) \ $(THREAD_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \ - $(RT_LIBS) $(DBUS_LIBS) + $(RT_LIBS) $(DBUS_LIBS) $(LIBNL_ROUTE3_LIBS) noinst_LTLIBRARIES += libvirt_conf.la @@ -809,12 +809,16 @@ endif libvirt_driver_qemu_la_CFLAGS = $(NUMACTL_CFLAGS) \ $(GNUTLS_CFLAGS) \ $(LIBXML_CFLAGS) \ + $(LIBNL_CFLAGS) \ + $(LIBNL_ROUTE3_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_qemu_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_qemu_la_LIBADD = $(NUMACTL_LIBS) \ $(CAPNG_LIBS) \ $(GNUTLS_LIBS) \ - $(LIBXML_LIBS) + $(LIBXML_LIBS) \ + $(LIBNL_LIBS) \ + $(LIBNL_ROUTE3_LIBS) if WITH_DRIVER_MODULES libvirt_driver_qemu_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_qemu_la_LDFLAGS += -module -avoid-version @@ -840,8 +844,9 @@ noinst_LTLIBRARIES += libvirt_driver_lxc.la #libvirt_la_BUILT_LIBADD += libvirt_driver_lxc.la endif libvirt_driver_lxc_la_CFLAGS = \ + $(LIBNL_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) -libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) +libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS) $(LIBNL_ROUTE3_LIBS) if WITH_SECDRIVER_SELINUX libvirt_driver_lxc_la_LIBADD += $(SELINUX_LIBS) endif @@ -941,9 +946,10 @@ noinst_LTLIBRARIES += libvirt_driver_network.la #libvirt_la_BUILT_LIBADD += libvirt_driver_network.la endif libvirt_driver_network_la_CFLAGS = \ + $(LIBNL_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) if WITH_DRIVER_MODULES -libvirt_driver_network_la_LIBADD = ../gnulib/lib/libgnu.la +libvirt_driver_network_la_LIBADD = ../gnulib/lib/libgnu.la $(LIBNL_LIBS) $(LIBNL_ROUTE3_LIBS) libvirt_driver_network_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) endif libvirt_driver_network_la_SOURCES = $(NETWORK_DRIVER_SOURCES) @@ -1086,9 +1092,10 @@ libvirt_la_BUILT_LIBADD += libvirt_driver_nwfilter.la noinst_LTLIBRARIES += libvirt_driver_nwfilter.la endif libvirt_driver_nwfilter_la_CFLAGS = $(LIBPCAP_CFLAGS) \ - -I$(top_srcdir)/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(LIBNL_CFLAGS) \ + $(LIBNL_ROUTE3_CFLAGS) $(AM_CFLAGS) libvirt_driver_nwfilter_la_LDFLAGS = $(LD_AMFLAGS) -libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) +libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) $(LIBNL_LIBS) $(LIBNL_ROUTE3_LIBS) if WITH_DRIVER_MODULES libvirt_driver_nwfilter_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_nwfilter_la_LDFLAGS += -module -avoid-version @@ -1522,7 +1529,7 @@ libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(AM_LDFLAGS) libvirt_lxc_LDADD = $(CAPNG_LIBS) $(YAJL_LIBS) \ $(LIBXML_LIBS) $(NUMACTL_LIBS) $(THREAD_LIBS) \ $(LIBNL_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \ - $(RT_LIBS) $(DBUS_LIBS) \ + $(RT_LIBS) $(DBUS_LIBS) $(LIBNL_ROUTE3_LIBS) \ ../gnulib/lib/libgnu.la if WITH_DTRACE_PROBES libvirt_lxc_LDADD += probes.o @@ -1540,6 +1547,8 @@ libvirt_lxc_CFLAGS = \ $(YAJL_CFLAGS) \ $(AUDIT_CFLAGS) \ $(DBUS_CFLAGS) \ + $(LIBNL_CFLAGS) \ + $(LIBNL_ROUTE3_CFLAGS) \ -I$(top_srcdir)/src/conf \ $(AM_CFLAGS) if HAVE_LIBBLKID diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index b2e9d51..1d3cd2e 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -67,7 +67,11 @@ struct _virNetlinkEventSrvPrivate { virMutex lock; int eventwatch; int netlinkfd; +#ifdef HAVE_LIBNL1 struct nl_handle *netlinknh; +#else + struct nl_sock *netlinksock; +#endif /*Events*/ int handled; size_t handlesCount; @@ -121,15 +125,31 @@ int virNetlinkCommand(struct nl_msg *nl_msg, int fd; int n; struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg); +#ifdef HAVE_LIBNL1 struct nl_handle *nlhandle = nl_handle_alloc(); +#else + struct nl_sock *nlsock = nl_socket_alloc(); +#endif +#ifdef HAVE_LIBNL1 if (!nlhandle) { +#else + if (!nlsock) { +#endif virReportSystemError(errno, +#ifdef HAVE_LIBNL1 "%s", _("cannot allocate nlhandle for netlink")); +#else + "%s", _("cannot allocate nlsock for netlink")); +#endif return -1; } +#ifdef HAVE_LIBNL1 if (nl_connect(nlhandle, NETLINK_ROUTE) < 0) { +#else + if (nl_connect(nlsock, NETLINK_ROUTE) < 0) { +#endif virReportSystemError(errno, "%s", _("cannot connect to netlink socket")); rc = -1; @@ -140,7 +160,11 @@ int virNetlinkCommand(struct nl_msg *nl_msg, nlmsg->nlmsg_pid = getpid(); +#ifdef HAVE_LIBNL1 nbytes = nl_send_auto_complete(nlhandle, nl_msg); +#else + nbytes = nl_send_auto_complete(nlsock, nl_msg); +#endif if (nbytes < 0) { virReportSystemError(errno, "%s", _("cannot send to netlink socket")); @@ -148,7 +172,11 @@ int virNetlinkCommand(struct nl_msg *nl_msg, goto error; } +#ifdef HAVE_LIBNL1 fd = nl_socket_get_fd(nlhandle); +#else + fd = nl_socket_get_fd(nlsock); +#endif FD_ZERO(&readfds); FD_SET(fd, &readfds); @@ -165,7 +193,11 @@ int virNetlinkCommand(struct nl_msg *nl_msg, goto error; } +#ifdef HAVE_LIBNL1 *respbuflen = nl_recv(nlhandle, &nladdr, respbuf, NULL); +#else + *respbuflen = nl_recv(nlsock, &nladdr, respbuf, NULL); +#endif if (*respbuflen <= 0) { virReportSystemError(errno, "%s", _("nl_recv failed")); @@ -178,7 +210,11 @@ error: *respbuflen = 0; } +#ifdef HAVE_LIBNL1 nl_handle_destroy(nlhandle); +#else + nl_socket_free(nlsock); +#endif return rc; } @@ -233,7 +269,11 @@ virNetlinkEventCallback(int watch, int i, length; bool handled = false; +#ifdef HAVE_LIBNL1 length = nl_recv(srv->netlinknh, &peer, &msg, &creds); +#else + length = nl_recv(srv->netlinksock, &peer, &msg, &creds); +#endif if (length == 0) return; @@ -284,8 +324,13 @@ virNetlinkEventServiceStop(void) return 0; virNetlinkEventServerLock(srv); +#ifdef HAVE_LIBNL1 nl_close(srv->netlinknh); nl_handle_destroy(srv->netlinknh); +#else + nl_close(srv->netlinksock); + nl_socket_free(srv->netlinksock); +#endif virEventRemoveHandle(srv->eventwatch); /* free any remaining clients on the list */ @@ -346,21 +391,37 @@ virNetlinkEventServiceStart(void) virNetlinkEventServerLock(srv); /* Allocate a new socket and get fd */ +#ifdef HAVE_LIBNL1 srv->netlinknh = nl_handle_alloc(); +#else + srv->netlinksock = nl_socket_alloc(); +#endif +#ifdef HAVE_LIBNL1 if (!srv->netlinknh) { +#else + if (!srv->netlinksock) { +#endif virReportSystemError(errno, "%s", _("cannot allocate nlhandle for virNetlinkEvent server")); goto error_locked; } +#ifdef HAVE_LIBNL1 if (nl_connect(srv->netlinknh, NETLINK_ROUTE) < 0) { +#else + if (nl_connect(srv->netlinksock, NETLINK_ROUTE) < 0) { +#endif virReportSystemError(errno, "%s", _("cannot connect to netlink socket")); goto error_server; } +#ifdef HAVE_LIBNL1 fd = nl_socket_get_fd(srv->netlinknh); +#else + fd = nl_socket_get_fd(srv->netlinksock); +#endif if (fd < 0) { virReportSystemError(errno, @@ -368,7 +429,11 @@ virNetlinkEventServiceStart(void) goto error_server; } +#ifdef HAVE_LIBNL1 if (nl_socket_set_nonblocking(srv->netlinknh)) { +#else + if (nl_socket_set_nonblocking(srv->netlinksock)) { +#endif virReportSystemError(errno, "%s", _("cannot set netlink socket nonblocking")); goto error_server; @@ -391,8 +456,13 @@ virNetlinkEventServiceStart(void) error_server: if (ret < 0) { +#ifdef HAVE_LIBNL1 nl_close(srv->netlinknh); nl_handle_destroy(srv->netlinknh); +#else + nl_close(srv->netlinksock); + nl_socket_free(srv->netlinksock); +#endif } error_locked: virNetlinkEventServerUnlock(srv); -- 1.7.9.5

On 04/30/2012 06:59 PM, Serge Hallyn wrote:
configure.ac: Check for libnl-3. If found, find libnl-route-3. If not found, do the original check to look for libnl-1.
[...]
--- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -67,7 +67,11 @@ struct _virNetlinkEventSrvPrivate { virMutex lock; int eventwatch; int netlinkfd; +#ifdef HAVE_LIBNL1 struct nl_handle *netlinknh; +#else + struct nl_sock *netlinksock; +#endif
Since the two members are treated similarly, could you give these structure members the same name and with that we could get rid of a couple of the #ifdef's below. I suppose the major change between v1 and v3 that we are touching upon here is that of nl_handle to nl_sock.
/*Events*/ int handled; size_t handlesCount; @@ -121,15 +125,31 @@ int virNetlinkCommand(struct nl_msg *nl_msg, int fd; int n; struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg); +#ifdef HAVE_LIBNL1 struct nl_handle *nlhandle = nl_handle_alloc(); +#else + struct nl_sock *nlsock = nl_socket_alloc(); +#endif
Also same name here.
+#ifdef HAVE_LIBNL1 if (!nlhandle) { +#else + if (!nlsock) { +#endif
This could then be just one test.
virReportSystemError(errno, +#ifdef HAVE_LIBNL1 "%s", _("cannot allocate nlhandle for netlink")); +#else + "%s", _("cannot allocate nlsock for netlink")); +#endif return -1; }
+#ifdef HAVE_LIBNL1 if (nl_connect(nlhandle, NETLINK_ROUTE)< 0) { +#else + if (nl_connect(nlsock, NETLINK_ROUTE)< 0) { +#endif
... this one also ...
virReportSystemError(errno, "%s", _("cannot connect to netlink socket")); rc = -1; @@ -140,7 +160,11 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
nlmsg->nlmsg_pid = getpid();
+#ifdef HAVE_LIBNL1 nbytes = nl_send_auto_complete(nlhandle, nl_msg); +#else + nbytes = nl_send_auto_complete(nlsock, nl_msg); +#endif
as well as this function call and from what I can see pretty much all of the rest too except for the destroy/free calls. Regards, Stefan

Quoting Stefan Berger (stefanb@linux.vnet.ibm.com):
On 04/30/2012 06:59 PM, Serge Hallyn wrote:
configure.ac: Check for libnl-3. If found, find libnl-route-3. If not found, do the original check to look for libnl-1.
[...]
--- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -67,7 +67,11 @@ struct _virNetlinkEventSrvPrivate { virMutex lock; int eventwatch; int netlinkfd; +#ifdef HAVE_LIBNL1 struct nl_handle *netlinknh; +#else + struct nl_sock *netlinksock; +#endif
Since the two members are treated similarly, could you give these structure members the same name and with that we could get rid of a couple of the #ifdef's below. I suppose the major change between v1 and v3 that we are touching upon here is that of nl_handle to nl_sock.
I could - that's what I was referring to later in the commit message. I would worry that it would over time not be robust, and would get all the more confusing if it needed to be unwound at some point. But, while I think it would be short-sighted to do this just to shorten the patch, it would also make the flow of the rest of the code cleaner, so it may be worth it. For that matter, with a simple wrapper function or two we should be able to hide the remaining ifdefs, if that's what you'd like.
/*Events*/ int handled; size_t handlesCount; @@ -121,15 +125,31 @@ int virNetlinkCommand(struct nl_msg *nl_msg, int fd; int n; struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg); +#ifdef HAVE_LIBNL1 struct nl_handle *nlhandle = nl_handle_alloc(); +#else + struct nl_sock *nlsock = nl_socket_alloc(); +#endif
Also same name here.
+#ifdef HAVE_LIBNL1 if (!nlhandle) { +#else + if (!nlsock) { +#endif
This could then be just one test.
virReportSystemError(errno, +#ifdef HAVE_LIBNL1 "%s", _("cannot allocate nlhandle for netlink")); +#else + "%s", _("cannot allocate nlsock for netlink")); +#endif return -1; }
+#ifdef HAVE_LIBNL1 if (nl_connect(nlhandle, NETLINK_ROUTE)< 0) { +#else + if (nl_connect(nlsock, NETLINK_ROUTE)< 0) { +#endif
... this one also ...
virReportSystemError(errno, "%s", _("cannot connect to netlink socket")); rc = -1; @@ -140,7 +160,11 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
nlmsg->nlmsg_pid = getpid();
+#ifdef HAVE_LIBNL1 nbytes = nl_send_auto_complete(nlhandle, nl_msg); +#else + nbytes = nl_send_auto_complete(nlsock, nl_msg); +#endif
as well as this function call and from what I can see pretty much all of the rest too except for the destroy/free calls.
Regards, Stefan

configure.ac+Makefile.am: support libnl-3 as well as libnl-1 src/util/virnetlink.c: support libnl3 api. To minimize impact on code flow with #ifdefs as requested by Stefan Berger, do some #defines at the top. Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added to a bunch of places where they weren't needed with libnl1. Stefan, in this version I may have gone too far :) if you prefer I just stick to using 'struct nl_socket nlhandle' and leave the rest with explicit #ifdefs, let me know. But this version leaves the original code flow unencumbered by ifdefs and easier to read and vet. Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> --- configure.ac | 24 +++++++++++++++++------- daemon/Makefile.am | 5 ++++- src/Makefile.am | 25 +++++++++++++++++-------- src/util/virnetlink.c | 22 ++++++++++++++++------ 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/configure.ac b/configure.ac index a819898..ab40e1d 100644 --- a/configure.ac +++ b/configure.ac @@ -2626,19 +2626,29 @@ AM_CONDITIONAL([WITH_VIRTUALPORT], [test "$with_virtualport" = "yes"]) dnl netlink library +LIBNL_ROUTE3_CFLAGS="" +LIBNL_ROUTE3_LIBS="" LIBNL_CFLAGS="" LIBNL_LIBS="" have_libnl=no if test "$with_linux" = "yes"; then - PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + PKG_CHECK_MODULES([LIBNL],[libnl-3.0],[ have_libnl=yes - AC_DEFINE_UNQUOTED([HAVE_LIBNL], 1, [whether the netlink library is available]) - ], [ - if test "$with_macvtap" = "yes"; then - AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) - fi - ]) + AC_DEFINE([HAVE_LIBNL3], [1], [Use libnl-3.0]) + AC_DEFINE([HAVE_LIBNL], [1], [whether the netlink library is available]) + PKG_CHECK_MODULES([LIBNL_ROUTE3],[libnl-route-3.0]) + ], + PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + have_libnl=yes + AC_DEFINE_UNQUOTED([HAVE_LIBNL], 1, [whether the netlink library is available]) + AC_DEFINE_UNQUOTED([HAVE_LIBNL1], 1, [whether the netlink v1 library is available]) + ], [ + if test "$with_macvtap" = "yes"; then + AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) + fi + ]) + ) fi AM_CONDITIONAL([HAVE_LIBNL], [test "$have_libnl" = "yes"]) diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 24cce8f..8074803 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -95,6 +95,7 @@ libvirtd_SOURCES = $(DAEMON_SOURCES) libvirtd_CFLAGS = \ $(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) $(SASL_CFLAGS) \ $(XDR_CFLAGS) $(POLKIT_CFLAGS) $(DBUS_CFLAGS) \ + $(LIBNL_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) \ $(WARN_CFLAGS) \ $(COVERAGE_CFLAGS) \ -DQEMUD_PID_FILE="\"$(QEMUD_PID_FILE)\"" \ @@ -109,7 +110,9 @@ libvirtd_LDADD = \ $(GNUTLS_LIBS) \ $(SASL_LIBS) \ $(DBUS_LIBS) \ - $(POLKIT_LIBS) + $(POLKIT_LIBS) \ + $(LIBNL_LIBS) \ + $(LIBNL_ROUTE3_LIBS) if WITH_DTRACE_PROBES libvirtd_LDADD += ../src/probes.o diff --git a/src/Makefile.am b/src/Makefile.am index e48dfa5..c159c1e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -576,10 +576,10 @@ libvirt_util_la_SOURCES = \ $(UTIL_SOURCES) libvirt_util_la_CFLAGS = $(CAPNG_CFLAGS) $(YAJL_CFLAGS) $(LIBNL_CFLAGS) \ $(AM_CFLAGS) $(AUDIT_CFLAGS) $(DEVMAPPER_CFLAGS) \ - $(DBUS_CFLAGS) + $(DBUS_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) libvirt_util_la_LIBADD = $(CAPNG_LIBS) $(YAJL_LIBS) $(LIBNL_LIBS) \ $(THREAD_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \ - $(RT_LIBS) $(DBUS_LIBS) + $(RT_LIBS) $(DBUS_LIBS) $(LIBNL_ROUTE3_LIBS) noinst_LTLIBRARIES += libvirt_conf.la @@ -809,12 +809,16 @@ endif libvirt_driver_qemu_la_CFLAGS = $(NUMACTL_CFLAGS) \ $(GNUTLS_CFLAGS) \ $(LIBXML_CFLAGS) \ + $(LIBNL_CFLAGS) \ + $(LIBNL_ROUTE3_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_qemu_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_qemu_la_LIBADD = $(NUMACTL_LIBS) \ $(CAPNG_LIBS) \ $(GNUTLS_LIBS) \ - $(LIBXML_LIBS) + $(LIBXML_LIBS) \ + $(LIBNL_LIBS) \ + $(LIBNL_ROUTE3_LIBS) if WITH_DRIVER_MODULES libvirt_driver_qemu_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_qemu_la_LDFLAGS += -module -avoid-version @@ -840,8 +844,9 @@ noinst_LTLIBRARIES += libvirt_driver_lxc.la #libvirt_la_BUILT_LIBADD += libvirt_driver_lxc.la endif libvirt_driver_lxc_la_CFLAGS = \ + $(LIBNL_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) -libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) +libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS) $(LIBNL_ROUTE3_LIBS) if WITH_SECDRIVER_SELINUX libvirt_driver_lxc_la_LIBADD += $(SELINUX_LIBS) endif @@ -941,9 +946,10 @@ noinst_LTLIBRARIES += libvirt_driver_network.la #libvirt_la_BUILT_LIBADD += libvirt_driver_network.la endif libvirt_driver_network_la_CFLAGS = \ + $(LIBNL_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) if WITH_DRIVER_MODULES -libvirt_driver_network_la_LIBADD = ../gnulib/lib/libgnu.la +libvirt_driver_network_la_LIBADD = ../gnulib/lib/libgnu.la $(LIBNL_LIBS) $(LIBNL_ROUTE3_LIBS) libvirt_driver_network_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) endif libvirt_driver_network_la_SOURCES = $(NETWORK_DRIVER_SOURCES) @@ -1086,9 +1092,10 @@ libvirt_la_BUILT_LIBADD += libvirt_driver_nwfilter.la noinst_LTLIBRARIES += libvirt_driver_nwfilter.la endif libvirt_driver_nwfilter_la_CFLAGS = $(LIBPCAP_CFLAGS) \ - -I$(top_srcdir)/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(LIBNL_CFLAGS) \ + $(LIBNL_ROUTE3_CFLAGS) $(AM_CFLAGS) libvirt_driver_nwfilter_la_LDFLAGS = $(LD_AMFLAGS) -libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) +libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) $(LIBNL_LIBS) $(LIBNL_ROUTE3_LIBS) if WITH_DRIVER_MODULES libvirt_driver_nwfilter_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_nwfilter_la_LDFLAGS += -module -avoid-version @@ -1522,7 +1529,7 @@ libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(AM_LDFLAGS) libvirt_lxc_LDADD = $(CAPNG_LIBS) $(YAJL_LIBS) \ $(LIBXML_LIBS) $(NUMACTL_LIBS) $(THREAD_LIBS) \ $(LIBNL_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \ - $(RT_LIBS) $(DBUS_LIBS) \ + $(RT_LIBS) $(DBUS_LIBS) $(LIBNL_ROUTE3_LIBS) \ ../gnulib/lib/libgnu.la if WITH_DTRACE_PROBES libvirt_lxc_LDADD += probes.o @@ -1540,6 +1547,8 @@ libvirt_lxc_CFLAGS = \ $(YAJL_CFLAGS) \ $(AUDIT_CFLAGS) \ $(DBUS_CFLAGS) \ + $(LIBNL_CFLAGS) \ + $(LIBNL_ROUTE3_CFLAGS) \ -I$(top_srcdir)/src/conf \ $(AM_CFLAGS) if HAVE_LIBBLKID diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index b2e9d51..596a917 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -60,6 +60,16 @@ struct virNetlinkEventHandle { int deleted; }; +#ifdef HAVE_LIBNL1 +#define nl_alloc nl_handle_alloc +#define nl_free nl_handle_destroy +typedef struct nl_handle nlhandle_t; +#else +#define nl_alloc nl_socket_alloc +#define nl_free nl_socket_free +typedef struct nl_sock nlhandle_t; +#endif + typedef struct _virNetlinkEventSrvPrivate virNetlinkEventSrvPrivate; typedef virNetlinkEventSrvPrivate *virNetlinkEventSrvPrivatePtr; struct _virNetlinkEventSrvPrivate { @@ -67,7 +77,7 @@ struct _virNetlinkEventSrvPrivate { virMutex lock; int eventwatch; int netlinkfd; - struct nl_handle *netlinknh; + nlhandle_t *netlinknh; /*Events*/ int handled; size_t handlesCount; @@ -121,7 +131,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg, int fd; int n; struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg); - struct nl_handle *nlhandle = nl_handle_alloc(); + nlhandle_t *nlhandle = nl_alloc(); if (!nlhandle) { virReportSystemError(errno, @@ -178,7 +188,7 @@ error: *respbuflen = 0; } - nl_handle_destroy(nlhandle); + nl_free(nlhandle); return rc; } @@ -285,7 +295,7 @@ virNetlinkEventServiceStop(void) virNetlinkEventServerLock(srv); nl_close(srv->netlinknh); - nl_handle_destroy(srv->netlinknh); + nl_free(srv->netlinknh); virEventRemoveHandle(srv->eventwatch); /* free any remaining clients on the list */ @@ -346,7 +356,7 @@ virNetlinkEventServiceStart(void) virNetlinkEventServerLock(srv); /* Allocate a new socket and get fd */ - srv->netlinknh = nl_handle_alloc(); + srv->netlinknh = nl_alloc(); if (!srv->netlinknh) { virReportSystemError(errno, @@ -392,7 +402,7 @@ virNetlinkEventServiceStart(void) error_server: if (ret < 0) { nl_close(srv->netlinknh); - nl_handle_destroy(srv->netlinknh); + nl_free(srv->netlinknh); } error_locked: virNetlinkEventServerUnlock(srv); -- 1.7.9.5

On 05/03/2012 12:10 PM, Serge Hallyn wrote:
configure.ac+Makefile.am: support libnl-3 as well as libnl-1
src/util/virnetlink.c: support libnl3 api. To minimize impact on code flow with #ifdefs as requested by Stefan Berger, do some #defines at the top.
Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added to a bunch of places where they weren't needed with libnl1.
Stefan, in this version I may have gone too far :) if you prefer I just stick to using 'struct nl_socket nlhandle' and leave the rest with explicit #ifdefs, let me know. But this version leaves the original code flow unencumbered by ifdefs and easier to read and vet.
Signed-off-by: Serge Hallyn<serge.hallyn@canonical.com>
--- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -60,6 +60,16 @@ struct virNetlinkEventHandle { int deleted; };
+#ifdef HAVE_LIBNL1 +#define nl_alloc nl_handle_alloc +#define nl_free nl_handle_destroy +typedef struct nl_handle nlhandle_t; +#else +#define nl_alloc nl_socket_alloc +#define nl_free nl_socket_free +typedef struct nl_sock nlhandle_t; +#endif +
I would not #define in the namespace of that library (nl_*). What about the following: #ifdef HAVE_LIBNL1 static struct nl_handle * virNLHandleAlloc(void) { return nl_handle_alloc(); } static void virNWHandleDestroy(struct nl_handle *h) { nl_handle_destroy(h); } #else static struct nl_sock * virNLHandleAlloc(void) { return nl_socket_alloc(); } static void virNWHandleDestroy(struct nl_sock *h) { nl_socket_free(h); } #endif Regards, Stefan

On 05/03/2012 11:55 AM, Stefan Berger wrote:
+#ifdef HAVE_LIBNL1 +#define nl_alloc nl_handle_alloc +#define nl_free nl_handle_destroy +typedef struct nl_handle nlhandle_t; +#else +#define nl_alloc nl_socket_alloc +#define nl_free nl_socket_free +typedef struct nl_sock nlhandle_t; +#endif +
I would not #define in the namespace of that library (nl_*).
Agreed that a vir* namespace is safer.
What about the following:
#ifdef HAVE_LIBNL1
static struct nl_handle * virNLHandleAlloc(void) { return nl_handle_alloc(); }
One further: typedef struct nl_handle virNLHandle; static virNLHandle * virNLHandleAlloc(void) ... so that the rest of the code is indeed isolated into virNL wrappers with no additional #ifdefs. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Quoting Eric Blake (eblake@redhat.com):
On 05/03/2012 11:55 AM, Stefan Berger wrote:
+#ifdef HAVE_LIBNL1 +#define nl_alloc nl_handle_alloc +#define nl_free nl_handle_destroy +typedef struct nl_handle nlhandle_t; +#else +#define nl_alloc nl_socket_alloc +#define nl_free nl_socket_free +typedef struct nl_sock nlhandle_t; +#endif +
I would not #define in the namespace of that library (nl_*).
Agreed that a vir* namespace is safer.
What about the following:
#ifdef HAVE_LIBNL1
static struct nl_handle * virNLHandleAlloc(void) { return nl_handle_alloc(); }
One further:
typedef struct nl_handle virNLHandle;
static virNLHandle * virNLHandleAlloc(void) ...
so that the rest of the code is indeed isolated into virNL wrappers with no additional #ifdefs.
Yup, I like it, thanks guys. I don't know whether I'll have time to send a new patch tomorrow. If not I'll aim to write one over the weekend, but if someone else wants to make the (somewhat trivial) updates I won't feel upstaged :) thanks, -serge

From: Serge Hallyn <serge.hallyn@canonical.com> configure.ac: check for libnl-3 in addition to libnl-1 src/Makefile.am: link against libnl when needed src/util/virnetlink.c: support libnl3 api. To minimize impact on code flow, wrap the differences under the virNetlink* namespace. Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added to a bunch of places where they weren't needed with libnl1. Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> Signed-off-by: Eric Blake <eblake@redhat.com> --- So far, I've tested under libnl-1 on Fedora 16. I'm also firing up my Ubuntu VM and upgrading it to 12.04, if I can reproduce the build failure pre-patch and a successful build post-patch, then I will push this under the build-breaker rule. Or I will push it if I get a positive review in the meantime. configure.ac | 25 +++++++++++++++++++------ src/Makefile.am | 15 ++++++++++----- src/util/virnetlink.c | 24 +++++++++++++++++------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index a819898..30eff91 100644 --- a/configure.ac +++ b/configure.ac @@ -2626,18 +2626,31 @@ AM_CONDITIONAL([WITH_VIRTUALPORT], [test "$with_virtualport" = "yes"]) dnl netlink library +LIBNL_ROUTE3_CFLAGS="" +LIBNL_ROUTE3_LIBS="" LIBNL_CFLAGS="" LIBNL_LIBS="" have_libnl=no if test "$with_linux" = "yes"; then - PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + PKG_CHECK_MODULES([LIBNL], [libnl-3.0], [ have_libnl=yes - AC_DEFINE_UNQUOTED([HAVE_LIBNL], 1, [whether the netlink library is available]) - ], [ - if test "$with_macvtap" = "yes"; then - AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) - fi + AC_DEFINE([HAVE_LIBNL3], [1], [Use libnl-3.0]) + AC_DEFINE([HAVE_LIBNL], [1], [whether the netlink library is available]) + PKG_CHECK_MODULES([LIBNL_ROUTE3], [libnl-route-3.0]) + LIBNL_CFLAGS="$LIBNL_CFLAGS $LIBNL_ROUTE3_CFLAGS" + LIBNL_LIBS="$LIBNL_LIBS $LIBNL_ROUTE3_LIBS" + ], [PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + have_libnl=yes + AC_DEFINE_UNQUOTED([HAVE_LIBNL], [1], + [whether the netlink library is available]) + AC_DEFINE_UNQUOTED([HAVE_LIBNL1], [1], + [whether the netlink v1 library is available]) + ], [ + if test "$with_macvtap" = "yes"; then + AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) + fi + ]) ]) fi AM_CONDITIONAL([HAVE_LIBNL], [test "$have_libnl" = "yes"]) diff --git a/src/Makefile.am b/src/Makefile.am index e48dfa5..0dadc29 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -809,12 +809,14 @@ endif libvirt_driver_qemu_la_CFLAGS = $(NUMACTL_CFLAGS) \ $(GNUTLS_CFLAGS) \ $(LIBXML_CFLAGS) \ + $(LIBNL_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_qemu_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_qemu_la_LIBADD = $(NUMACTL_LIBS) \ $(CAPNG_LIBS) \ $(GNUTLS_LIBS) \ - $(LIBXML_LIBS) + $(LIBXML_LIBS) \ + $(LIBNL_LIBS) if WITH_DRIVER_MODULES libvirt_driver_qemu_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_qemu_la_LDFLAGS += -module -avoid-version @@ -840,8 +842,9 @@ noinst_LTLIBRARIES += libvirt_driver_lxc.la #libvirt_la_BUILT_LIBADD += libvirt_driver_lxc.la endif libvirt_driver_lxc_la_CFLAGS = \ + $(LIBNL_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) -libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) +libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS) if WITH_SECDRIVER_SELINUX libvirt_driver_lxc_la_LIBADD += $(SELINUX_LIBS) endif @@ -941,9 +944,10 @@ noinst_LTLIBRARIES += libvirt_driver_network.la #libvirt_la_BUILT_LIBADD += libvirt_driver_network.la endif libvirt_driver_network_la_CFLAGS = \ + $(LIBNL_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) if WITH_DRIVER_MODULES -libvirt_driver_network_la_LIBADD = ../gnulib/lib/libgnu.la +libvirt_driver_network_la_LIBADD = ../gnulib/lib/libgnu.la $(LIBNL_LIBS) libvirt_driver_network_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) endif libvirt_driver_network_la_SOURCES = $(NETWORK_DRIVER_SOURCES) @@ -1086,9 +1090,9 @@ libvirt_la_BUILT_LIBADD += libvirt_driver_nwfilter.la noinst_LTLIBRARIES += libvirt_driver_nwfilter.la endif libvirt_driver_nwfilter_la_CFLAGS = $(LIBPCAP_CFLAGS) \ - -I$(top_srcdir)/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(LIBNL_CFLAGS) $(AM_CFLAGS) libvirt_driver_nwfilter_la_LDFLAGS = $(LD_AMFLAGS) -libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) +libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) $(LIBNL_LIBS) if WITH_DRIVER_MODULES libvirt_driver_nwfilter_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_nwfilter_la_LDFLAGS += -module -avoid-version @@ -1540,6 +1544,7 @@ libvirt_lxc_CFLAGS = \ $(YAJL_CFLAGS) \ $(AUDIT_CFLAGS) \ $(DBUS_CFLAGS) \ + $(LIBNL_CFLAGS) \ -I$(top_srcdir)/src/conf \ $(AM_CFLAGS) if HAVE_LIBBLKID diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index b2e9d51..74f43ac 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Red Hat, Inc. + * Copyright (C) 2010-2012 Red Hat, Inc. * Copyright (C) 2010-2012 IBM Corporation * * This library is free software; you can redistribute it and/or @@ -60,6 +60,16 @@ struct virNetlinkEventHandle { int deleted; }; +# ifdef HAVE_LIBNL1 +# define virNetlinkAlloc nl_handle_alloc +# define virNetlinkFree nl_handle_destroy +typedef struct nl_handle virNetlinkHandle; +# else +# define virNetlinkAlloc nl_socket_alloc +# define virNetlinkFree nl_socket_free +typedef struct nl_sock virNetlinkHandle; +# endif + typedef struct _virNetlinkEventSrvPrivate virNetlinkEventSrvPrivate; typedef virNetlinkEventSrvPrivate *virNetlinkEventSrvPrivatePtr; struct _virNetlinkEventSrvPrivate { @@ -67,7 +77,7 @@ struct _virNetlinkEventSrvPrivate { virMutex lock; int eventwatch; int netlinkfd; - struct nl_handle *netlinknh; + virNetlinkHandle *netlinknh; /*Events*/ int handled; size_t handlesCount; @@ -121,7 +131,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg, int fd; int n; struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg); - struct nl_handle *nlhandle = nl_handle_alloc(); + virNetlinkHandle *nlhandle = virNetlinkAlloc(); if (!nlhandle) { virReportSystemError(errno, @@ -178,7 +188,7 @@ error: *respbuflen = 0; } - nl_handle_destroy(nlhandle); + virNetlinkFree(nlhandle); return rc; } @@ -285,7 +295,7 @@ virNetlinkEventServiceStop(void) virNetlinkEventServerLock(srv); nl_close(srv->netlinknh); - nl_handle_destroy(srv->netlinknh); + virNetlinkFree(srv->netlinknh); virEventRemoveHandle(srv->eventwatch); /* free any remaining clients on the list */ @@ -346,7 +356,7 @@ virNetlinkEventServiceStart(void) virNetlinkEventServerLock(srv); /* Allocate a new socket and get fd */ - srv->netlinknh = nl_handle_alloc(); + srv->netlinknh = virNetlinkAlloc(); if (!srv->netlinknh) { virReportSystemError(errno, @@ -392,7 +402,7 @@ virNetlinkEventServiceStart(void) error_server: if (ret < 0) { nl_close(srv->netlinknh); - nl_handle_destroy(srv->netlinknh); + virNetlinkFree(srv->netlinknh); } error_locked: virNetlinkEventServerUnlock(srv); -- 1.7.7.6

On 05/03/2012 04:26 PM, Eric Blake wrote:
From: Serge Hallyn<serge.hallyn@canonical.com>
configure.ac: check for libnl-3 in addition to libnl-1
src/Makefile.am: link against libnl when needed
src/util/virnetlink.c: support libnl3 api. To minimize impact on code flow, wrap the differences under the virNetlink* namespace.
Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added to a bunch of places where they weren't needed with libnl1.
Signed-off-by: Serge Hallyn<serge.hallyn@canonical.com> Signed-off-by: Eric Blake<eblake@redhat.com> ---
ACK

On 05/03/2012 03:15 PM, Stefan Berger wrote:
On 05/03/2012 04:26 PM, Eric Blake wrote:
From: Serge Hallyn<serge.hallyn@canonical.com>
configure.ac: check for libnl-3 in addition to libnl-1
src/Makefile.am: link against libnl when needed
src/util/virnetlink.c: support libnl3 api. To minimize impact on code flow, wrap the differences under the virNetlink* namespace.
Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added to a bunch of places where they weren't needed with libnl1.
Signed-off-by: Serge Hallyn<serge.hallyn@canonical.com> Signed-off-by: Eric Blake<eblake@redhat.com> ---
ACK
Thanks; pushed. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Quoting Eric Blake (eblake@redhat.com):
On 05/03/2012 03:15 PM, Stefan Berger wrote:
On 05/03/2012 04:26 PM, Eric Blake wrote:
From: Serge Hallyn<serge.hallyn@canonical.com>
configure.ac: check for libnl-3 in addition to libnl-1
src/Makefile.am: link against libnl when needed
src/util/virnetlink.c: support libnl3 api. To minimize impact on code flow, wrap the differences under the virNetlink* namespace.
Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added to a bunch of places where they weren't needed with libnl1.
Signed-off-by: Serge Hallyn<serge.hallyn@canonical.com> Signed-off-by: Eric Blake<eblake@redhat.com> ---
ACK
Thanks; pushed.
Thanks, Eric! -serge

On 05/03/2012 10:10 AM, Serge Hallyn wrote:
configure.ac+Makefile.am: support libnl-3 as well as libnl-1
src/util/virnetlink.c: support libnl3 api. To minimize impact on code flow with #ifdefs as requested by Stefan Berger, do some #defines at the top.
Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added to a bunch of places where they weren't needed with libnl1.
if test "$with_linux" = "yes"; then - PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + PKG_CHECK_MODULES([LIBNL],[libnl-3.0],[ have_libnl=yes - AC_DEFINE_UNQUOTED([HAVE_LIBNL], 1, [whether the netlink library is available]) - ], [ - if test "$with_macvtap" = "yes"; then - AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) - fi - ]) + AC_DEFINE([HAVE_LIBNL3], [1], [Use libnl-3.0]) + AC_DEFINE([HAVE_LIBNL], [1], [whether the netlink library is available]) + PKG_CHECK_MODULES([LIBNL_ROUTE3],[libnl-route-3.0]) + ],
Need [ here...
+ PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + have_libnl=yes + AC_DEFINE_UNQUOTED([HAVE_LIBNL], 1, [whether the netlink library is available]) + AC_DEFINE_UNQUOTED([HAVE_LIBNL1], 1, [whether the netlink v1 library is available]) + ], [ + if test "$with_macvtap" = "yes"; then + AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) + fi + ])
and another ] here. (That is, when nesting one PKG_CHECK_MODULES within another, the nested version needs to be quoted.)
+ ) fi AM_CONDITIONAL([HAVE_LIBNL], [test "$have_libnl" = "yes"])
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 24cce8f..8074803 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -95,6 +95,7 @@ libvirtd_SOURCES = $(DAEMON_SOURCES) libvirtd_CFLAGS = \ $(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) $(SASL_CFLAGS) \ $(XDR_CFLAGS) $(POLKIT_CFLAGS) $(DBUS_CFLAGS) \ + $(LIBNL_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) \
I would prefer an approach that merged LIBNL_ROUTE3_CFLAGS into LIBNL_CFLAGS at configure time, so that you don't need so many Makefile.am edits.
@@ -109,7 +110,9 @@ libvirtd_LDADD = \ $(GNUTLS_LIBS) \ $(SASL_LIBS) \ $(DBUS_LIBS) \ - $(POLKIT_LIBS) + $(POLKIT_LIBS) \ + $(LIBNL_LIBS) \ + $(LIBNL_ROUTE3_LIBS)
Same for merging LIBNL_ROUTE3_LIBS into LIBNL_LIBS at configure time.
+++ b/src/util/virnetlink.c @@ -60,6 +60,16 @@ struct virNetlinkEventHandle { int deleted; };
+#ifdef HAVE_LIBNL1 +#define nl_alloc nl_handle_alloc +#define nl_free nl_handle_destroy
This fails 'make syntax-check' if you have cppi installed; you need to indent as in: #ifdef HAVE_LIBNL1 # define nl_alloc nl_handle_alloc #else ... But I do like the approach you took here. Looking forward to v3. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Eric Blake
-
Serge Hallyn
-
Stefan Berger