提交 60fb8a22 编写于 作者: S Serge Hallyn 提交者: Eric Blake

build: support libnl-3

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: NSerge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 c8982638
...@@ -2626,18 +2626,31 @@ AM_CONDITIONAL([WITH_VIRTUALPORT], [test "$with_virtualport" = "yes"]) ...@@ -2626,18 +2626,31 @@ AM_CONDITIONAL([WITH_VIRTUALPORT], [test "$with_virtualport" = "yes"])
dnl netlink library dnl netlink library
LIBNL_ROUTE3_CFLAGS=""
LIBNL_ROUTE3_LIBS=""
LIBNL_CFLAGS="" LIBNL_CFLAGS=""
LIBNL_LIBS="" LIBNL_LIBS=""
have_libnl=no have_libnl=no
if test "$with_linux" = "yes"; then if test "$with_linux" = "yes"; then
PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ PKG_CHECK_MODULES([LIBNL], [libnl-3.0], [
have_libnl=yes have_libnl=yes
AC_DEFINE_UNQUOTED([HAVE_LIBNL], 1, [whether the netlink library is available]) AC_DEFINE([HAVE_LIBNL3], [1], [Use libnl-3.0])
], [ AC_DEFINE([HAVE_LIBNL], [1], [whether the netlink library is available])
if test "$with_macvtap" = "yes"; then PKG_CHECK_MODULES([LIBNL_ROUTE3], [libnl-route-3.0])
AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) LIBNL_CFLAGS="$LIBNL_CFLAGS $LIBNL_ROUTE3_CFLAGS"
fi 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 fi
AM_CONDITIONAL([HAVE_LIBNL], [test "$have_libnl" = "yes"]) AM_CONDITIONAL([HAVE_LIBNL], [test "$have_libnl" = "yes"])
......
...@@ -809,12 +809,14 @@ endif ...@@ -809,12 +809,14 @@ endif
libvirt_driver_qemu_la_CFLAGS = $(NUMACTL_CFLAGS) \ libvirt_driver_qemu_la_CFLAGS = $(NUMACTL_CFLAGS) \
$(GNUTLS_CFLAGS) \ $(GNUTLS_CFLAGS) \
$(LIBXML_CFLAGS) \ $(LIBXML_CFLAGS) \
$(LIBNL_CFLAGS) \
-I$(top_srcdir)/src/conf $(AM_CFLAGS) -I$(top_srcdir)/src/conf $(AM_CFLAGS)
libvirt_driver_qemu_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_qemu_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_qemu_la_LIBADD = $(NUMACTL_LIBS) \ libvirt_driver_qemu_la_LIBADD = $(NUMACTL_LIBS) \
$(CAPNG_LIBS) \ $(CAPNG_LIBS) \
$(GNUTLS_LIBS) \ $(GNUTLS_LIBS) \
$(LIBXML_LIBS) $(LIBXML_LIBS) \
$(LIBNL_LIBS)
if WITH_DRIVER_MODULES if WITH_DRIVER_MODULES
libvirt_driver_qemu_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_qemu_la_LIBADD += ../gnulib/lib/libgnu.la
libvirt_driver_qemu_la_LDFLAGS += -module -avoid-version libvirt_driver_qemu_la_LDFLAGS += -module -avoid-version
...@@ -840,8 +842,9 @@ noinst_LTLIBRARIES += libvirt_driver_lxc.la ...@@ -840,8 +842,9 @@ noinst_LTLIBRARIES += libvirt_driver_lxc.la
#libvirt_la_BUILT_LIBADD += libvirt_driver_lxc.la #libvirt_la_BUILT_LIBADD += libvirt_driver_lxc.la
endif endif
libvirt_driver_lxc_la_CFLAGS = \ libvirt_driver_lxc_la_CFLAGS = \
$(LIBNL_CFLAGS) \
-I$(top_srcdir)/src/conf $(AM_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 if WITH_SECDRIVER_SELINUX
libvirt_driver_lxc_la_LIBADD += $(SELINUX_LIBS) libvirt_driver_lxc_la_LIBADD += $(SELINUX_LIBS)
endif endif
...@@ -941,9 +944,10 @@ noinst_LTLIBRARIES += libvirt_driver_network.la ...@@ -941,9 +944,10 @@ noinst_LTLIBRARIES += libvirt_driver_network.la
#libvirt_la_BUILT_LIBADD += libvirt_driver_network.la #libvirt_la_BUILT_LIBADD += libvirt_driver_network.la
endif endif
libvirt_driver_network_la_CFLAGS = \ libvirt_driver_network_la_CFLAGS = \
$(LIBNL_CFLAGS) \
-I$(top_srcdir)/src/conf $(AM_CFLAGS) -I$(top_srcdir)/src/conf $(AM_CFLAGS)
if WITH_DRIVER_MODULES 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) libvirt_driver_network_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS)
endif endif
libvirt_driver_network_la_SOURCES = $(NETWORK_DRIVER_SOURCES) libvirt_driver_network_la_SOURCES = $(NETWORK_DRIVER_SOURCES)
...@@ -1086,9 +1090,9 @@ libvirt_la_BUILT_LIBADD += libvirt_driver_nwfilter.la ...@@ -1086,9 +1090,9 @@ libvirt_la_BUILT_LIBADD += libvirt_driver_nwfilter.la
noinst_LTLIBRARIES += libvirt_driver_nwfilter.la noinst_LTLIBRARIES += libvirt_driver_nwfilter.la
endif endif
libvirt_driver_nwfilter_la_CFLAGS = $(LIBPCAP_CFLAGS) \ 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_LDFLAGS = $(LD_AMFLAGS)
libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) $(LIBNL_LIBS)
if WITH_DRIVER_MODULES if WITH_DRIVER_MODULES
libvirt_driver_nwfilter_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_nwfilter_la_LIBADD += ../gnulib/lib/libgnu.la
libvirt_driver_nwfilter_la_LDFLAGS += -module -avoid-version libvirt_driver_nwfilter_la_LDFLAGS += -module -avoid-version
...@@ -1540,6 +1544,7 @@ libvirt_lxc_CFLAGS = \ ...@@ -1540,6 +1544,7 @@ libvirt_lxc_CFLAGS = \
$(YAJL_CFLAGS) \ $(YAJL_CFLAGS) \
$(AUDIT_CFLAGS) \ $(AUDIT_CFLAGS) \
$(DBUS_CFLAGS) \ $(DBUS_CFLAGS) \
$(LIBNL_CFLAGS) \
-I$(top_srcdir)/src/conf \ -I$(top_srcdir)/src/conf \
$(AM_CFLAGS) $(AM_CFLAGS)
if HAVE_LIBBLKID if HAVE_LIBBLKID
......
/* /*
* Copyright (C) 2010-2011 Red Hat, Inc. * Copyright (C) 2010-2012 Red Hat, Inc.
* Copyright (C) 2010-2012 IBM Corporation * Copyright (C) 2010-2012 IBM Corporation
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -60,6 +60,16 @@ struct virNetlinkEventHandle { ...@@ -60,6 +60,16 @@ struct virNetlinkEventHandle {
int deleted; 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 struct _virNetlinkEventSrvPrivate virNetlinkEventSrvPrivate;
typedef virNetlinkEventSrvPrivate *virNetlinkEventSrvPrivatePtr; typedef virNetlinkEventSrvPrivate *virNetlinkEventSrvPrivatePtr;
struct _virNetlinkEventSrvPrivate { struct _virNetlinkEventSrvPrivate {
...@@ -67,7 +77,7 @@ struct _virNetlinkEventSrvPrivate { ...@@ -67,7 +77,7 @@ struct _virNetlinkEventSrvPrivate {
virMutex lock; virMutex lock;
int eventwatch; int eventwatch;
int netlinkfd; int netlinkfd;
struct nl_handle *netlinknh; virNetlinkHandle *netlinknh;
/*Events*/ /*Events*/
int handled; int handled;
size_t handlesCount; size_t handlesCount;
...@@ -121,7 +131,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg, ...@@ -121,7 +131,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
int fd; int fd;
int n; int n;
struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg); struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg);
struct nl_handle *nlhandle = nl_handle_alloc(); virNetlinkHandle *nlhandle = virNetlinkAlloc();
if (!nlhandle) { if (!nlhandle) {
virReportSystemError(errno, virReportSystemError(errno,
...@@ -178,7 +188,7 @@ error: ...@@ -178,7 +188,7 @@ error:
*respbuflen = 0; *respbuflen = 0;
} }
nl_handle_destroy(nlhandle); virNetlinkFree(nlhandle);
return rc; return rc;
} }
...@@ -285,7 +295,7 @@ virNetlinkEventServiceStop(void) ...@@ -285,7 +295,7 @@ virNetlinkEventServiceStop(void)
virNetlinkEventServerLock(srv); virNetlinkEventServerLock(srv);
nl_close(srv->netlinknh); nl_close(srv->netlinknh);
nl_handle_destroy(srv->netlinknh); virNetlinkFree(srv->netlinknh);
virEventRemoveHandle(srv->eventwatch); virEventRemoveHandle(srv->eventwatch);
/* free any remaining clients on the list */ /* free any remaining clients on the list */
...@@ -346,7 +356,7 @@ virNetlinkEventServiceStart(void) ...@@ -346,7 +356,7 @@ virNetlinkEventServiceStart(void)
virNetlinkEventServerLock(srv); virNetlinkEventServerLock(srv);
/* Allocate a new socket and get fd */ /* Allocate a new socket and get fd */
srv->netlinknh = nl_handle_alloc(); srv->netlinknh = virNetlinkAlloc();
if (!srv->netlinknh) { if (!srv->netlinknh) {
virReportSystemError(errno, virReportSystemError(errno,
...@@ -392,7 +402,7 @@ virNetlinkEventServiceStart(void) ...@@ -392,7 +402,7 @@ virNetlinkEventServiceStart(void)
error_server: error_server:
if (ret < 0) { if (ret < 0) {
nl_close(srv->netlinknh); nl_close(srv->netlinknh);
nl_handle_destroy(srv->netlinknh); virNetlinkFree(srv->netlinknh);
} }
error_locked: error_locked:
virNetlinkEventServerUnlock(srv); virNetlinkEventServerUnlock(srv);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册