# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1214822350 -3600
# Node ID 51b392ab1912e00d11fe5373ddf8dd2c1d2ae612
# Parent 81d47e75ce1ab8e9c1f5924773c18d36de29f632
blktap: Fall back to libcrypto if libgcrypt is not installed.
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
tools/blktap/drivers/Makefile | 10 ++++++++-
tools/blktap/drivers/block-qcow.c | 40 +++++++++++++++++++++++++++++++++++++-
tools/blktap/drivers/check_gcrypt | 14 +++++++++++++
3 files changed, 62 insertions(+), 2 deletions(-)
diff -r 81d47e75ce1a -r 51b392ab1912 tools/blktap/drivers/Makefile
--- a/tools/blktap/drivers/Makefile Mon Jun 30 10:02:21 2008 +0100
+++ b/tools/blktap/drivers/Makefile Mon Jun 30 11:39:10 2008 +0100
@@ -17,8 +17,16 @@ CFLAGS += -Wp,-MD,.$(@F).d
CFLAGS += -Wp,-MD,.$(@F).d
DEPS = .*.d
+ifeq ($(shell . ./check_gcrypt),"yes")
+CFLAGS += -DUSE_GCRYPT
+CRYPT_LIB := -lgcrypt
+else
+CRYPT_LIB := -lcrypto
+$(warning *** libgcrypt not installed: falling back to libcrypto ***)
+endif
+
LDFLAGS_blktapctrl := $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenstore) -L../lib
-lblktap
-LDFLAGS_img := $(LIBAIO_DIR)/libaio.a -lgcrypt -lpthread -lz
+LDFLAGS_img := $(LIBAIO_DIR)/libaio.a $(CRYPT_LIB) -lpthread -lz
BLK-OBJS-y := block-aio.o
BLK-OBJS-y += block-sync.o
diff -r 81d47e75ce1a -r 51b392ab1912 tools/blktap/drivers/block-qcow.c
--- a/tools/blktap/drivers/block-qcow.c Mon Jun 30 10:02:21 2008 +0100
+++ b/tools/blktap/drivers/block-qcow.c Mon Jun 30 11:39:10 2008 +0100
@@ -33,7 +33,6 @@
#include <zlib.h>
#include <inttypes.h>
#include <libaio.h>
-#include <gcrypt.h>
#include "bswap.h"
#include "aes.h"
#include "tapdisk.h"
@@ -146,6 +145,10 @@ struct tdqcow_state {
static int decompress_cluster(struct tdqcow_state *s, uint64_t cluster_offset);
+#ifdef USE_GCRYPT
+
+#include <gcrypt.h>
+
static uint32_t gen_cksum(char *ptr, int len)
{
int i;
@@ -166,6 +169,41 @@ static uint32_t gen_cksum(char *ptr, int
return md[0];
}
+
+#else /* use libcrypto */
+
+#include <openssl/md5.h>
+
+static uint32_t gen_cksum(char *ptr, int len)
+{
+ int i;
+ unsigned char *md;
+ uint32_t ret;
+
+ md = malloc(MD5_DIGEST_LENGTH);
+ if(!md) return 0;
+
+ /* Convert L1 table to big endian */
+ for(i = 0; i < len / sizeof(uint64_t); i++) {
+ cpu_to_be64s(&((uint64_t*) ptr)[i]);
+ }
+
+ /* Generate checksum */
+ if (MD5((unsigned char *)ptr, len, md) != md)
+ ret = 0;
+ else
+ memcpy(&ret, md, sizeof(uint32_t));
+
+ /* Convert L1 table back to native endianess */
+ for(i = 0; i < len / sizeof(uint64_t); i++) {
+ be64_to_cpus(&((uint64_t*) ptr)[i]);
+ }
+
+ free(md);
+ return ret;
+}
+
+#endif
static int get_filesize(char *filename, uint64_t *size, struct stat *st)
{
diff -r 81d47e75ce1a -r 51b392ab1912 tools/blktap/drivers/check_gcrypt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap/drivers/check_gcrypt Mon Jun 30 11:39:10 2008 +0100
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+cat > .gcrypt.c << EOF
+#include <gcrypt.h>
+int main(void) { return 0; }
+EOF
+
+if $1 -o .gcrypt .gcrypt.c -lgcrypt 2>/dev/null ; then
+ echo "yes"
+else
+ echo "no"
+fi
+
+rm -f .gcrypt*
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|