From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNfe6-0005h1-JY for qemu-devel@nongnu.org; Thu, 04 Apr 2013 04:35:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UNfe0-0005bm-52 for qemu-devel@nongnu.org; Thu, 04 Apr 2013 04:35:46 -0400 Received: from mail.hq.newdream.net ([66.33.206.127]:46897) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNfdz-0005bc-V1 for qemu-devel@nongnu.org; Thu, 04 Apr 2013 04:35:40 -0400 From: Josh Durgin Date: Thu, 4 Apr 2013 01:35:15 -0700 Message-Id: <1365064515-23222-2-git-send-email-josh.durgin@inktank.com> In-Reply-To: <1365064515-23222-1-git-send-email-josh.durgin@inktank.com> References: <1365064515-23222-1-git-send-email-josh.durgin@inktank.com> In-Reply-To: <20130402141042.GL2341@dhcp-200-207.str.redhat.com> References: <20130402141042.GL2341@dhcp-200-207.str.redhat.com> Subject: [Qemu-devel] [PATCH 2/2] rbd: disable unsupported librbd functions at runtime List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi QEMU may be compiled against a newer version of librbd, but run and dynamically linked with an older version that does not support these functions. Declare them as weak symbols so they can be checked for existence at runtime. Only rbd_aio_discard, rbd_aio_flush, and rbd_flush were added after the initial version of librbd, so only they need to be checked. Signed-off-by: Josh Durgin --- block/rbd.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/block/rbd.c b/block/rbd.c index 037d82b..69a339a 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -44,6 +44,15 @@ * leading "\". */ +/* + * Treat newer librbd functions as weak symbols so we can detect + * whether they're supported at runtime, and disable their use + * if they aren't available. + */ +#pragma weak rbd_aio_discard +#pragma weak rbd_aio_flush +#pragma weak rbd_flush + /* rbd_aio_discard added in 0.1.2 */ #if LIBRBD_VERSION_CODE >= LIBRBD_VERSION(0, 1, 2) #define LIBRBD_SUPPORTS_DISCARD @@ -970,6 +979,7 @@ static BlockDriver bdrv_rbd = { .bdrv_aio_readv = qemu_rbd_aio_readv, .bdrv_aio_writev = qemu_rbd_aio_writev, + /* select which of these to use at runtime in bdrv_rbd_init */ .bdrv_aio_flush = qemu_rbd_aio_flush, .bdrv_co_flush_to_disk = qemu_rbd_co_flush, @@ -985,6 +995,15 @@ static BlockDriver bdrv_rbd = { static void bdrv_rbd_init(void) { + if (!rbd_flush || rbd_aio_flush) { + bdrv_rbd.bdrv_co_flush_to_disk = NULL; + } + if (!rbd_aio_flush) { + bdrv_rbd.bdrv_aio_flush = NULL; + } + if (!rbd_aio_discard) { + bdrv_rbd.bdrv_aio_discard = NULL; + } bdrv_register(&bdrv_rbd); } -- 1.7.9.5