Patchwork [V12,4/7] libqblock build system

login
register
mail settings
Submitter Wayne Xia
Date Nov. 28, 2012, 8:55 a.m.
Message ID <1354092935-6508-5-git-send-email-xiawenc@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/202401/
State New
Headers show

Comments

Wayne Xia - Nov. 28, 2012, 8:55 a.m.
Libqblock was placed in new directory ./libqblock, libtool will build
dynamic library there, source files of block layer remains in ./block.
So block related source code will generate 3 sets of binary, first is old
ones used in qemu, second and third are non PIC and PIC ones in ./libqblock.
  GCC compiler flag visibility=hidden was used with special macro, to export
only symbols that was marked as PUBLIC.
  For testing, make check-libqblock will build binaries and execute it, make
clean or make check-clean will delete generated binaries.
  By default this library will be built and tested if libtool present, out of
tree building is supported.

v10:
  Use $(SRC_PATH) in install rules.
  Call install libqblock from install target in root Makefile.
  Make libqblock and check-libqblock is conditional to a configure option and
libtool now, if libtool is not present it is forced to be disabled.
  Removed unnest-vars in libqblock Makfile for that it was done in Makefile.objs.
  Picked out only needed objects files for libqblock, added stub objects in
libqblock linking.
  Use libtool to link check-libqblock.
  Removed -fPIC cc flag replacement in tests/Makefile.
  Removed seperate directory for libqblock test case.
  Added target subdir-libqblock.
  Added targets to .phony.
  Generate files at root directory instead of ./libqblock.

v11:
  Set libqblock initial string to empty instead of “yes” in configure, by default
it will be set depending on libtool’s state, fail when user set it to yes but
libtool not present.
  Removed link flag in check-libqblock linkage, use libtool to search library.
  Added libqblock-aio.c, which contains code from main-loop.c, iohandler.c
compatfd.c, removed these three files from compile and link objects.

v12:
  libqblock/libqblock-aio.c, this file is kept in this patch which will be
changed in following patch to introduce API needed by libqblock.
  tests/Makefile, Removed variable LIBQBLOCK_DIR, Renamed LTLINK_CHECK_LIBQBLOCK
to LTLINK, removed space in LTLINK command "lt LINK $(TARGET_DIR) $@".
  tests/Makefile, use only gtester option -k, to avoid silent fail for segment fault.
  libqblock/Makefile, use stubs-obj-y directly for that symbol conflict solved.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 .gitignore                    |    2 +
 Makefile                      |   25 +++++++++++++-
 configure                     |   39 +++++++++++++++++++++++
 libqblock/Makefile            |   69 +++++++++++++++++++++++++++++++++++++++++
 libqblock/libqblock-aio.c     |   62 ++++++++++++++++++++++++++++++++++++
 libqblock/libqblock.c         |    6 +++
 libqblock/libqblock.h         |    1 +
 libqblock/libqblock.pc.in     |   13 ++++++++
 tests/Makefile                |   31 +++++++++++++++++-
 tests/check-libqblock-qcow2.c |    6 +++
 10 files changed, 250 insertions(+), 4 deletions(-)
 create mode 100644 libqblock/Makefile
 create mode 100644 libqblock/libqblock-aio.c
 create mode 100644 libqblock/libqblock-error.c
 create mode 100644 libqblock/libqblock-error.h
 create mode 100644 libqblock/libqblock-types.h
 create mode 100644 libqblock/libqblock.c
 create mode 100644 libqblock/libqblock.h
 create mode 100644 libqblock/libqblock.pc.in
 create mode 100644 tests/check-libqblock-qcow2.c
Paolo Bonzini - Nov. 28, 2012, 9:26 a.m.
Ok, I'm pretty confident that v13 will be the last one. :)

Il 28/11/2012 09:55, Wenchao Xia ha scritto:
> @@ -1119,6 +1124,8 @@ echo "  --with-coroutine=BACKEND coroutine backend. Supported options:"
>  echo "                           gthread, ucontext, sigaltstack, windows"
>  echo "  --enable-glusterfs       enable GlusterFS backend"
>  echo "  --disable-glusterfs      disable GlusterFS backend"
> +echo "  --enable-libqblock       enable dynamic library libqblock"
> +echo "  --disable-libqblock      disable dynamic library libqblock"

"shared" library, not dynamic.

>  echo ""
>  echo "NOTE: The object files are built at the place where configure is launched"
>  exit 1
> @@ -2349,6 +2356,28 @@ EOF
>    fi
>  fi
>  
> +##########################################
> +# libqblock probe
> +if test "$libqblock" == "yes" ; then
> +    # if it is set to yes by user, check whether libtool exist
> +    if ! has $libtool; then
> +        echo
> +        echo "ERROR: Libqblock needs libtool, but libtool was not found."
> +        echo "Make sure libtool was installed, or disable libqblock."
> +        echo
> +        exit 1
> +    fi
> +fi
> +
> +if test "$libqblock" == "" ; then
> +    # libqblock depends on libtool, default to yes if libtool exist
> +    if ! has $libtool; then
> +        libqblock="no"
> +    else
> +        libqblock="yes"
> +    fi
> +fi
> +
>  #
>  # Check for xxxat() functions when we are building linux-user
>  # emulator.  This is done because older glibc versions don't
> @@ -3101,6 +3130,9 @@ if test "$want_tools" = "yes" ; then
>    if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
>      tools="qemu-nbd\$(EXESUF) $tools"
>    fi
> +  if test "$libqblock" = "yes" ; then
> +  tools="subdir-libqblock $tools"
> +  fi
>  fi
>  if test "$softmmu" = yes ; then
>    if test "$virtfs" != no ; then
> @@ -3235,6 +3267,7 @@ echo "build guest agent $guest_agent"
>  echo "seccomp support   $seccomp"
>  echo "coroutine backend $coroutine_backend"
>  echo "GlusterFS support $glusterfs"
> +echo "libqblock support $libqblock"
>  
>  if test "$sdl_too_old" = "yes"; then
>  echo "-> Your SDL version is too old - please upgrade to have SDL support"
> @@ -3581,6 +3614,10 @@ if test "$glusterfs" = "yes" ; then
>    echo "CONFIG_GLUSTERFS=y" >> $config_host_mak
>  fi
>  
> +if test "$libqblock" = "yes" ; then
> +  echo "CONFIG_LIBQBLOCK=y" >> $config_host_mak
> +fi
> +
>  # USB host support
>  case "$usb" in
>  linux)
> @@ -4166,12 +4203,14 @@ DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas"
>  DIRS="$DIRS roms/seabios roms/vgabios"
>  DIRS="$DIRS qapi-generated"
>  DIRS="$DIRS libcacard libcacard/libcacard libcacard/trace"
> +DIRS="$DIRS libqblock"
>  FILES="Makefile tests/Makefile tests/tcg/Makefile qdict-test-data.txt"
>  FILES="$FILES tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit"
>  FILES="$FILES tests/tcg/lm32/Makefile libcacard/Makefile"
>  FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps"
>  FILES="$FILES pc-bios/spapr-rtas/Makefile"
>  FILES="$FILES roms/seabios/Makefile roms/vgabios/Makefile"
> +FILES="$FILES libqblock/Makefile"
>  for bios_file in \
>      $source_path/pc-bios/*.bin \
>      $source_path/pc-bios/*.rom \
> diff --git a/libqblock/Makefile b/libqblock/Makefile
> new file mode 100644
> index 0000000..13f9522
> --- /dev/null
> +++ b/libqblock/Makefile
> @@ -0,0 +1,69 @@
> +###########################################################################
> +# libqblock Makefile
> +##########################################################################
> +-include ../config-host.mak
> +-include $(SRC_PATH)/rules.mak
> +-include $(SRC_PATH)/Makefile.objs
> +
> +#############################################################################
> +# Library settings
> +#############################################################################
> +# src files are in orignial path
> +$(call set-vpath, $(SRC_PATH))
> +# generated files are in ../
> +$(call set-vpath, ../)
> +
> +#library objects
> +libqblock-obj-y= libqblock/libqblock.o libqblock/libqblock-error.o libqblock/libqblock-aio.o
> +
> +extra-obj-y= qemu-timer.o qemu-tool.o
> +
> +QEMU_OBJS= $(libqblock-obj-y) $(block-obj-y) $(oslib-obj-y) $(stub-obj-y) \
> +           $(extra-obj-y)
> +QEMU_OBJS_LIB= $(patsubst %.o, %.lo, $(QEMU_OBJS))
> +
> +QEMU_CFLAGS+= -I$(SRC_PATH) -I$(SRC_PATH)/include -I../
> +#adding magic macro define for symbol hiding and exposing
> +QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
> +
> +#dependency libraries
> +LIBS+= -lz $(LIBS_TOOLS)
> +
> +#header files to be installed
> +libqblock_includedir= $(includedir)/qblock
> +libqblock_srcpath= $(SRC_PATH)/libqblock
> +libqblock-pub-headers= $(libqblock_srcpath)/libqblock.h \
> +                       $(libqblock_srcpath)/libqblock-types.h \
> +                       $(libqblock_srcpath)/libqblock-error.h
> +
> +#################################################################
> +# Runtime rules
> +#################################################################
> +.PHONY: clean all libqblock.la libqblock.pc install-libqblock
> +
> +clean:
> +	rm -f *.lo *.o *.d *.la *.pc
> +	rm -rf .libs block trace audio fsdev hw net qapi qga qom slirp ui libqblock stubs backends
> +
> +all: libqblock.la libqblock.pc
> +# Dummy command so that make thinks it has done something
> +	@true
> +
> +libqblock.la: $(QEMU_OBJS_LIB)
> +	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
> +
> +libqblock.pc: $(libqblock_srcpath)/libqblock.pc.in
> +	$(call quiet-command,sed -e 's|@LIBDIR@|$(libdir)|' \
> +		-e 's|@INCLUDEDIR@|$(libqblock_includedir)|' \
> +	    -e 's|@VERSION@|$(shell cat $(SRC_PATH)/VERSION)|' \
> +		-e 's|@PREFIX@|$(prefix)|' \
> +		< $(libqblock_srcpath)/libqblock.pc.in > libqblock.pc,\
> +	"  GEN   $@")
> +
> +install-libqblock: libqblock.la libqblock.pc
> +	$(INSTALL_DIR) "$(DESTDIR)$(libdir)"
> +	$(INSTALL_DIR) "$(DESTDIR)$(libdir)/pkgconfig"
> +	$(INSTALL_DIR) "$(DESTDIR)$(libqblock_includedir)"
> +	$(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.la "$(DESTDIR)$(libdir)"
> +	$(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.pc "$(DESTDIR)$(libdir)/pkgconfig"
> +	$(LIBTOOL) --mode=install $(INSTALL_DATA) $(libqblock-pub-headers) "$(DESTDIR)$(libqblock_includedir)"
> diff --git a/libqblock/libqblock-aio.c b/libqblock/libqblock-aio.c
> new file mode 100644
> index 0000000..935fb7f
> --- /dev/null
> +++ b/libqblock/libqblock-aio.c
> @@ -0,0 +1,62 @@
> +/*
> + * QEMU block layer library
> + *
> + * Copyright IBM, Corp. 2012
> + *
> + * Authors:
> + *  Wenchao Xia   <xiawenc@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2 or later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */
> +
> +#include <sys/syscall.h>
> +
> +#include "qemu-common.h"
> +#include "qemu-aio.h"
> +#include "main-loop.h"
> +#include "compatfd.h"
> +
> +void qemu_notify_event(void)
> +{
> +    return;
> +}
> +
> +QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
> +{
> +    return NULL;
> +}
> +
> +void qemu_aio_flush(void)
> +{
> +    return;
> +}
> +
> +bool qemu_aio_wait(void)
> +{
> +    return false;
> +}
> +
> +#ifdef CONFIG_POSIX
> +void qemu_aio_set_fd_handler(int fd,
> +                             IOHandler *io_read,
> +                             IOHandler *io_write,
> +                             AioFlushHandler *io_flush,
> +                             void *opaque)
> +{
> +    return;
> +}
> +#endif
> +
> +void qemu_aio_set_event_notifier(EventNotifier *notifier,
> +                                 EventNotifierHandler *io_read,
> +                                 AioFlushEventNotifierHandler *io_flush)
> +{
> +    return;
> +}
> +
> +bool qemu_signalfd_available(void)
> +{
> +    return false;
> +}
> diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
> new file mode 100644
> index 0000000..4c18c41
> --- /dev/null
> +++ b/libqblock/libqblock.c
> @@ -0,0 +1,6 @@
> +#include "libqblock.h"
> +
> +int libqb_test(void)
> +{
> +    return 0;
> +}
> diff --git a/libqblock/libqblock.h b/libqblock/libqblock.h
> new file mode 100644
> index 0000000..b0f9daf
> --- /dev/null
> +++ b/libqblock/libqblock.h
> @@ -0,0 +1 @@
> +__attribute__((visibility("default"))) int libqb_test(void);
> diff --git a/libqblock/libqblock.pc.in b/libqblock/libqblock.pc.in
> new file mode 100644
> index 0000000..d2a7d06
> --- /dev/null
> +++ b/libqblock/libqblock.pc.in
> @@ -0,0 +1,13 @@
> +prefix=@PREFIX@
> +exec_prefix=${prefix}
> +libdir=@LIBDIR@
> +includedir=@INCLUDEDIR@
> +
> +Name: qblock
> +Description: QEMU block layer library
> +Version: @VERSION@
> +
> +Requires:  rt gthread-2.0 glib-2.0 z curl cap-ng uuid

This is a bit problematic, because these requires should only be present
if the libraries are actually in use.

I suggest that you put

Requires: @REQUIRES@

in this file, and compute the actual requirements in the Makefile:

libqblock-requires-y = rt gthread-2.0 glib-2.0 z
libqblock-requires-$(CONFIG_CURL) += curl
libqblock-requires-$(CONFIG_LIBCAP) += cap-ng
libqblock-requires-$(CONFIG_UUID) += uuid

etc.

> +Libs: -L${libdir} -lqblock
> +Libs.private:
> +Cflags: -I${includedir}
> diff --git a/tests/Makefile b/tests/Makefile
> index fc816d0..76de5f4 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -88,6 +88,20 @@ check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)
>  qtest-obj-y = tests/libqtest.o $(oslib-obj-y) libqemustub.a
>  $(check-qtest-y): $(qtest-obj-y)
>  
> +#libqblock build rules
> +check-libqblock-$(CONFIG_LIBQBLOCK) = tests/check-libqblock-qcow2$(EXESUF)
> +
> +$(check-libqblock-y): QEMU_INCLUDES += -I$(SRC_PATH)/tests -I$(SRC_PATH)/libqblock
> +LIBQBLOCK_TEST_DIR = tests/test_images
> +LIBQBLOCK_LA = libqblock/libqblock.la
> +
> +LTLINK = $(call quiet-command, $(LIBTOOL) --mode=link --quiet --tag=CC \
> +         $(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) \
> +         -o $@ $(sort $(1)) $(LIBS), "lt LINK $(TARGET_DIR)$@")

Please move LTLINK to rules.mak.

> +$(check-libqblock-y): %$(EXESUF): %.o
> +	$(call LTLINK, $^ $(LIBQBLOCK_LA))
> +
>  .PHONY: check-help
>  check-help:
>  	@echo "Regression testing targets:"
> @@ -98,6 +112,7 @@ check-help:
>  	@echo " make check-unit           Run qobject tests"
>  	@echo " make check-block          Run block tests"
>  	@echo " make check-report.html    Generates an HTML test report"
> +	@echo " make check-libqblock      Run libqblock tests"
>  	@echo " make check-clean          Clean the tests"
>  	@echo
>  	@echo "Please note that HTML reports do not regenerate if the unit tests"
> @@ -130,6 +145,15 @@ $(patsubst %, check-report-qtest-%.xml, $(QTEST_TARGETS)): check-report-qtest-%.
>  check-report-unit.xml: $(check-unit-y)
>  	$(call quiet-command,gtester -q $(GTESTER_OPTIONS) -o $@ -m=$(SPEED) $^, "GTESTER $@")
>  
> +# gtester tests with libqblock
> +
> +# remove quite option to show error if program is terminated by seg fault, otherwise it fails silently.
> +GTESTER_OPTIONS_LIBQBLOCK:= -k

Either remove this, or apply it to all tests.  For now, I'd say please
remove this.

Also, the corresponding rules for .xml files are missing.

> +.PHONY: $(patsubst %, check-%, $(check-libqblock-y))
> +$(patsubst %, check-%, $(check-libqblock-y)): check-%: %
> +	$(call quiet-command, LIBQBLOCK_TEST_DIR=$(LIBQBLOCK_TEST_DIR) gtester $(GTESTER_OPTIONS_LIBQBLOCK) -m=$(SPEED) $*,"GTESTER $*")
> +
>  # Reports and overall runs
>  
>  check-report.xml: $(patsubst %,check-report-qtest-%.xml, $(QTEST_TARGETS)) check-report-unit.xml
> @@ -147,16 +171,19 @@ check-tests/qemu-iotests-quick.sh: tests/qemu-iotests-quick.sh qemu-img$(EXESUF)
>  
>  # Consolidated targets
>  
> -.PHONY: check-qtest check-unit check
> +.PHONY: check-qtest check-unit check check-libqblock check-clean
>  check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS))
>  check-unit: $(patsubst %,check-%, $(check-unit-y))
>  check-block: $(patsubst %,check-%, $(check-block-y))
> -check: check-unit check-qtest
> +check-libqblock: $(patsubst %,check-%, $(check-libqblock-y))
> +check: check-libqblock check-unit check-qtest
>  
>  check-clean:
>  	$(MAKE) -C tests/tcg clean
>  	rm -f $(check-unit-y)
>  	rm -f $(check-qtest-i386-y) $(check-qtest-x86_64-y) $(check-qtest-sparc64-y) $(check-qtest-sparc-y)
>  	rm -f tests/*.o
> +	rm -f $(check-libqblock-y)
> +	rm -rf $(LIBQBLOCK_TEST_DIR)
>  
>  -include $(wildcard tests/*.d)
> diff --git a/tests/check-libqblock-qcow2.c b/tests/check-libqblock-qcow2.c
> new file mode 100644
> index 0000000..50a4df3
> --- /dev/null
> +++ b/tests/check-libqblock-qcow2.c
> @@ -0,0 +1,6 @@
> +#include "libqblock.h"
> +int main(int argc, char **argv)
> +{
> +    libqb_test();
> +    return 0;
> +}
>
Wayne Xia - Nov. 29, 2012, 6:28 a.m.
于 2012-11-28 17:26, Paolo Bonzini 写道:
> Ok, I'm pretty confident that v13 will be the last one. :)
>
> Il 28/11/2012 09:55, Wenchao Xia ha scritto:
>> @@ -1119,6 +1124,8 @@ echo "  --with-coroutine=BACKEND coroutine backend. Supported options:"
>>   echo "                           gthread, ucontext, sigaltstack, windows"
>>   echo "  --enable-glusterfs       enable GlusterFS backend"
>>   echo "  --disable-glusterfs      disable GlusterFS backend"
>> +echo "  --enable-libqblock       enable dynamic library libqblock"
>> +echo "  --disable-libqblock      disable dynamic library libqblock"
>
> "shared" library, not dynamic.
>
   OK.

>>   echo ""
>>   echo "NOTE: The object files are built at the place where configure is launched"
>>   exit 1
>> @@ -2349,6 +2356,28 @@ EOF
>>     fi
>>   fi
>>
>> +##########################################
>> +# libqblock probe
>> +if test "$libqblock" == "yes" ; then
>> +    # if it is set to yes by user, check whether libtool exist
>> +    if ! has $libtool; then
>> +        echo
>> +        echo "ERROR: Libqblock needs libtool, but libtool was not found."
>> +        echo "Make sure libtool was installed, or disable libqblock."
>> +        echo
>> +        exit 1
>> +    fi
>> +fi
>> +
>> +if test "$libqblock" == "" ; then
>> +    # libqblock depends on libtool, default to yes if libtool exist
>> +    if ! has $libtool; then
>> +        libqblock="no"
>> +    else
>> +        libqblock="yes"
>> +    fi
>> +fi
>> +
>>   #
>>   # Check for xxxat() functions when we are building linux-user
>>   # emulator.  This is done because older glibc versions don't
>> @@ -3101,6 +3130,9 @@ if test "$want_tools" = "yes" ; then
>>     if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
>>       tools="qemu-nbd\$(EXESUF) $tools"
>>     fi
>> +  if test "$libqblock" = "yes" ; then
>> +  tools="subdir-libqblock $tools"
>> +  fi
>>   fi
>>   if test "$softmmu" = yes ; then
>>     if test "$virtfs" != no ; then
>> @@ -3235,6 +3267,7 @@ echo "build guest agent $guest_agent"
>>   echo "seccomp support   $seccomp"
>>   echo "coroutine backend $coroutine_backend"
>>   echo "GlusterFS support $glusterfs"
>> +echo "libqblock support $libqblock"
>>
>>   if test "$sdl_too_old" = "yes"; then
>>   echo "-> Your SDL version is too old - please upgrade to have SDL support"
>> @@ -3581,6 +3614,10 @@ if test "$glusterfs" = "yes" ; then
>>     echo "CONFIG_GLUSTERFS=y" >> $config_host_mak
>>   fi
>>
>> +if test "$libqblock" = "yes" ; then
>> +  echo "CONFIG_LIBQBLOCK=y" >> $config_host_mak
>> +fi
>> +
>>   # USB host support
>>   case "$usb" in
>>   linux)
>> @@ -4166,12 +4203,14 @@ DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas"
>>   DIRS="$DIRS roms/seabios roms/vgabios"
>>   DIRS="$DIRS qapi-generated"
>>   DIRS="$DIRS libcacard libcacard/libcacard libcacard/trace"
>> +DIRS="$DIRS libqblock"
>>   FILES="Makefile tests/Makefile tests/tcg/Makefile qdict-test-data.txt"
>>   FILES="$FILES tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit"
>>   FILES="$FILES tests/tcg/lm32/Makefile libcacard/Makefile"
>>   FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps"
>>   FILES="$FILES pc-bios/spapr-rtas/Makefile"
>>   FILES="$FILES roms/seabios/Makefile roms/vgabios/Makefile"
>> +FILES="$FILES libqblock/Makefile"
>>   for bios_file in \
>>       $source_path/pc-bios/*.bin \
>>       $source_path/pc-bios/*.rom \
>> diff --git a/libqblock/Makefile b/libqblock/Makefile
>> new file mode 100644
>> index 0000000..13f9522
>> --- /dev/null
>> +++ b/libqblock/Makefile
>> @@ -0,0 +1,69 @@
>> +###########################################################################
>> +# libqblock Makefile
>> +##########################################################################
>> +-include ../config-host.mak
>> +-include $(SRC_PATH)/rules.mak
>> +-include $(SRC_PATH)/Makefile.objs
>> +
>> +#############################################################################
>> +# Library settings
>> +#############################################################################
>> +# src files are in orignial path
>> +$(call set-vpath, $(SRC_PATH))
>> +# generated files are in ../
>> +$(call set-vpath, ../)
>> +
>> +#library objects
>> +libqblock-obj-y= libqblock/libqblock.o libqblock/libqblock-error.o libqblock/libqblock-aio.o
>> +
>> +extra-obj-y= qemu-timer.o qemu-tool.o
>> +
>> +QEMU_OBJS= $(libqblock-obj-y) $(block-obj-y) $(oslib-obj-y) $(stub-obj-y) \
>> +           $(extra-obj-y)
>> +QEMU_OBJS_LIB= $(patsubst %.o, %.lo, $(QEMU_OBJS))
>> +
>> +QEMU_CFLAGS+= -I$(SRC_PATH) -I$(SRC_PATH)/include -I../
>> +#adding magic macro define for symbol hiding and exposing
>> +QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
>> +
>> +#dependency libraries
>> +LIBS+= -lz $(LIBS_TOOLS)
>> +
>> +#header files to be installed
>> +libqblock_includedir= $(includedir)/qblock
>> +libqblock_srcpath= $(SRC_PATH)/libqblock
>> +libqblock-pub-headers= $(libqblock_srcpath)/libqblock.h \
>> +                       $(libqblock_srcpath)/libqblock-types.h \
>> +                       $(libqblock_srcpath)/libqblock-error.h
>> +
>> +#################################################################
>> +# Runtime rules
>> +#################################################################
>> +.PHONY: clean all libqblock.la libqblock.pc install-libqblock
>> +
>> +clean:
>> +	rm -f *.lo *.o *.d *.la *.pc
>> +	rm -rf .libs block trace audio fsdev hw net qapi qga qom slirp ui libqblock stubs backends
>> +
>> +all: libqblock.la libqblock.pc
>> +# Dummy command so that make thinks it has done something
>> +	@true
>> +
>> +libqblock.la: $(QEMU_OBJS_LIB)
>> +	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
>> +
>> +libqblock.pc: $(libqblock_srcpath)/libqblock.pc.in
>> +	$(call quiet-command,sed -e 's|@LIBDIR@|$(libdir)|' \
>> +		-e 's|@INCLUDEDIR@|$(libqblock_includedir)|' \
>> +	    -e 's|@VERSION@|$(shell cat $(SRC_PATH)/VERSION)|' \
>> +		-e 's|@PREFIX@|$(prefix)|' \
>> +		< $(libqblock_srcpath)/libqblock.pc.in > libqblock.pc,\
>> +	"  GEN   $@")
>> +
>> +install-libqblock: libqblock.la libqblock.pc
>> +	$(INSTALL_DIR) "$(DESTDIR)$(libdir)"
>> +	$(INSTALL_DIR) "$(DESTDIR)$(libdir)/pkgconfig"
>> +	$(INSTALL_DIR) "$(DESTDIR)$(libqblock_includedir)"
>> +	$(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.la "$(DESTDIR)$(libdir)"
>> +	$(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.pc "$(DESTDIR)$(libdir)/pkgconfig"
>> +	$(LIBTOOL) --mode=install $(INSTALL_DATA) $(libqblock-pub-headers) "$(DESTDIR)$(libqblock_includedir)"
>> diff --git a/libqblock/libqblock-aio.c b/libqblock/libqblock-aio.c
>> new file mode 100644
>> index 0000000..935fb7f
>> --- /dev/null
>> +++ b/libqblock/libqblock-aio.c
>> @@ -0,0 +1,62 @@
>> +/*
>> + * QEMU block layer library
>> + *
>> + * Copyright IBM, Corp. 2012
>> + *
>> + * Authors:
>> + *  Wenchao Xia   <xiawenc@linux.vnet.ibm.com>
>> + *
>> + * This work is licensed under the terms of the GNU LGPL, version 2 or later.
>> + * See the COPYING.LIB file in the top-level directory.
>> + *
>> + */
>> +
>> +#include <sys/syscall.h>
>> +
>> +#include "qemu-common.h"
>> +#include "qemu-aio.h"
>> +#include "main-loop.h"
>> +#include "compatfd.h"
>> +
>> +void qemu_notify_event(void)
>> +{
>> +    return;
>> +}
>> +
>> +QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
>> +{
>> +    return NULL;
>> +}
>> +
>> +void qemu_aio_flush(void)
>> +{
>> +    return;
>> +}
>> +
>> +bool qemu_aio_wait(void)
>> +{
>> +    return false;
>> +}
>> +
>> +#ifdef CONFIG_POSIX
>> +void qemu_aio_set_fd_handler(int fd,
>> +                             IOHandler *io_read,
>> +                             IOHandler *io_write,
>> +                             AioFlushHandler *io_flush,
>> +                             void *opaque)
>> +{
>> +    return;
>> +}
>> +#endif
>> +
>> +void qemu_aio_set_event_notifier(EventNotifier *notifier,
>> +                                 EventNotifierHandler *io_read,
>> +                                 AioFlushEventNotifierHandler *io_flush)
>> +{
>> +    return;
>> +}
>> +
>> +bool qemu_signalfd_available(void)
>> +{
>> +    return false;
>> +}
>> diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
>> new file mode 100644
>> index 0000000..4c18c41
>> --- /dev/null
>> +++ b/libqblock/libqblock.c
>> @@ -0,0 +1,6 @@
>> +#include "libqblock.h"
>> +
>> +int libqb_test(void)
>> +{
>> +    return 0;
>> +}
>> diff --git a/libqblock/libqblock.h b/libqblock/libqblock.h
>> new file mode 100644
>> index 0000000..b0f9daf
>> --- /dev/null
>> +++ b/libqblock/libqblock.h
>> @@ -0,0 +1 @@
>> +__attribute__((visibility("default"))) int libqb_test(void);
>> diff --git a/libqblock/libqblock.pc.in b/libqblock/libqblock.pc.in
>> new file mode 100644
>> index 0000000..d2a7d06
>> --- /dev/null
>> +++ b/libqblock/libqblock.pc.in
>> @@ -0,0 +1,13 @@
>> +prefix=@PREFIX@
>> +exec_prefix=${prefix}
>> +libdir=@LIBDIR@
>> +includedir=@INCLUDEDIR@
>> +
>> +Name: qblock
>> +Description: QEMU block layer library
>> +Version: @VERSION@
>> +
>> +Requires:  rt gthread-2.0 glib-2.0 z curl cap-ng uuid
>
> This is a bit problematic, because these requires should only be present
> if the libraries are actually in use.
>
> I suggest that you put
>
> Requires: @REQUIRES@
>
> in this file, and compute the actual requirements in the Makefile:
>
> libqblock-requires-y = rt gthread-2.0 glib-2.0 z
> libqblock-requires-$(CONFIG_CURL) += curl
> libqblock-requires-$(CONFIG_LIBCAP) += cap-ng
> libqblock-requires-$(CONFIG_UUID) += uuid
>
> etc.
>
   I'll try this way, thank u for the detailed tips.

>> +Libs: -L${libdir} -lqblock
>> +Libs.private:
>> +Cflags: -I${includedir}
>> diff --git a/tests/Makefile b/tests/Makefile
>> index fc816d0..76de5f4 100644
>> --- a/tests/Makefile
>> +++ b/tests/Makefile
>> @@ -88,6 +88,20 @@ check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)
>>   qtest-obj-y = tests/libqtest.o $(oslib-obj-y) libqemustub.a
>>   $(check-qtest-y): $(qtest-obj-y)
>>
>> +#libqblock build rules
>> +check-libqblock-$(CONFIG_LIBQBLOCK) = tests/check-libqblock-qcow2$(EXESUF)
>> +
>> +$(check-libqblock-y): QEMU_INCLUDES += -I$(SRC_PATH)/tests -I$(SRC_PATH)/libqblock
>> +LIBQBLOCK_TEST_DIR = tests/test_images
>> +LIBQBLOCK_LA = libqblock/libqblock.la
>> +
>> +LTLINK = $(call quiet-command, $(LIBTOOL) --mode=link --quiet --tag=CC \
>> +         $(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) \
>> +         -o $@ $(sort $(1)) $(LIBS), "lt LINK $(TARGET_DIR)$@")
>
> Please move LTLINK to rules.mak.
>
   OK.

>> +$(check-libqblock-y): %$(EXESUF): %.o
>> +	$(call LTLINK, $^ $(LIBQBLOCK_LA))
>> +
>>   .PHONY: check-help
>>   check-help:
>>   	@echo "Regression testing targets:"
>> @@ -98,6 +112,7 @@ check-help:
>>   	@echo " make check-unit           Run qobject tests"
>>   	@echo " make check-block          Run block tests"
>>   	@echo " make check-report.html    Generates an HTML test report"
>> +	@echo " make check-libqblock      Run libqblock tests"
>>   	@echo " make check-clean          Clean the tests"
>>   	@echo
>>   	@echo "Please note that HTML reports do not regenerate if the unit tests"
>> @@ -130,6 +145,15 @@ $(patsubst %, check-report-qtest-%.xml, $(QTEST_TARGETS)): check-report-qtest-%.
>>   check-report-unit.xml: $(check-unit-y)
>>   	$(call quiet-command,gtester -q $(GTESTER_OPTIONS) -o $@ -m=$(SPEED) $^, "GTESTER $@")
>>
>> +# gtester tests with libqblock
>> +
>> +# remove quite option to show error if program is terminated by seg fault, otherwise it fails silently.
>> +GTESTER_OPTIONS_LIBQBLOCK:= -k
>
> Either remove this, or apply it to all tests.  For now, I'd say please
> remove this.
>
> Also, the corresponding rules for .xml files are missing.
>
   OK.

>> +.PHONY: $(patsubst %, check-%, $(check-libqblock-y))
>> +$(patsubst %, check-%, $(check-libqblock-y)): check-%: %
>> +	$(call quiet-command, LIBQBLOCK_TEST_DIR=$(LIBQBLOCK_TEST_DIR) gtester $(GTESTER_OPTIONS_LIBQBLOCK) -m=$(SPEED) $*,"GTESTER $*")
>> +
>>   # Reports and overall runs
>>
>>   check-report.xml: $(patsubst %,check-report-qtest-%.xml, $(QTEST_TARGETS)) check-report-unit.xml
>> @@ -147,16 +171,19 @@ check-tests/qemu-iotests-quick.sh: tests/qemu-iotests-quick.sh qemu-img$(EXESUF)
>>
>>   # Consolidated targets
>>
>> -.PHONY: check-qtest check-unit check
>> +.PHONY: check-qtest check-unit check check-libqblock check-clean
>>   check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS))
>>   check-unit: $(patsubst %,check-%, $(check-unit-y))
>>   check-block: $(patsubst %,check-%, $(check-block-y))
>> -check: check-unit check-qtest
>> +check-libqblock: $(patsubst %,check-%, $(check-libqblock-y))
>> +check: check-libqblock check-unit check-qtest
>>
>>   check-clean:
>>   	$(MAKE) -C tests/tcg clean
>>   	rm -f $(check-unit-y)
>>   	rm -f $(check-qtest-i386-y) $(check-qtest-x86_64-y) $(check-qtest-sparc64-y) $(check-qtest-sparc-y)
>>   	rm -f tests/*.o
>> +	rm -f $(check-libqblock-y)
>> +	rm -rf $(LIBQBLOCK_TEST_DIR)
>>
>>   -include $(wildcard tests/*.d)
>> diff --git a/tests/check-libqblock-qcow2.c b/tests/check-libqblock-qcow2.c
>> new file mode 100644
>> index 0000000..50a4df3
>> --- /dev/null
>> +++ b/tests/check-libqblock-qcow2.c
>> @@ -0,0 +1,6 @@
>> +#include "libqblock.h"
>> +int main(int argc, char **argv)
>> +{
>> +    libqb_test();
>> +    return 0;
>> +}
>>
>
>

Patch

diff --git a/.gitignore b/.gitignore
index bd6ba1c..77c1910 100644
--- a/.gitignore
+++ b/.gitignore
@@ -93,3 +93,5 @@  cscope.*
 tags
 TAGS
 *~
+tests/check-libqblock-qcow2
+tests/test_images
diff --git a/Makefile b/Makefile
index b04d862..dd01fe7 100644
--- a/Makefile
+++ b/Makefile
@@ -195,6 +195,27 @@  qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) $(block-obj-y) libqemustub.a
 qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) $(block-obj-y) libqemustub.a
 qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y) libqemustub.a
 
+######################################################################
+# Support building shared library libqblock
+.PHONY: install-libqblock subdir-libqblock
+
+ifeq ($(CONFIG_LIBQBLOCK), y)
+subdir-libqblock: $(GENERATED_HEADERS) $(GENERATED_SOURCES)
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" all,)
+
+install-libqblock: subdir-libqblock
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" install-libqblock,)
+else
+LIBQBLOCK_WARN = "Libqblock was not enabled, skip. Make sure libtool was installed and libqblock was enabled."
+subdir-libqblock: $(GENERATED_HEADERS) $(GENERATED_SOURCES)
+	@echo $(LIBQBLOCK_WARN)
+
+install-libqblock:
+	@echo $(LIBQBLOCK_WARN)
+endif
+
+###########################################################################
+
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
 vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) libcacard/vscclient.o libqemustub.a
@@ -258,7 +279,7 @@  clean:
 	rm -rf qapi-generated
 	rm -rf qga/qapi-generated
 	$(MAKE) check-clean
-	for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \
+	for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard libqblock; do \
 	if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
 	rm -f $$d/qemu-options.def; \
         done
@@ -331,7 +352,7 @@  install-confdir:
 install-sysconfig: install-datadir install-confdir
 	$(INSTALL_DATA) $(SRC_PATH)/sysconfigs/target/target-x86_64.conf "$(DESTDIR)$(qemu_confdir)"
 
-install: all $(if $(BUILD_DOCS),install-doc) install-sysconfig install-datadir
+install: all $(if $(BUILD_DOCS),install-doc) install-sysconfig install-datadir $(if $(CONFIG_LIBQBLOCK),install-libqblock)
 	$(INSTALL_DIR) "$(DESTDIR)$(bindir)"
 ifneq ($(TOOLS),)
 	$(INSTALL_PROG) $(STRIP_OPT) $(TOOLS) "$(DESTDIR)$(bindir)"
diff --git a/configure b/configure
index 801585c..b0bf912 100755
--- a/configure
+++ b/configure
@@ -223,6 +223,7 @@  libiscsi=""
 coroutine=""
 seccomp=""
 glusterfs=""
+libqblock=""
 
 # parse CC options first
 for opt do
@@ -871,6 +872,10 @@  for opt do
   ;;
   --enable-glusterfs) glusterfs="yes"
   ;;
+  --disable-libqblock) libqblock="no"
+  ;;
+  --enable-libqblock) libqblock="yes"
+  ;;
   *) echo "ERROR: unknown option $opt"; show_help="yes"
   ;;
   esac
@@ -1119,6 +1124,8 @@  echo "  --with-coroutine=BACKEND coroutine backend. Supported options:"
 echo "                           gthread, ucontext, sigaltstack, windows"
 echo "  --enable-glusterfs       enable GlusterFS backend"
 echo "  --disable-glusterfs      disable GlusterFS backend"
+echo "  --enable-libqblock       enable dynamic library libqblock"
+echo "  --disable-libqblock      disable dynamic library libqblock"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
 exit 1
@@ -2349,6 +2356,28 @@  EOF
   fi
 fi
 
+##########################################
+# libqblock probe
+if test "$libqblock" == "yes" ; then
+    # if it is set to yes by user, check whether libtool exist
+    if ! has $libtool; then
+        echo
+        echo "ERROR: Libqblock needs libtool, but libtool was not found."
+        echo "Make sure libtool was installed, or disable libqblock."
+        echo
+        exit 1
+    fi
+fi
+
+if test "$libqblock" == "" ; then
+    # libqblock depends on libtool, default to yes if libtool exist
+    if ! has $libtool; then
+        libqblock="no"
+    else
+        libqblock="yes"
+    fi
+fi
+
 #
 # Check for xxxat() functions when we are building linux-user
 # emulator.  This is done because older glibc versions don't
@@ -3101,6 +3130,9 @@  if test "$want_tools" = "yes" ; then
   if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
     tools="qemu-nbd\$(EXESUF) $tools"
   fi
+  if test "$libqblock" = "yes" ; then
+  tools="subdir-libqblock $tools"
+  fi
 fi
 if test "$softmmu" = yes ; then
   if test "$virtfs" != no ; then
@@ -3235,6 +3267,7 @@  echo "build guest agent $guest_agent"
 echo "seccomp support   $seccomp"
 echo "coroutine backend $coroutine_backend"
 echo "GlusterFS support $glusterfs"
+echo "libqblock support $libqblock"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -3581,6 +3614,10 @@  if test "$glusterfs" = "yes" ; then
   echo "CONFIG_GLUSTERFS=y" >> $config_host_mak
 fi
 
+if test "$libqblock" = "yes" ; then
+  echo "CONFIG_LIBQBLOCK=y" >> $config_host_mak
+fi
+
 # USB host support
 case "$usb" in
 linux)
@@ -4166,12 +4203,14 @@  DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas"
 DIRS="$DIRS roms/seabios roms/vgabios"
 DIRS="$DIRS qapi-generated"
 DIRS="$DIRS libcacard libcacard/libcacard libcacard/trace"
+DIRS="$DIRS libqblock"
 FILES="Makefile tests/Makefile tests/tcg/Makefile qdict-test-data.txt"
 FILES="$FILES tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit"
 FILES="$FILES tests/tcg/lm32/Makefile libcacard/Makefile"
 FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps"
 FILES="$FILES pc-bios/spapr-rtas/Makefile"
 FILES="$FILES roms/seabios/Makefile roms/vgabios/Makefile"
+FILES="$FILES libqblock/Makefile"
 for bios_file in \
     $source_path/pc-bios/*.bin \
     $source_path/pc-bios/*.rom \
diff --git a/libqblock/Makefile b/libqblock/Makefile
new file mode 100644
index 0000000..13f9522
--- /dev/null
+++ b/libqblock/Makefile
@@ -0,0 +1,69 @@ 
+###########################################################################
+# libqblock Makefile
+##########################################################################
+-include ../config-host.mak
+-include $(SRC_PATH)/rules.mak
+-include $(SRC_PATH)/Makefile.objs
+
+#############################################################################
+# Library settings
+#############################################################################
+# src files are in orignial path
+$(call set-vpath, $(SRC_PATH))
+# generated files are in ../
+$(call set-vpath, ../)
+
+#library objects
+libqblock-obj-y= libqblock/libqblock.o libqblock/libqblock-error.o libqblock/libqblock-aio.o
+
+extra-obj-y= qemu-timer.o qemu-tool.o
+
+QEMU_OBJS= $(libqblock-obj-y) $(block-obj-y) $(oslib-obj-y) $(stub-obj-y) \
+           $(extra-obj-y)
+QEMU_OBJS_LIB= $(patsubst %.o, %.lo, $(QEMU_OBJS))
+
+QEMU_CFLAGS+= -I$(SRC_PATH) -I$(SRC_PATH)/include -I../
+#adding magic macro define for symbol hiding and exposing
+QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
+
+#dependency libraries
+LIBS+= -lz $(LIBS_TOOLS)
+
+#header files to be installed
+libqblock_includedir= $(includedir)/qblock
+libqblock_srcpath= $(SRC_PATH)/libqblock
+libqblock-pub-headers= $(libqblock_srcpath)/libqblock.h \
+                       $(libqblock_srcpath)/libqblock-types.h \
+                       $(libqblock_srcpath)/libqblock-error.h
+
+#################################################################
+# Runtime rules
+#################################################################
+.PHONY: clean all libqblock.la libqblock.pc install-libqblock
+
+clean:
+	rm -f *.lo *.o *.d *.la *.pc
+	rm -rf .libs block trace audio fsdev hw net qapi qga qom slirp ui libqblock stubs backends
+
+all: libqblock.la libqblock.pc
+# Dummy command so that make thinks it has done something
+	@true
+
+libqblock.la: $(QEMU_OBJS_LIB)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
+
+libqblock.pc: $(libqblock_srcpath)/libqblock.pc.in
+	$(call quiet-command,sed -e 's|@LIBDIR@|$(libdir)|' \
+		-e 's|@INCLUDEDIR@|$(libqblock_includedir)|' \
+	    -e 's|@VERSION@|$(shell cat $(SRC_PATH)/VERSION)|' \
+		-e 's|@PREFIX@|$(prefix)|' \
+		< $(libqblock_srcpath)/libqblock.pc.in > libqblock.pc,\
+	"  GEN   $@")
+
+install-libqblock: libqblock.la libqblock.pc
+	$(INSTALL_DIR) "$(DESTDIR)$(libdir)"
+	$(INSTALL_DIR) "$(DESTDIR)$(libdir)/pkgconfig"
+	$(INSTALL_DIR) "$(DESTDIR)$(libqblock_includedir)"
+	$(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.la "$(DESTDIR)$(libdir)"
+	$(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.pc "$(DESTDIR)$(libdir)/pkgconfig"
+	$(LIBTOOL) --mode=install $(INSTALL_DATA) $(libqblock-pub-headers) "$(DESTDIR)$(libqblock_includedir)"
diff --git a/libqblock/libqblock-aio.c b/libqblock/libqblock-aio.c
new file mode 100644
index 0000000..935fb7f
--- /dev/null
+++ b/libqblock/libqblock-aio.c
@@ -0,0 +1,62 @@ 
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   <xiawenc@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include <sys/syscall.h>
+
+#include "qemu-common.h"
+#include "qemu-aio.h"
+#include "main-loop.h"
+#include "compatfd.h"
+
+void qemu_notify_event(void)
+{
+    return;
+}
+
+QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
+{
+    return NULL;
+}
+
+void qemu_aio_flush(void)
+{
+    return;
+}
+
+bool qemu_aio_wait(void)
+{
+    return false;
+}
+
+#ifdef CONFIG_POSIX
+void qemu_aio_set_fd_handler(int fd,
+                             IOHandler *io_read,
+                             IOHandler *io_write,
+                             AioFlushHandler *io_flush,
+                             void *opaque)
+{
+    return;
+}
+#endif
+
+void qemu_aio_set_event_notifier(EventNotifier *notifier,
+                                 EventNotifierHandler *io_read,
+                                 AioFlushEventNotifierHandler *io_flush)
+{
+    return;
+}
+
+bool qemu_signalfd_available(void)
+{
+    return false;
+}
diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
new file mode 100644
index 0000000..4c18c41
--- /dev/null
+++ b/libqblock/libqblock.c
@@ -0,0 +1,6 @@ 
+#include "libqblock.h"
+
+int libqb_test(void)
+{
+    return 0;
+}
diff --git a/libqblock/libqblock.h b/libqblock/libqblock.h
new file mode 100644
index 0000000..b0f9daf
--- /dev/null
+++ b/libqblock/libqblock.h
@@ -0,0 +1 @@ 
+__attribute__((visibility("default"))) int libqb_test(void);
diff --git a/libqblock/libqblock.pc.in b/libqblock/libqblock.pc.in
new file mode 100644
index 0000000..d2a7d06
--- /dev/null
+++ b/libqblock/libqblock.pc.in
@@ -0,0 +1,13 @@ 
+prefix=@PREFIX@
+exec_prefix=${prefix}
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: qblock
+Description: QEMU block layer library
+Version: @VERSION@
+
+Requires:  rt gthread-2.0 glib-2.0 z curl cap-ng uuid
+Libs: -L${libdir} -lqblock
+Libs.private:
+Cflags: -I${includedir}
diff --git a/tests/Makefile b/tests/Makefile
index fc816d0..76de5f4 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -88,6 +88,20 @@  check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)
 qtest-obj-y = tests/libqtest.o $(oslib-obj-y) libqemustub.a
 $(check-qtest-y): $(qtest-obj-y)
 
+#libqblock build rules
+check-libqblock-$(CONFIG_LIBQBLOCK) = tests/check-libqblock-qcow2$(EXESUF)
+
+$(check-libqblock-y): QEMU_INCLUDES += -I$(SRC_PATH)/tests -I$(SRC_PATH)/libqblock
+LIBQBLOCK_TEST_DIR = tests/test_images
+LIBQBLOCK_LA = libqblock/libqblock.la
+
+LTLINK = $(call quiet-command, $(LIBTOOL) --mode=link --quiet --tag=CC \
+         $(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) \
+         -o $@ $(sort $(1)) $(LIBS), "lt LINK $(TARGET_DIR)$@")
+
+$(check-libqblock-y): %$(EXESUF): %.o
+	$(call LTLINK, $^ $(LIBQBLOCK_LA))
+
 .PHONY: check-help
 check-help:
 	@echo "Regression testing targets:"
@@ -98,6 +112,7 @@  check-help:
 	@echo " make check-unit           Run qobject tests"
 	@echo " make check-block          Run block tests"
 	@echo " make check-report.html    Generates an HTML test report"
+	@echo " make check-libqblock      Run libqblock tests"
 	@echo " make check-clean          Clean the tests"
 	@echo
 	@echo "Please note that HTML reports do not regenerate if the unit tests"
@@ -130,6 +145,15 @@  $(patsubst %, check-report-qtest-%.xml, $(QTEST_TARGETS)): check-report-qtest-%.
 check-report-unit.xml: $(check-unit-y)
 	$(call quiet-command,gtester -q $(GTESTER_OPTIONS) -o $@ -m=$(SPEED) $^, "GTESTER $@")
 
+# gtester tests with libqblock
+
+# remove quite option to show error if program is terminated by seg fault, otherwise it fails silently.
+GTESTER_OPTIONS_LIBQBLOCK:= -k
+
+.PHONY: $(patsubst %, check-%, $(check-libqblock-y))
+$(patsubst %, check-%, $(check-libqblock-y)): check-%: %
+	$(call quiet-command, LIBQBLOCK_TEST_DIR=$(LIBQBLOCK_TEST_DIR) gtester $(GTESTER_OPTIONS_LIBQBLOCK) -m=$(SPEED) $*,"GTESTER $*")
+
 # Reports and overall runs
 
 check-report.xml: $(patsubst %,check-report-qtest-%.xml, $(QTEST_TARGETS)) check-report-unit.xml
@@ -147,16 +171,19 @@  check-tests/qemu-iotests-quick.sh: tests/qemu-iotests-quick.sh qemu-img$(EXESUF)
 
 # Consolidated targets
 
-.PHONY: check-qtest check-unit check
+.PHONY: check-qtest check-unit check check-libqblock check-clean
 check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS))
 check-unit: $(patsubst %,check-%, $(check-unit-y))
 check-block: $(patsubst %,check-%, $(check-block-y))
-check: check-unit check-qtest
+check-libqblock: $(patsubst %,check-%, $(check-libqblock-y))
+check: check-libqblock check-unit check-qtest
 
 check-clean:
 	$(MAKE) -C tests/tcg clean
 	rm -f $(check-unit-y)
 	rm -f $(check-qtest-i386-y) $(check-qtest-x86_64-y) $(check-qtest-sparc64-y) $(check-qtest-sparc-y)
 	rm -f tests/*.o
+	rm -f $(check-libqblock-y)
+	rm -rf $(LIBQBLOCK_TEST_DIR)
 
 -include $(wildcard tests/*.d)
diff --git a/tests/check-libqblock-qcow2.c b/tests/check-libqblock-qcow2.c
new file mode 100644
index 0000000..50a4df3
--- /dev/null
+++ b/tests/check-libqblock-qcow2.c
@@ -0,0 +1,6 @@ 
+#include "libqblock.h"
+int main(int argc, char **argv)
+{
+    libqb_test();
+    return 0;
+}