Skip to contentSkip to conversation

libqblock qemu block layer library

PATCH Superseded Wenchao Xia 3 participants 22 messages Nov 20, 2012 – Nov 22, 2012 Kbuild

v10 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v10 cover libqblock qemu block layer library

These patches introduce libqblock API, make subdir-libqblock and make
check-libqblock could build this library.
Functionalities:
1 create a new image.
2 sync access of an image.
3 basic image information retrieving such as backing file. 4 detect if a sector is allocated in an image.
Supported Formats:
ALL using file protocols.

Patch 1 to 2 is independent with libqblock, which fix small bug and improve
qemu, can be applied without libqblock. I am not sure if I should sent them in another thread, but following patch need these two fixing patch, so include them here together.

v2:
Insert reserved bytes into union.
Use uint64_t instead of size_t, offset.
Use const char * in filename pointer.
Initialization function removed and it was automatically executed when
library is loaded.
Added compile flag visibility=hidden, to avoid name space pollution. Structure naming style changed.
Using byte unit instead of sector for every API.
Added a member in image static information structure, to report logical
sector size, which is always 512 now.
Read and write API can take request not aligned to 512 now. It returns the
byte number that have succeed in operation, but now either negative value or the number requested would be returned, because qemu block sync I/O API would not return such number.
Typo fix due to comments and improved documents.

v3:
Removed the code about OOM error, introduced GError.
Used a table to map from string to enum types about format.
Use typedef for every structure.
Improved the gcc compiler macro to warn if gcc was not used. Global variable name changed with prefix libqb_.
The struct QBlockStaticInfo was changed to folder full format related
information inside, and a new member with pointers pointing to the mostly used members, such as backing file, virt size, was added. This would allow the user to get full information about how it is created in the future.
Each patch in the serial can work with qemu now.
Typo fixes.

v4:
Renamed QBroker to QBlockContext.
Removed tool objs out of libqblock.
Added a check in initialization about structure size for ABI. Added a new helper API to duplicate protocol information, helps to open files
in a backing file chain.
Check-libqblock will not rebuild libqblock every time now.
Test case file renamed to "libqblock-[FMT].c".
Test use gtest framework now.
Test do random creation of test file now, added check for information API in
it.
Test do random sync io instead of fixed offset io now.
Test accept one parameter about where to place the test image, now it is
./tests/libqblock/test_images.

v5:
Makefile of libqblock was adjusted to be similar as libcacard, added spec
file and install section.
Removed warning when GCC was not found.
Structure names were changed to better ones.
Removed the union typedef that contain reserved bytes to reduce the folder
depth.
Some format related enum options was changed to better name. Added accessors about image static information, hide indirect accessing
member detail in the structure.
Test Makefile do not create diretory now, test case create it themself. Test build system do not use libtool now, and removed qtest-obj-y in its
dependency, make check will automatically execute test anyway now.
Removed "ifeq ($(LIBTOOL),)" in Makefile.

v6:
Remove address pointer member in image static info structure.

v7:
Support out of tree building.

v8:
Fix a bug in out of tree building.

v9:
Rebase and splitted out small fix patch for qemu.

v10:
Rebased to upstream, adjusted libqblock build system according to Paolo's
comments.

Wenchao Xia (7):
Buildsystem fix distclean error for pixman
Buildsystem clean tests directory clearly
block export function path_has_protocol
libqblock build system
libqblock type defines
libqblock API
libqblock test example

 .gitignore                     |    2 +
 Makefile                       |   33 +-
 block.c                        |    2 +-
 block.h                        |    2 +
 configure                      |   31 +-
 libqblock/Makefile             |   74 +++
 libqblock/libqblock-error.c    |   57 ++
 libqblock/libqblock-error.h    |   49 ++
 libqblock/libqblock-internal.h |   75 +++
 libqblock/libqblock-types.h    |  252 +++++++++
 libqblock/libqblock.c          | 1191 ++++++++++++++++++++++++++++++++++++++++
 libqblock/libqblock.h          |  341 ++++++++++++
 libqblock/libqblock.pc.in      |   13 +
 tests/Makefile                 |   38 ++-
 tests/check-libqblock-qcow2.c  |  392 +++++++++++++
 15 files changed, 2541 insertions(+), 11 deletions(-)
 create mode 100644 libqblock/Makefile
 create mode 100644 libqblock/libqblock-error.c
 create mode 100644 libqblock/libqblock-error.h
 create mode 100644 libqblock/libqblock-internal.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
#1 lore raw

PATCH v10 1/7 Buildsystem fix distclean error for pixman

Currently Makefile test if pixman have configure log, but the script directly
return error if that file do not exist. This patch fix it.

v2: print out the command.

---
 Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
index 3e8d441..9ecbcbb 100644
@@ -286,7 +286,7 @@ distclean: clean
 	for d in $(TARGET_DIRS) $(QEMULIBS); do \
 	rm -rf $$d || exit 1 ; \
         done
-	test -f pixman/config.log && make -C pixman distclean
+	if test -f pixman/config.log; then make -C pixman distclean; fi
 
 KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  modifiers  no  pt-br  sv \
 ar      de     en-us  fi  fr-be  hr     it  lv  nl         pl  ru     th \
Signature · 1 line
1.7.1
#5 lore raw

PATCH v10 3/7 block export function path_has_protocol

In reply to Wenchao Xia

This function is needed in other module, so export it. There is
already some patch on mail-list try export it, If that patch was applied, pls ignore this one.

---
 block.c |    2 +-
 block.h |    2 ++
 2 files changed, 3 insertions(+), 1 deletions(-)
block.c +1 -1
index 854ebd6..bfb2be8 100644
@@ -199,7 +199,7 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs,
 }
 
 /* check if the path starts with "<protocol>:" */
-static int path_has_protocol(const char *path)
+int path_has_protocol(const char *path)
 {
     const char *p;
 
block.h +2 -0
index 722c620..6805245 100644
@@ -428,6 +428,8 @@ typedef enum {
     BLKDBG_EVENT_MAX,
 } BlkDebugEvent;
 
+int path_has_protocol(const char *path);
+
 #define BLKDBG_EVENT(bs, evt) bdrv_debug_event(bs, evt)
 void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event);
 
Signature · 1 line
1.7.1
#4 lore raw

PATCH v10 2/7 Buildsystem clean tests directory clearly

In reply to Wenchao Xia

Currently root Makefile try clean tests/tcg, hard to extend.
This patch added command make check-clean, which clean all generated files used in tests. With this command root Makefile do not care tests clean method any more, it simply calls the command to do it, so any more clean script could be added in tests/Makefile, make it easier to extend.

v2:
Discard env MAKEFILES, always include tests/Makefile.

---
 Makefile       |    6 ++----
 configure      |    2 +-
 tests/Makefile |    7 +++++++
 3 files changed, 10 insertions(+), 5 deletions(-)
Makefile +2 -4
index 9ecbcbb..b04d862 100644
@@ -211,9 +211,7 @@ qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
 
 gen-out-type = $(subst .,-,$(suffix $@))
 
-ifneq ($(wildcard config-host.mak),)
-include $(SRC_PATH)/tests/Makefile
-endif
+include tests/Makefile
 
 qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py
 
@@ -259,7 +257,7 @@ clean:
 	rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
 	rm -rf qapi-generated
 	rm -rf qga/qapi-generated
-	$(MAKE) -C tests/tcg clean
+	$(MAKE) check-clean
 	for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \
 	if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
 	rm -f $$d/qemu-options.def; \
configure +1 -1
index 780b19a..801585c 100755
@@ -4166,7 +4166,7 @@ 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"
-FILES="Makefile tests/tcg/Makefile qdict-test-data.txt"
+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"
tests/Makefile +7 -0
index ca680e5..ef6c9f2 100644
@@ -94,6 +94,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-clean          Clean the tests"
 	@echo
 	@echo "Please note that HTML reports do not regenerate if the unit tests"
 	@echo "has not changed."
@@ -148,4 +149,10 @@ check-unit: $(patsubst %,check-%, $(check-unit-y))
 check-block: $(patsubst %,check-%, $(check-block-y))
 check: 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
+
 -include $(wildcard tests/*.d)
Signature · 1 line
1.7.1
#6 lore raw

PATCH v10 4/7 libqblock build system

In reply to Wenchao Xia

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, 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.

---
 .gitignore                    |    2 +
 Makefile                      |   25 +++++++++++++-
 configure                     |   29 ++++++++++++++++
 libqblock/Makefile            |   74 +++++++++++++++++++++++++++++++++++++++++
 libqblock/libqblock.c         |    6 +++
 libqblock/libqblock.h         |    1 +
 libqblock/libqblock.pc.in     |   13 +++++++
 tests/Makefile                |   31 ++++++++++++++++-
 tests/check-libqblock-qcow2.c |    6 +++
 9 files changed, 183 insertions(+), 4 deletions(-)
 create mode 100644 libqblock/Makefile
 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
.gitignore +2 -0
index bd6ba1c..77c1910 100644
@@ -93,3 +93,5 @@ cscope.*
 tags
 TAGS
 *~
+tests/check-libqblock-qcow2
+tests/test_images
Makefile +23 -2
index b04d862..dd01fe7 100644
@@ -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)"
configure +29 -0
index 801585c..b0cc044 100755
@@ -223,6 +223,7 @@ libiscsi=""
 coroutine=""
 seccomp=""
 glusterfs=""
+libqblock="yes"
 
 # 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,18 @@ EOF
   fi
 fi
 
+##########################################
+# libqblock probe
+if test "$libqblock" != "no" ; then
+# libqblock depends on libtool, default to yes if libtool exist
+    if ! has $libtool; then
+        echo
+        echo "Warning: libqblock needs libtool"
+        echo "Setting libqblock option to no."
+        echo
+        libqblock="no"
+    fi
+fi
 #
 # Check for xxxat() functions when we are building linux-user
 # emulator.  This is done because older glibc versions don't
@@ -3101,6 +3120,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 +3257,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 +3604,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 +4193,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 \
libqblock/Makefile new file +74 -0

74 lines not on this page · raw message

libqblock/libqblock-error.c new file +0 -0
new file mode 100644
index 0000000..e69de29
libqblock/libqblock-error.h new file +0 -0
new file mode 100644
index 0000000..e69de29
libqblock/libqblock-types.h new file +0 -0
new file mode 100644
index 0000000..e69de29
libqblock/libqblock.c new file +6 -0
new file mode 100644
index 0000000..4c18c41
@@ -0,0 +1,6 @@
+#include "libqblock.h"
+
+int libqb_test(void)
+{
+    return 0;
+}
libqblock/libqblock.h new file +1 -0
new file mode 100644
index 0000000..b0f9daf
@@ -0,0 +1 @@
+__attribute__((visibility("default"))) int libqb_test(void);
libqblock/libqblock.pc.in new file +13 -0
new file mode 100644
index 0000000..d2a7d06
@@ -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}
tests/Makefile +29 -2
index ef6c9f2..997dbcc 100644
@@ -84,6 +84,23 @@ 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_DIR)
+LIBQBLOCK_TEST_DIR = tests/test_images
+LIBQBLOCK_DIR = libqblock
+LIBQBLOCK_SO = $(LIBQBLOCK_DIR)/.libs/libqblock.so
+LIBQBLOCK_SO_LINK_FLAG = -Wl,-rpath,$(LIBQBLOCK_DIR)/.libs
+
+#use libtool to link check-libqblock, use LIBQBLOCK_SO_LINK_FLAG to add lib search diretory
+LTLINK_CHECK_LIBQBLOCK = $(call quiet-command, $(LIBTOOL) --mode=link --quiet --tag=CC \
+         $(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) $(LIBQBLOCK_SO_LINK_FLAG) \
+         -o $@ $(sort $(1)) $(LIBS), "lt LINK $(TARGET_DIR) $@")
+
+$(check-libqblock-y): %$(EXESUF): %.o
+	$(call LTLINK_CHECK_LIBQBLOCK, $^ $(LIBQBLOCK_SO))
+
 .PHONY: check-help
 check-help:
 	@echo "Regression testing targets:"
@@ -94,6 +111,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"
@@ -126,6 +144,12 @@ $(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
+
+.PHONY: $(patsubst %, check-%, $(check-libqblock-y))
+$(patsubst %, check-%, $(check-libqblock-y)): check-%: %
+	$(call quiet-command, LIBQBLOCK_TEST_DIR=$(LIBQBLOCK_TEST_DIR) gtester $(GTESTER_OPTIONS) -m=$(SPEED) $*,"GTESTER $*")
+
 # Reports and overall runs
 
 check-report.xml: $(patsubst %,check-report-qtest-%.xml, $(QTEST_TARGETS)) check-report-unit.xml
@@ -143,16 +167,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)
tests/check-libqblock-qcow2.c new file +6 -0
new file mode 100644
index 0000000..50a4df3
@@ -0,0 +1,6 @@
+#include "libqblock.h"
+int main(int argc, char **argv)
+{
+    libqb_test();
+    return 0;
+}
Signature · 1 line
1.7.1
#11 lore raw

PATCH v10 5/7 libqblock type defines

In reply to Wenchao Xia

This patch contains type and macro defines used in APIs, one file for public
usage, one for libqblock internal usage.

---
 libqblock/libqblock-internal.h |   75 ++++++++++++
 libqblock/libqblock-types.h    |  252 ++++++++++++++++++++++++++++++++++++++++
 libqblock/libqblock.c          |    6 -
 libqblock/libqblock.h          |    1 -
 tests/check-libqblock-qcow2.c  |    1 -
 5 files changed, 327 insertions(+), 8 deletions(-)
 create mode 100644 libqblock/libqblock-internal.h
libqblock/libqblock-internal.h new file +75 -0
new file mode 100644
index 0000000..75c0452
@@ -0,0 +1,75 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * 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.
+ *
+ */
+
+#ifndef LIBQBLOCK_INTERNAL
+#define LIBQBLOCK_INTERNAL
+
+#include "glib.h"
+
+#include "block.h"
+#include "block_int.h"
+#include "libqblock-types.h"
+
+/* this file contains defines and types used inside the library. */
+
+#define FUNC_FREE(p) g_free((p))
+#define FUNC_MALLOC(size) g_malloc((size))
+#define FUNC_CALLOC(nmemb, size) g_malloc0((nmemb)*(size))
+#define FUNC_STRDUP(p) g_strdup((p))
+
+#define CLEAN_FREE(p) { \
+        FUNC_FREE(p); \
+        (p) = NULL; \
+}
+
+/* details should be hidden to user */
+struct QBlockState {
+    BlockDriverState *bdrvs;
+    /* internal used file name now, if it is not NULL, it means
+       image was opened.
+    */
+    char *filename;
+};
+
+struct QBlockContext {
+    /* last error */
+    GError *g_error;
+    int err_ret; /* 1st level of error, the libqblock error number */
+    int err_no; /* 2nd level of error, errno what below reports */
+};
+
+/**
+ * QBlockStaticInfoAddr: a structure contains a set of pointer.
+ *
+ *    this struct contains a set of pointer pointing to some
+ *  property related to format or protocol. If a property is not available,
+ *  it will be set as NULL. User could use this to get properties directly.
+ *
+ *  @virt_size: virtual size, it is always not NULL.
+ *  @backing_loc: backing file location.
+ *  @encrypt: encryption flag.
+*/
+
+typedef struct QBlockStaticInfoAddr {
+    uint64_t *virt_size;
+    QBlockLocationInfo *backing_loc;
+    bool *encrypt;
+} QBlockStaticInfoAddr;
+
+#define G_LIBQBLOCK_ERROR g_libqbock_error_quark()
+
+static inline GQuark g_libqbock_error_quark(void)
+{
+    return g_quark_from_static_string("g-libqblock-error-quark");
+}
+#endif
libqblock/libqblock-types.h +252 -0

252 lines not on this page · raw message

libqblock/libqblock.c +0 -6
index 4c18c41..e69de29 100644
@@ -1,6 +0,0 @@
-#include "libqblock.h"
-
-int libqb_test(void)
-{
-    return 0;
-}
libqblock/libqblock.h +0 -1
index b0f9daf..e69de29 100644
@@ -1 +0,0 @@
-__attribute__((visibility("default"))) int libqb_test(void);
tests/check-libqblock-qcow2.c +0 -1
index 50a4df3..6f5ccac 100644
@@ -1,6 +1,5 @@
 #include "libqblock.h"
 int main(int argc, char **argv)
 {
-    libqb_test();
     return 0;
 }
Signature · 1 line
1.7.1
#16 lore raw

PATCH v10 6/7 libqblock API

In reply to Wenchao Xia

This patch contains the major APIs in the library. For ABI some reserved
members were used.
Important APIs:
1 QBlockContext. This structure was used to retrieve errors, every thread
must create one first.
2 QBlockState. It stands for an block image object.
3 QBlockStaticInfo. It contains static information such as location, backing
file, size.
4 Sync I/O. It is similar to C file open, read, write and close operations.

---
 libqblock/libqblock-error.c |   57 ++
 libqblock/libqblock-error.h |   49 ++
 libqblock/libqblock.c       | 1191 +++++++++++++++++++++++++++++++++++++++++++
 libqblock/libqblock.h       |  341 +++++++++++++
 4 files changed, 1638 insertions(+), 0 deletions(-)
libqblock/libqblock-error.c +57 -0
index e69de29..2a59970 100644
@@ -0,0 +1,57 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * 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 "libqblock-error.h"
+#include "libqblock-internal.h"
+
+void qb_error_get_human_str(QBlockContext *context,
+                            char *buf, size_t buf_size)
+{
+    const char *err_ret_str;
+    switch (context->err_ret) {
+    case QB_ERR_INTERNAL_ERR:
+        err_ret_str = "Internal error.";
+        break;
+    case QB_ERR_INVALID_PARAM:
+        err_ret_str = "Invalid param.";
+        break;
+    case QB_ERR_BLOCK_OUT_OF_RANGE:
+        err_ret_str = "request is out of image's range.";
+        break;
+    default:
+        err_ret_str = "Unknown error.";
+        break;
+    }
+    if (context == NULL) {
+        snprintf(buf, buf_size, "%s", err_ret_str);
+        return;
+    }
+
+    if (context->err_ret == QB_ERR_INTERNAL_ERR) {
+        snprintf(buf, buf_size, "%s %s errno [%d]. strerror [%s].",
+                     err_ret_str, context->g_error->message,
+                     context->err_no, strerror(-context->err_no));
+    } else {
+        snprintf(buf, buf_size, "%s %s",
+                     err_ret_str, context->g_error->message);
+    }
+    return;
+}
+
+int qb_error_get_errno(QBlockContext *context)
+{
+    if (context->err_ret == QB_ERR_INTERNAL_ERR) {
+        return context->err_no;
+    }
+    return 0;
+}
libqblock/libqblock-error.h +49 -0

49 lines not on this page · raw message

libqblock/libqblock.c +1191 -0

1,191 lines not on this page · raw message

libqblock/libqblock.h +341 -0

341 lines not on this page · raw message

Signature · 1 line
1.7.1
#21 lore raw

PATCH v10 7/7 libqblock test example

In reply to Wenchao Xia

In this example, first it will create some qcow2 images, then try get
information including backing file relationship, then it will do sync IO on the image.

---
 tests/check-libqblock-qcow2.c |  389 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 388 insertions(+), 1 deletions(-)
tests/check-libqblock-qcow2.c +388 -1
index 6f5ccac..15e81b8 100644
@@ -1,5 +1,392 @@
+/*
+ * QEMU block layer library test
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * 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.
+ *
+ * Limitation:
+ *    1 filename do not support relative path, to save trouble in creating
+ * backing files.
+ */
+
+#include <glib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+
 #include "libqblock.h"
+#include "libqtest.h"
+
+#define LIBQB_TEST_ENV_DIR "LIBQBLOCK_TEST_DIR"
+#define LIBQB_TEST_DEFAULT_DIR "/tmp"
+#define LIBQB_TEST_DEFAULT_FILENAME "libqblock_qcow2_test_img"
+
+typedef struct LibqbTestSettings {
+    const char *image_filename;
+    uint64_t image_size;
+    unsigned int num_backings;
+    unsigned int io_buf_size;
+    uint64_t io_offset;
+    int print_flag;
+} LibqbTestSettings;
+
+LibqbTestSettings libqb_test_settings;
+
+static void print_loc(const QBlockLocationInfo *loc)
+{
+    if (loc == NULL) {
+        printf("loc is NULL.");
+        return;
+    }
+    switch (loc->prot_type) {
+    case QB_PROTO_NONE:
+        printf("protocol type [none].");
+        break;
+    case QB_PROTO_FILE:
+        printf("protocol type [file], filename [%s].",
+               loc->o_file.filename);
+        break;
+    default:
+        printf("protocol type not supported.");
+        break;
+    }
+}
+
+static void print_info_image_static(QBlockStaticInfo *info)
+{
+    const uint64_t *virt_size = qb_get_virt_size(info);
+    const QBlockLocationInfo *backing_loc = qb_get_backing_loc(info);
+    g_assert(virt_size != NULL);
+
+    printf("=======image location:\n");
+    print_loc(&info->loc);
+    printf("\nvirtual_size %" PRId64 ", format type %d [%s]",
+           *(virt_size),
+           info->fmt.fmt_type, qb_fmttype2str(info->fmt.fmt_type));
+    printf("\nbacking image location:\n");
+    print_loc(backing_loc);
+    printf("\n");
+}
+
+static char *generate_backing_filename(const char *filename, int index)
+{
+    char *backing_filename = NULL;
+
+    backing_filename = g_strdup_printf("%s_backing_%d", filename, index);
+    return backing_filename;
+}
+
+/* get filename in a full path */
+static const char *get_filename(const char *path)
+{
+    const char *filename;
+    filename = strrchr(path, '/');
+    if (filename == NULL) {
+        filename = path;
+    } else {
+        filename++;
+    }
+    return filename;
+}
+
+/* create a chain of files, num_backings must >= 0. */
+static void files_create_qcow2(const char *filename,
+                               int num_backings,
+                               uint64_t virt_size)
+{
+    QBlockContext *context = NULL;
+    QBlockState *qbs = NULL;
+    QBlockLocationInfo *loc_info = NULL;
+    QBlockFormatInfo *fmt_info = NULL;
+    int ret;
+    int index;
+    int flag;
+    char *backing_filename = NULL, *new_filename = NULL;
+    const char *relative_filename = NULL;
+
+    ret = qb_context_new(&context);
+    g_assert(ret == 0);
+
+    ret = qb_state_new(context, &qbs);
+    g_assert(ret == 0);
+
+    ret = qb_loc_info_new(context, &loc_info);
+    g_assert(ret == 0);
+
+    ret = qb_fmt_info_new(context, &fmt_info);
+    g_assert(ret == 0);
+
+    loc_info->prot_type = QB_PROTO_FILE;
+    fmt_info->fmt_type = QB_FMT_QCOW2;
+    fmt_info->o_qcow2.virt_size = virt_size;
+    flag = 0;
+
+    index = 0;
+    while (index < num_backings) {
+        new_filename = generate_backing_filename(filename, index);
+        loc_info->o_file.filename = new_filename;
+        if (backing_filename != NULL) {
+            fmt_info->o_qcow2.backing_loc.prot_type = QB_PROTO_FILE;
+            relative_filename = get_filename(backing_filename);
+            fmt_info->o_qcow2.backing_loc.o_file.filename =
+                                                             relative_filename;
+        }
+        ret = qb_create(context, qbs, loc_info, fmt_info, flag);
+        g_assert(ret == 0);
+        free(backing_filename);
+        backing_filename = new_filename;
+        new_filename = NULL;
+        index++;
+    }
+
+    loc_info->o_file.filename = filename;
+    if (backing_filename != NULL) {
+        fmt_info->o_qcow2.backing_loc.prot_type = QB_PROTO_FILE;
+        relative_filename = get_filename(backing_filename);
+        fmt_info->o_qcow2.backing_loc.o_file.filename =
+                                                         relative_filename;
+    }
+    ret = qb_create(context, qbs, loc_info, fmt_info, flag);
+    g_assert(ret == 0);
+    free(backing_filename);
+
+    qb_fmt_info_delete(context, &fmt_info);
+    qb_loc_info_delete(context, &loc_info);
+    qb_state_delete(context, &qbs);
+    qb_context_delete(&context);
+    return;
+}
+
+static void files_delete(const char *filename,
+                         int num_backings,
+                         uint64_t virt_size)
+{
+    char *new_filename = NULL;
+    int index = 0;
+    while (index < num_backings) {
+        new_filename = generate_backing_filename(filename, index);
+        unlink(new_filename);
+        free(new_filename);
+        index++;
+    }
+    unlink(filename);
+}
+
+static void testcase_info_image_static(void)
+{
+    const char *filename = libqb_test_settings.image_filename;
+    uint64_t image_size = libqb_test_settings.image_size;
+    int num_backings = libqb_test_settings.num_backings;
+    QBlockContext *context = NULL;
+    QBlockState *qbs = NULL;
+    QBlockLocationInfo *loc_info = NULL;
+    int ret, flag;
+    QBlockStaticInfo *info_st = NULL;
+    int i;
+    char *backing_filename = NULL;
+    const uint64_t *virt_size = NULL;
+    const QBlockLocationInfo *backing_loc = NULL;
+
+    ret = qb_context_new(&context);
+    g_assert(ret == 0);
+
+    ret = qb_state_new(context, &qbs);
+    g_assert(ret == 0);
+
+    ret = qb_loc_info_new(context, &loc_info);
+    g_assert(ret == 0);
+
+    loc_info->prot_type = QB_PROTO_FILE;
+    loc_info->o_file.filename = filename;
+    flag = LIBQBLOCK_O_NO_BACKING;
+    ret = qb_open(context, qbs, loc_info, NULL, flag);
+    g_assert(ret == 0);
+
+    i = num_backings - 1;
+    while (1) {
+        ret = qb_info_image_static_get(context, qbs, &info_st);
+        g_assert(ret == 0);
+        if (libqb_test_settings.print_flag > 0) {
+            print_info_image_static(info_st);
+        }
+        qb_close(context, qbs);
+
+        /* checking the information */
+        g_assert(info_st->loc.prot_type == loc_info->prot_type);
+        ret = strcmp(info_st->loc.o_file.filename,
+                     loc_info->o_file.filename);
+
+        g_assert(ret == 0);
+        g_assert(info_st->fmt.fmt_type == QB_FMT_QCOW2);
+        virt_size = qb_get_virt_size(info_st);
+        g_assert(virt_size != NULL);
+        g_assert(*virt_size == image_size);
+        backing_loc = qb_get_backing_loc(info_st);
+        /* qcow2 have always backing file property */
+        g_assert(backing_loc != NULL);
+        if (i >= 0) {
+            /* it should have backing file */
+            g_assert(backing_loc->prot_type == QB_PROTO_FILE);
+            backing_filename = generate_backing_filename(filename, i);
+            ret = strcmp(backing_filename, backing_loc->o_file.filename);
+            g_assert(ret == 0);
+            g_free(backing_filename);
+        } else {
+            g_assert(backing_loc->prot_type == QB_FMT_NONE);
+        }
+        i--;
+        /* see if there is backing file need to check. */
+        if (backing_loc->prot_type == QB_FMT_NONE) {
+            g_assert(i < 0);
+            break;
+        }
+        qb_loc_info_delete(context, &loc_info);
+        loc_info = qb_loc_info_dup(backing_loc);
+        ret = qb_open(context, qbs, loc_info, NULL, flag);
+        g_assert(ret == 0);
+        qb_info_image_static_delete(context, &info_st);
+    }
+    qb_info_image_static_delete(context, &info_st);
+
+    qb_loc_info_delete(context, &loc_info);
+    qb_state_delete(context, &qbs);
+    qb_context_delete(&context);
+    return;
+}
+
+/* assuming the image is new created */
+static void testcase_sync_io(void)
+{
+    const char *filename = libqb_test_settings.image_filename;
+    uint64_t io_buf_size = libqb_test_settings.io_buf_size;
+    uint64_t io_offset = libqb_test_settings.io_offset;;
+    unsigned char *buf_r, *buf_w;
+    uint64_t i;
+    unsigned int rand_value;
+
+    buf_r = g_malloc0(io_buf_size);
+    buf_w = g_malloc0(io_buf_size);
+    for (i = 0; i < io_buf_size; i++) {
+        rand_value = g_test_rand_int_range(0, 255);
+        buf_w[i] = (unsigned char)rand_value;
+    }
+
+    QBlockContext *context = NULL;
+    QBlockState *qbs = NULL;
+    QBlockLocationInfo *loc_info = NULL;
+    int ret, flag;
+
+    ret = qb_context_new(&context);
+    g_assert(ret == 0);
+
+    ret = qb_state_new(context, &qbs);
+    g_assert(ret == 0);
+
+    ret = qb_loc_info_new(context, &loc_info);
+    g_assert(ret == 0);
+
+
+    loc_info->prot_type = QB_PROTO_FILE;
+    loc_info->o_file.filename = filename;
+    flag = LIBQBLOCK_O_RDWR;
+    ret = qb_open(context, qbs, loc_info, NULL, flag);
+    g_assert(ret == 0);
+
+    int status;
+    int64_t len;
+    ret = qb_check_allocation(context, qbs, io_offset, io_buf_size,
+                                       &status, &len);
+    g_assert(ret == 0);
+    g_assert(status == 0);
+    g_assert(len == io_buf_size);
+
+    ret = qb_write(context, qbs, buf_w, io_buf_size, io_offset);
+    g_assert(ret == io_buf_size);
+
+    ret = qb_read(context, qbs, buf_r, io_buf_size, io_offset);
+    g_assert(ret == io_buf_size);
+
+    int cmp = memcmp(buf_r, buf_w, io_buf_size);
+    g_assert(cmp == 0);
+
+    ret = qb_check_allocation(context, qbs, io_offset, io_buf_size,
+                                       &status, &len);
+    g_assert(ret == 0);
+    g_assert(status == 1);
+    g_assert(len == io_buf_size);
+
+    qb_close(context, qbs);
+
+    qb_loc_info_delete(context, &loc_info);
+    qb_state_delete(context, &qbs);
+    qb_context_delete(&context);
+    g_free(buf_r);
+    g_free(buf_w);
+    return;
+}
+
 int main(int argc, char **argv)
 {
-    return 0;
+    const char *root_dir;
+    const char *name = LIBQB_TEST_DEFAULT_FILENAME;
+    int ret;
+    int dir_created = 0;
+    char *filename;
+
+    root_dir = getenv(LIBQB_TEST_ENV_DIR);
+    if (root_dir == NULL) {
+        root_dir = LIBQB_TEST_DEFAULT_DIR;
+    }
+
+    ret = access(root_dir, F_OK);
+    if (ret != 0) {
+        /*try mkdir */
+        ret = mkdir(root_dir, 0755);
+        g_assert(ret == 0);
+        dir_created = 1;
+    }
+
+    filename = g_strdup_printf("%s/%s", root_dir, name);
+
+    g_test_init(&argc, &argv, NULL);
+    g_test_rand_int();
+
+    libqb_test_settings.image_filename = filename;
+    libqb_test_settings.image_size =
+                            1024 * 1024 * g_test_rand_int_range(1, 1024);
+    libqb_test_settings.num_backings = g_test_rand_int_range(0, 10);
+    libqb_test_settings.io_buf_size = g_test_rand_int_range(1, 1024 * 1024);
+    libqb_test_settings.io_offset = g_test_rand_int_range(0,
+            libqb_test_settings.image_size - libqb_test_settings.io_buf_size);
+
+    files_create_qcow2(libqb_test_settings.image_filename,
+                       libqb_test_settings.num_backings,
+                       libqb_test_settings.image_size);
+
+    g_test_add_func("/libqblock/sync_info_image_static",
+                      testcase_info_image_static);
+    g_test_add_func("/libqblock/sync_io", testcase_sync_io);
+
+    ret = g_test_run();
+    files_delete(libqb_test_settings.image_filename,
+                 libqb_test_settings.num_backings,
+                 libqb_test_settings.image_size);
+
+    g_free(filename);
+    if (dir_created) {
+        ret = rmdir(root_dir);
+        g_assert(ret == 0);
+    }
+    return ret;
 }
Signature · 1 line
1.7.1
#7 lore raw

Re: [Qemu-devel] [PATCH V10 4/7] libqblock build system

In reply to Wenchao Xia

Mostly looks good...

Il 20/11/2012 10:46, Wenchao Xia ha scritto:

Quoted 1 line

+libqblock="yes"

Please make the default the empty string, i.e. "build if and only if libtool is present".

Quoted 4 lines
configure +3 -0
+##########################################
+# libqblock probe
+if test "$libqblock" != "no" ; then

configure EOF · line 2371

Quoted 10 lines
configure +9 -0
+# libqblock depends on libtool, default to yes if libtool exist
+    if ! has $libtool; then
+        echo
+        echo "Warning: libqblock needs libtool"
+        echo "Setting libqblock option to no."
+        echo
+        libqblock="no"
+    fi
+fi
 #

Please fail here if libqblock=yes but libtool is not found.

libqblock/Makefile line 19

Quoted 4 lines
libqblock/Makefile new file +4 -0
+#library objects
+libqblock-obj-y= libqblock/libqblock.o libqblock/libqblock-error.o
+extra-obj-y= main-loop.o qemu-timer.o qemu-tool.o iohandler.o \
+             compatfd.o

Are all of these really necessary? Instead of main-loop/compatfd/iohandler, I think you can just add a new libqblock/libqblock-aio.c file, and copy these definitions from main-loop.c:

QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
void qemu_aio_flush(void)
bool qemu_aio_wait(void)
void qemu_aio_set_fd_handler(int fd,

                            IOHandler *io_read,
                            IOHandler *io_write,
                            AioFlushHandler *io_flush,
                            void *opaque);
void qemu_aio_set_event_notifier(EventNotifier *notifier,
                                EventNotifierHandler *io_read,
                                AioFlushEventNotifierHandler *io_flush);

and also include part of qemu_init_main_loop in the creation of a new QBlockContext (the first time it's called). We can later map each QBlockContext to a different AioContext. Please document somewhere that the library is not yet thread-safe.

Quoted 6 lines
tests/Makefile +0 -0
index ef6c9f2..997dbcc 100644
@@ -84,6 +84,23 @@ check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)
 qtest-obj-y = tests/libqtest.o $(oslib-obj-y) libqemustub.a

tests/Makefile check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET) · line 94

Quoted 10 lines
tests/Makefile +8 -0
 $(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_DIR)
+LIBQBLOCK_TEST_DIR = tests/test_images
+LIBQBLOCK_DIR = libqblock
+LIBQBLOCK_SO = $(LIBQBLOCK_DIR)/.libs/libqblock.so
+LIBQBLOCK_SO_LINK_FLAG = -Wl,-rpath,$(LIBQBLOCK_DIR)/.libs

These two should not be required. Just link in libqblock/libqblock.la and libtool will do all of its magic.

Paolo

Quoted 8 lines
tests/Makefile +8 -0
+
+#use libtool to link check-libqblock, use LIBQBLOCK_SO_LINK_FLAG to add lib search diretory
+LTLINK_CHECK_LIBQBLOCK = $(call quiet-command, $(LIBTOOL) --mode=link --quiet --tag=CC \
+         $(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) $(LIBQBLOCK_SO_LINK_FLAG) \
+         -o $@ $(sort $(1)) $(LIBS), "lt LINK $(TARGET_DIR) $@")
+
+$(check-libqblock-y): %$(EXESUF): %.o
+	$(call LTLINK_CHECK_LIBQBLOCK, $^ $(LIBQBLOCK_SO))
#12 lore raw

Re: [Qemu-devel] [PATCH V10 5/7] libqblock type defines

In reply to Wenchao Xia

Il 20/11/2012 10:46, Wenchao Xia ha scritto:

Quoted 2 lines

This patch contains type and macro defines used in APIs, one file for public
usage, one for libqblock internal usage.

Mostly looks good, just a few questions below.

Quoted 23 lines
---
 libqblock/libqblock-internal.h |   75 ++++++++++++
 libqblock/libqblock-types.h    |  252 ++++++++++++++++++++++++++++++++++++++++
 libqblock/libqblock.c          |    6 -
 libqblock/libqblock.h          |    1 -
 tests/check-libqblock-qcow2.c  |    1 -
 5 files changed, 327 insertions(+), 8 deletions(-)
 create mode 100644 libqblock/libqblock-internal.h
libqblock/libqblock-internal.h new file +7 -0
new file mode 100644
index 0000000..75c0452
@@ -0,0 +1,75 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>

libqblock/libqblock-internal.h line 17

Quoted 10 lines
libqblock/libqblock-internal.h new file +10 -0
+ *
+ * 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.
+ *
+ */
+
+#ifndef LIBQBLOCK_INTERNAL
+#define LIBQBLOCK_INTERNAL
+
+#include "glib.h"

Use <glib.h> please.

libqblock/libqblock-internal.h line 20

Quoted 3 lines
libqblock/libqblock-internal.h new file +3 -0
+
+#include "block.h"
+#include "block_int.h"

Is block_int.h really needed?

libqblock/libqblock-internal.h line 28

Quoted 8 lines
libqblock/libqblock-internal.h new file +8 -0
+#include "libqblock-types.h"
+
+/* this file contains defines and types used inside the library. */
+
+#define FUNC_FREE(p) g_free((p))
+#define FUNC_MALLOC(size) g_malloc((size))
+#define FUNC_CALLOC(nmemb, size) g_malloc0((nmemb)*(size))
+#define FUNC_STRDUP(p) g_strdup((p))

Why keep these?

libqblock/libqblock-internal.h line 33

Quoted 5 lines
libqblock/libqblock-internal.h new file +5 -0
+
+#define CLEAN_FREE(p) { \
+        FUNC_FREE(p); \
+        (p) = NULL; \
+}

What about calling it QB_FREE?

Quoted 28 lines
libqblock/libqblock-internal.h new file +28 -0
+
+/* details should be hidden to user */
+struct QBlockState {
+    BlockDriverState *bdrvs;
+    /* internal used file name now, if it is not NULL, it means
+       image was opened.
+    */
+    char *filename;
+};
+
+struct QBlockContext {
+    /* last error */
+    GError *g_error;
+    int err_ret; /* 1st level of error, the libqblock error number */
+    int err_no; /* 2nd level of error, errno what below reports */
+};
+
+/**
+ * QBlockStaticInfoAddr: a structure contains a set of pointer.
+ *
+ *    this struct contains a set of pointer pointing to some
+ *  property related to format or protocol. If a property is not available,
+ *  it will be set as NULL. User could use this to get properties directly.
+ *
+ *  @virt_size: virtual size, it is always not NULL.
+ *  @backing_loc: backing file location.
+ *  @encrypt: encryption flag.
+*/

libqblock/libqblock-internal.h line 71

Quoted 10 lines
libqblock/libqblock-internal.h new file +10 -0
+
+typedef struct QBlockStaticInfoAddr {
+    uint64_t *virt_size;
+    QBlockLocationInfo *backing_loc;
+    bool *encrypt;
+} QBlockStaticInfoAddr;
+
+#define G_LIBQBLOCK_ERROR g_libqbock_error_quark()
+
+static inline GQuark g_libqbock_error_quark(void)

libqblock, not libqbock.

Quoted 210 lines
libqblock/libqblock-internal.h new file +4 -0
+{
+    return g_quark_from_static_string("g-libqblock-error-quark");
+}
+#endif
libqblock/libqblock-types.h +201 -0
index e69de29..77ad325 100644
@@ -0,0 +1,252 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * 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.
+ *
+ */
+
+#ifndef LIBQBLOCK_TYPES_H
+#define LIBQBLOCK_TYPES_H
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+    #ifdef LIBQB_BUILD
+        #define DLL_PUBLIC __attribute__((visibility("default")))
+    #else
+        #define DLL_PUBLIC
+    #endif
+#endif
+
+/* this library is designed around this core struct. */
+typedef struct QBlockState QBlockState;
+
+/* every thread should have a context. */
+typedef struct QBlockContext QBlockContext;
+
+/* flag used in open and create */
+#define LIBQBLOCK_O_RDWR        0x0002
+/* do not use the host page cache */
+#define LIBQBLOCK_O_NOCACHE     0x0020
+/* use write-back caching */
+#define LIBQBLOCK_O_CACHE_WB    0x0040
+/* don't open the backing file */
+#define LIBQBLOCK_O_NO_BACKING  0x0100
+/* disable flushing on this disk */
+#define LIBQBLOCK_O_NO_FLUSH    0x0200
+
+#define LIBQBLOCK_O_CACHE_MASK \
+   (LIBQBLOCK_O_NOCACHE | LIBQBLOCK_O_CACHE_WB | LIBQBLOCK_O_NO_FLUSH)
+
+#define LIBQBLOCK_O_VALID_MASK \
+   (LIBQBLOCK_O_RDWR | LIBQBLOCK_O_NOCACHE | LIBQBLOCK_O_CACHE_WB | \
+    LIBQBLOCK_O_NO_BACKING | LIBQBLOCK_O_NO_FLUSH)
+
+typedef enum QBlockProtocol {
+    QB_PROTO_NONE = 0,
+    QB_PROTO_FILE,
+    QB_PROTO_MAX
+} QBlockProtocol;
+
+typedef struct QBlockProtocolOptionsFile {
+    const char *filename;
+} QBlockProtocolOptionsFile;
+
+/**
+ * struct QBlockLocationInfo: contains information about how to find the image
+ *
+ * @prot_type: protocol type, now only support FILE.
+ * @o_file: file protocol related attributes.
+ * @reserved: reserved bytes for ABI.
+ */
+#define QBLOCK_PROT_OPTIONS_UNION_SIZE (512)
+typedef struct QBlockLocationInfo {
+    QBlockProtocol prot_type;
+    union {
+        QBlockProtocolOptionsFile o_file;
+        uint64_t reserved[QBLOCK_PROT_OPTIONS_UNION_SIZE/8];
+    };
+} QBlockLocationInfo;
+
+
+/* format related options */
+typedef enum QBlockFormat {
+    QB_FMT_NONE = 0,
+    QB_FMT_COW,
+    QB_FMT_QED,
+    QB_FMT_QCOW,
+    QB_FMT_QCOW2,
+    QB_FMT_RAW,
+    QB_FMT_RBD,
+    QB_FMT_SHEEPDOG,
+    QB_FMT_VDI,
+    QB_FMT_VMDK,
+    QB_FMT_VPC,
+    QB_FMT_MAX
+} QBlockFormat;
+
+typedef struct QBlockFormatOptionsCOW {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+} QBlockFormatOptionsCOW;
+
+typedef struct QBlockFormatOptionsQED {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    QBlockFormat backing_fmt;
+    uint64_t cluster_size; /* unit is bytes */
+    uint64_t table_size; /* unit is clusters */
+} QBlockFormatOptionsQED;
+
+typedef struct QBlockFormatOptionsQCOW {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    bool encrypt;
+} QBlockFormatOptionsQCOW;
+
+/* "Compatibility level (0.10 or 1.1)" */
+typedef enum QBlockFormatOptionsQCOW2CompatLv {
+    QB_FMT_QCOW2_COMPAT_DEFAULT = 0,
+    QB_FMT_QCOW2_COMPAT_V0_10,
+    QB_FMT_QCOW2_COMPAT_V1_10,
+} QBlockFormatOptionsQCOW2CompatLv;
+
+/* off or metadata */
+typedef enum QBlockFormatOptionsQCOW2PreAlloc {
+    QB_FMT_QCOW2_PREALLOC_DEFAULT = 0,
+    QB_FMT_QCOW2_PREALLOC_OFF,
+    QB_FMT_QCOW2_PREALLOC_METADATA,
+} QBlockFormatOptionsQCOW2PreAlloc;
+
+typedef struct QBlockFormatOptionsQCOW2 {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    QBlockFormat backing_fmt;
+    bool encrypt;
+    uint64_t cluster_size; /* unit is bytes */
+    QBlockFormatOptionsQCOW2CompatLv cpt_lv;
+    QBlockFormatOptionsQCOW2PreAlloc pre_mode;
+} QBlockFormatOptionsQCOW2;
+
+typedef struct QBlockFormatOptionsRAW {
+    uint64_t virt_size;
+} QBlockFormatOptionsRAW;
+
+typedef struct QBlockFormatOptionsRBD {
+    uint64_t virt_size;
+    uint64_t cluster_size;
+} QBlockFormatOptionsRBD;
+
+/* off or full */
+typedef enum QBlockFormatOptionsSDPreAlloc {
+    QB_FMT_SD_PREALLOC_DEFAULT = 0,
+    QB_FMT_SD_PREALLOC_OFF,
+    QB_FMT_SD_PREALLOC_FULL,
+} QBlockFormatOptionsSDPreAlloc;
+
+typedef struct QBlockFormatOptionsSD {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    QBlockFormatOptionsSDPreAlloc pre_mode;
+} QBlockFormatOptionsSD;
+
+typedef enum QBlockFormatOptionsVDIPreAlloc {
+    QB_FMT_VDI_PREALLOC_DEFAULT = 0,
+    QB_FMT_VDI_PREALLOC_OFF,
+    QB_FMT_VDI_PREALLOC_METADATA,
+} QBlockFormatOptionsVDIPreAlloc;
+
+typedef struct QBlockFormatOptionsVDI {
+    uint64_t virt_size;
+    uint64_t cluster_size;
+    QBlockFormatOptionsVDIPreAlloc pre_mode;
+} QBlockFormatOptionsVDI;
+
+/* whether compact to vmdk verion 6 */
+typedef enum QBlockFormatOptionsVMDKCompatLv {
+    QB_FMT_VMDK_COMPAT_DEFAULT = 0,
+    QB_FMT_VMDK_COMPAT_VMDKV6_FALSE,
+    QB_FMT_VMDK_COMPAT_VMDKV6_TRUE,
+} QBlockFormatOptionsVMDKCompatLv;
+
+/* vmdk flat extent format, values:
+"{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse |
+twoGbMaxExtentFlat | streamOptimized} */
+typedef enum QBlockFormatOptionsVMDKSubfmt {
+    QB_FMT_VMDK_SUBFMT_DEFAULT = 0,
+    QB_FMT_VMDK_SUBFMT_MONOLITHIC_SPARSE,
+    QB_FMT_VMDK_SUBFMT_MONOLITHIC_FLAT,
+    QB_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_SPARSE,
+    QB_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_FLAT,
+    QB_FMT_VMDK_SUBFMT_STREAM_OPTIMIZED,
+} QBlockFormatOptionsVMDKSubfmt;
+
+typedef struct QBlockFormatOptionsVMDK {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    QBlockFormatOptionsVMDKCompatLv cpt_lv;
+    QBlockFormatOptionsVMDKSubfmt subfmt;
+} QBlockFormatOptionsVMDK;
+
+/* "{dynamic (default) | fixed} " */
+typedef enum QBlockFormatOptionsVPCSubfmt {
+    QB_FMT_VPC_SUBFMT_DEFAULT = 0,

libqblock/libqblock-types.h line 211

Quoted 10 lines
libqblock/libqblock-types.h +10 -0
+    QB_FMT_VPC_SUBFMT_DYNAMIC,
+    QB_FMT_VPC_SUBFMT_FIXED,
+} QBlockFormatOptionsVPCSubfmt;
+
+typedef struct QBlockFormatOptionsVPC {
+    uint64_t virt_size;
+    QBlockFormatOptionsVPCSubfmt subfmt;
+} QBlockFormatOptionsVPC;
+
+#define QBLOCK_FMT_OPTIONS_UNION_SIZE (QBLOCK_PROT_OPTIONS_UNION_SIZE*2)

Why?

Quoted 46 lines
libqblock/libqblock-types.h +41 -0
+
+/**
+ * struct QBlockFormatInfo: contains information about how to retrieve data
+ *  from the image
+ *
+ * @fmt_type: format type.
+ * @o_cow~@o_vdi: format related attributes.
+ * @reserved: reserved bytes for ABI.
+ */
+typedef struct QBlockFormatInfo {
+    QBlockFormat fmt_type;
+    union {
+        QBlockFormatOptionsCOW       o_cow;
+        QBlockFormatOptionsQED       o_qed;
+        QBlockFormatOptionsQCOW      o_qcow;
+        QBlockFormatOptionsQCOW2     o_qcow2;
+        QBlockFormatOptionsRAW       o_raw;
+        QBlockFormatOptionsRBD       o_rbd;
+        QBlockFormatOptionsSD        o_sd;
+        QBlockFormatOptionsVDI       o_vdi;
+        QBlockFormatOptionsVMDK      o_vmdk;
+        QBlockFormatOptionsVPC       o_vpc;
+        uint64_t reserved[QBLOCK_FMT_OPTIONS_UNION_SIZE/8];
+    };
+} QBlockFormatInfo;
+
+/**
+ * QBlockStaticInfo: information about the block image.
+ *
+ * @loc: location information.
+ * @fmt: format information.
+ * @sector_size: how many bytes in a sector, it is 512 usually.
+ */
+typedef struct QBlockStaticInfo {
+    QBlockLocationInfo loc;
+    QBlockFormatInfo fmt;
+    int sector_size;
+} QBlockStaticInfo;
+
+
+#endif
libqblock/libqblock.c +0 -0
index 4c18c41..e69de29 100644

libqblock/libqblock.c line 6

Quoted 6 lines
libqblock/libqblock.c +0 -6
@@ -1,6 +0,0 @@
-#include "libqblock.h"
-
-int libqb_test(void)
-{
-    return 0;
-}

Why?

Quoted 11 lines
libqblock/libqblock.h +0 -1
index b0f9daf..e69de29 100644
@@ -1 +0,0 @@
-__attribute__((visibility("default"))) int libqb_test(void);
tests/check-libqblock-qcow2.c +0 -0
index 50a4df3..6f5ccac 100644

tests/check-libqblock-qcow2.c line 4

Quoted 4 lines
tests/check-libqblock-qcow2.c +0 -1
@@ -1,6 +1,5 @@
 #include "libqblock.h"
 int main(int argc, char **argv)
 {
-    libqb_test();

Why?

Quoted 3 lines
tests/check-libqblock-qcow2.c +0 -0
     return 0;
 }
#17 lore raw

Re: [Qemu-devel] [PATCH V10 6/7] libqblock API

In reply to Wenchao Xia

Il 20/11/2012 10:46, Wenchao Xia ha scritto:

libqblock/libqblock.h

Quoted 4 lines
libqblock/libqblock.h +0 -0
index e69de29..8ca7d28 100644

Please move the creation of this file to the previous patch.

I dislike QBlockState and would prefer something like QBlockImage...

Also, it would be nicer to use reference counting for QBlockImage, rather than just a new/delete pair.

There are some spelling mistakes (openned->opened).

But overall we're converging, it's good work that you've done. Thanks for persisting!

libqblock/libqblock.h

Quoted 8 lines
libqblock/libqblock.h +7 -0
+    byte_offset = offset & (~BDRV_SECTOR_MASK);
+    if (byte_offset != 0) {
+        /* the start sector is not alligned, need to read/write this sector. */
+        bd_ret = bdrv_read(bs, sector_start, temp_buf, 1);
+        if (bd_ret < 0) {
+            set_context_err(context, QB_ERR_INTERNAL_ERR,
+                           "QEMU internal block error.");

These are I/O errors, not internal errors.

Quoted 2 lines

+ if (length > 0x1000000000000) {

What is this magic number? I think, just remove the check.

Quoted 4 lines
libqblock/libqblock.h +4 -0
+        set_context_err(context, QB_ERR_INVALID_PARAM,
+                       "length is too big.");
+        goto out;
+    }

...

Quoted 52 lines
libqblock/libqblock.h +49 -0
+            context->err_no = bd_ret;
+            return context->err_ret;
+        }
+        cp_len = BDRV_SECTOR_SIZE - byte_offset;
+        memcpy(p, temp_buf + byte_offset, cp_len);
+
+        remains -= cp_len;
+        p += cp_len;
+        sector_start++;
+    }
+
+    /* now start position is alligned. */
+    if (remains >= BDRV_SECTOR_SIZE) {
+        sector_num = remains >> BDRV_SECTOR_BITS;
+        bd_ret = bdrv_read(bs, sector_start, p, sector_num);
+        if (bd_ret < 0) {
+            set_context_err(context, QB_ERR_INTERNAL_ERR,
+                           "QEMU internal block error.");
+            context->err_no = bd_ret;
+            return context->err_ret;
+        }
+        remains -= sector_num << BDRV_SECTOR_BITS;
+        p += sector_num << BDRV_SECTOR_BITS;
+        sector_start += sector_num;
+    }
+
+    if (remains > 0) {
+        /* there is some request remains, less than 1 sector */
+        bd_ret = bdrv_read(bs, sector_start, temp_buf, 1);
+        if (bd_ret < 0) {
+            set_context_err(context, QB_ERR_INTERNAL_ERR,
+                           "QEMU internal block error.");
+            context->err_no = bd_ret;
+            return context->err_ret;
+        }
+        memcpy(p, temp_buf, remains);
+        remains -= remains;
+    }
+
 
 
 
+int qb_info_image_static_get(QBlockContext *context,
+                             QBlockState *qbs,
+                             QBlockStaticInfo **info)
+{
+    int ret = 0;
+    BlockDriverState *bs;
+    QBlockStaticInfo *info_tmp;
+    QBlockStaticInfoAddr *member_addr, addr;
+    const char *fmt_str;
+    uint64_t total_sectors;

libqblock/libqblock.h

Quoted 10 lines
libqblock/libqblock.h +10 -0
+    char backing_filename[LIBQB_FILENAME_MAX];
+
+    if (qbs->filename == NULL) {
+        set_context_err(context, QB_ERR_INVALID_PARAM,
+                       "Block Image was not openned.");
+        ret = context->err_ret;
+        goto out;
+    }
+
+    info_tmp = FUNC_CALLOC(1, sizeof(QBlockStaticInfo));

Please rename info to p_info and info_tmp to info.

libqblock/libqblock.h

Quoted 4 lines
libqblock/libqblock.h +4 -0
+    bs = qbs->bdrvs;
+
+    ret = filename2loc(context,
+                       &(info_tmp->loc),

Useless parentheses around & argument. This is very common, please remove them.

libqblock/libqblock.h

Quoted 10 lines
libqblock/libqblock.h +10 -0
+                       qbs->filename);
+    if (ret < 0) {
+        goto free;
+    }
+
+    fmt_str = bdrv_get_format_name(bs);
+    info_tmp->fmt.fmt_type = qb_str2fmttype(fmt_str);
+    /* we got the format type and basic location info now, setup the struct
+    pointer to the internal members */
+    memset(&addr, 0, sizeof(QBlockStaticInfoAddr));

Please move these memsets to qb_setup_info_addr.

libqblock/libqblock.h

Quoted 2 lines
libqblock/libqblock.h +2 -0
+    member_addr = &addr;
+    qb_setup_info_addr(info_tmp, member_addr);

Just use qb_setup_info_addr(info_tmp, &addr).

libqblock/libqblock.h

Quoted 4 lines
libqblock/libqblock.h +4 -0
+
+    assert(member_addr->virt_size != NULL);
+    bdrv_get_geometry(bs, &total_sectors);
+    *(member_addr->virt_size) = total_sectors * BDRV_SECTOR_SIZE;

virt_size is always valid, please move it out of the unions and in the main struct.

Quoted 24 lines
libqblock/libqblock.h +24 -0
+    if (member_addr->encrypt != NULL) {
+        *(member_addr->encrypt) = bdrv_is_encrypted(bs);
+    }
+    bdrv_get_full_backing_filename(bs, backing_filename,
+                                   sizeof(backing_filename));
+    if (backing_filename[0] != '\0') {
+        assert(member_addr->backing_loc != NULL);
+        ret = filename2loc(context,
+                           member_addr->backing_loc,
+                           backing_filename);
+        if (ret < 0) {
+            goto free;
+        }
+    }
+
+    info_tmp->sector_size = BDRV_SECTOR_SIZE;
+    *info = info_tmp;
+
+ out:
+    return ret;
+ free:
+    qb_info_image_static_delete(context, &info_tmp);
+    return ret;
+}
#8 lore raw

Re: [Qemu-devel] [PATCH V10 4/7] libqblock build system

In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini

Mostly looks good...

Il 20/11/2012 10:46, Wenchao Xia ha scritto:

Quoted 1 line

+libqblock="yes"

Please make the default the empty string, i.e. "build if and only if libtool is present".

Do you mean adding a probe section later that if libtool is present,
its default is "yes", else set it to "no"?

Quoted 17 lines
Quoted 4 lines
configure +3 -0
+##########################################
+# libqblock probe
+if test "$libqblock" != "no" ; then

configure EOF · line 2371

Quoted 10 lines
configure +9 -0
+# libqblock depends on libtool, default to yes if libtool exist
+    if ! has $libtool; then
+        echo
+        echo "Warning: libqblock needs libtool"
+        echo "Setting libqblock option to no."
+        echo
+        libqblock="no"
+    fi
+fi
  #

Please fail here if libqblock=yes but libtool is not found.

OK.

Quoted 9 lines

libqblock/Makefile line 19

Quoted 4 lines
libqblock/Makefile new file +4 -0
+#library objects
+libqblock-obj-y= libqblock/libqblock.o libqblock/libqblock-error.o
+extra-obj-y= main-loop.o qemu-timer.o qemu-tool.o iohandler.o \
+             compatfd.o

Are all of these really necessary? Instead of main-loop/compatfd/iohandler, I think you can just add a new libqblock/libqblock-aio.c file, and copy these definitions from main-loop.c:

OK, good idea.

Quoted 12 lines

QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
void qemu_aio_flush(void)
bool qemu_aio_wait(void)
void qemu_aio_set_fd_handler(int fd,

                             IOHandler *io_read,
                             IOHandler *io_write,
                             AioFlushHandler *io_flush,
                             void *opaque);
void qemu_aio_set_event_notifier(EventNotifier *notifier,
                                 EventNotifierHandler *io_read,
                                 AioFlushEventNotifierHandler *io_flush);
Quoted 5 lines

and also include part of qemu_init_main_loop in the creation of a new QBlockContext (the first time it's called). We can later map each QBlockContext to a different AioContext. Please document somewhere that the library is not yet thread-safe.

OK.

Quoted 8 lines
Quoted 8 lines
tests/Makefile +0 -0
index ef6c9f2..997dbcc 100644
@@ -84,6 +84,23 @@ 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)
 
Quoted 12 lines

tests/Makefile check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET) · line 94

Quoted 8 lines
tests/Makefile +8 -0
+#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_DIR)
+LIBQBLOCK_TEST_DIR = tests/test_images
+LIBQBLOCK_DIR = libqblock
+LIBQBLOCK_SO = $(LIBQBLOCK_DIR)/.libs/libqblock.so
+LIBQBLOCK_SO_LINK_FLAG = -Wl,-rpath,$(LIBQBLOCK_DIR)/.libs

These two should not be required. Just link in libqblock/libqblock.la and libtool will do all of its magic.

OK.

Quoted 12 lines

Paolo

Quoted 8 lines
tests/Makefile +8 -0
+
+#use libtool to link check-libqblock, use LIBQBLOCK_SO_LINK_FLAG to add lib search diretory
+LTLINK_CHECK_LIBQBLOCK = $(call quiet-command, $(LIBTOOL) --mode=link --quiet --tag=CC \
+         $(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) $(LIBQBLOCK_SO_LINK_FLAG) \
+         -o $@ $(sort $(1)) $(LIBS), "lt LINK $(TARGET_DIR) $@")
+
+$(check-libqblock-y): %$(EXESUF): %.o
+	$(call LTLINK_CHECK_LIBQBLOCK, $^ $(LIBQBLOCK_SO))
Signature · 3 lines
Best Regards

Wenchao Xia
#13 lore raw

Re: [Qemu-devel] [PATCH V10 5/7] libqblock type defines

In reply to Paolo Bonzini
Quoted 33 lines · Paolo Bonzini

Il 20/11/2012 10:46, Wenchao Xia ha scritto:

Quoted 2 lines

This patch contains type and macro defines used in APIs, one file for public
usage, one for libqblock internal usage.

Mostly looks good, just a few questions below.

Quoted 27 lines
---
  libqblock/libqblock-internal.h |   75 ++++++++++++
  libqblock/libqblock-types.h    |  252 ++++++++++++++++++++++++++++++++++++++++
  libqblock/libqblock.c          |    6 -
  libqblock/libqblock.h          |    1 -
  tests/check-libqblock-qcow2.c  |    1 -
  5 files changed, 327 insertions(+), 8 deletions(-)

create mode 100644 libqblock/libqblock-internal.h

libqblock/libqblock-internal.h new file +11 -0
new file mode 100644
index 0000000..75c0452
@@ -0,0 +1,75 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * 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.
+ *
Quoted 9 lines

libqblock/libqblock-internal.h line 17

Quoted 6 lines
libqblock/libqblock-internal.h new file +6 -0
+ */
+
+#ifndef LIBQBLOCK_INTERNAL
+#define LIBQBLOCK_INTERNAL
+
+#include "glib.h"

Use <glib.h> please.

OK.

Quoted 6 lines

libqblock/libqblock-internal.h line 20

Quoted 3 lines
libqblock/libqblock-internal.h new file +3 -0
+
+#include "block.h"
+#include "block_int.h"

Is block_int.h really needed?

Some type define in it was used before, let me check if it can be
removed.

Quoted 10 lines

libqblock/libqblock-internal.h line 28

Quoted 8 lines
libqblock/libqblock-internal.h new file +8 -0
+#include "libqblock-types.h"
+
+/* this file contains defines and types used inside the library. */
+
+#define FUNC_FREE(p) g_free((p))
+#define FUNC_MALLOC(size) g_malloc((size))
+#define FUNC_CALLOC(nmemb, size) g_malloc0((nmemb)*(size))
+#define FUNC_STRDUP(p) g_strdup((p))

Why keep these?

This macro make it easy to switch mem related functions if we change
our mind in the future.

Quoted 8 lines

libqblock/libqblock-internal.h line 33

Quoted 5 lines
libqblock/libqblock-internal.h new file +5 -0
+
+#define CLEAN_FREE(p) { \
+        FUNC_FREE(p); \
+        (p) = NULL; \
+}

What about calling it QB_FREE?

OK.

Quoted 32 lines
Quoted 32 lines
libqblock/libqblock-internal.h new file +32 -0
+
+/* details should be hidden to user */
+struct QBlockState {
+    BlockDriverState *bdrvs;
+    /* internal used file name now, if it is not NULL, it means
+       image was opened.
+    */
+    char *filename;
+};
+
+struct QBlockContext {
+    /* last error */
+    GError *g_error;
+    int err_ret; /* 1st level of error, the libqblock error number */
+    int err_no; /* 2nd level of error, errno what below reports */
+};
+
+/**
+ * QBlockStaticInfoAddr: a structure contains a set of pointer.
+ *
+ *    this struct contains a set of pointer pointing to some
+ *  property related to format or protocol. If a property is not available,
+ *  it will be set as NULL. User could use this to get properties directly.
+ *
+ *  @virt_size: virtual size, it is always not NULL.
+ *  @backing_loc: backing file location.
+ *  @encrypt: encryption flag.
+*/
+
+typedef struct QBlockStaticInfoAddr {
+    uint64_t *virt_size;
+    QBlockLocationInfo *backing_loc;
Quoted 9 lines

libqblock/libqblock-internal.h line 71

Quoted 6 lines
libqblock/libqblock-internal.h new file +6 -0
+    bool *encrypt;
+} QBlockStaticInfoAddr;
+
+#define G_LIBQBLOCK_ERROR g_libqbock_error_quark()
+
+static inline GQuark g_libqbock_error_quark(void)

libqblock, not libqbock.

my mistake.

Quoted 214 lines
Quoted 214 lines
libqblock/libqblock-internal.h new file +4 -0
+{
+    return g_quark_from_static_string("g-libqblock-error-quark");
+}
+#endif
libqblock/libqblock-types.h +205 -0
index e69de29..77ad325 100644
@@ -0,0 +1,252 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * 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.
+ *
+ */
+
+#ifndef LIBQBLOCK_TYPES_H
+#define LIBQBLOCK_TYPES_H
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+    #ifdef LIBQB_BUILD
+        #define DLL_PUBLIC __attribute__((visibility("default")))
+    #else
+        #define DLL_PUBLIC
+    #endif
+#endif
+
+/* this library is designed around this core struct. */
+typedef struct QBlockState QBlockState;
+
+/* every thread should have a context. */
+typedef struct QBlockContext QBlockContext;
+
+/* flag used in open and create */
+#define LIBQBLOCK_O_RDWR        0x0002
+/* do not use the host page cache */
+#define LIBQBLOCK_O_NOCACHE     0x0020
+/* use write-back caching */
+#define LIBQBLOCK_O_CACHE_WB    0x0040
+/* don't open the backing file */
+#define LIBQBLOCK_O_NO_BACKING  0x0100
+/* disable flushing on this disk */
+#define LIBQBLOCK_O_NO_FLUSH    0x0200
+
+#define LIBQBLOCK_O_CACHE_MASK \
+   (LIBQBLOCK_O_NOCACHE | LIBQBLOCK_O_CACHE_WB | LIBQBLOCK_O_NO_FLUSH)
+
+#define LIBQBLOCK_O_VALID_MASK \
+   (LIBQBLOCK_O_RDWR | LIBQBLOCK_O_NOCACHE | LIBQBLOCK_O_CACHE_WB | \
+    LIBQBLOCK_O_NO_BACKING | LIBQBLOCK_O_NO_FLUSH)
+
+typedef enum QBlockProtocol {
+    QB_PROTO_NONE = 0,
+    QB_PROTO_FILE,
+    QB_PROTO_MAX
+} QBlockProtocol;
+
+typedef struct QBlockProtocolOptionsFile {
+    const char *filename;
+} QBlockProtocolOptionsFile;
+
+/**
+ * struct QBlockLocationInfo: contains information about how to find the image
+ *
+ * @prot_type: protocol type, now only support FILE.
+ * @o_file: file protocol related attributes.
+ * @reserved: reserved bytes for ABI.
+ */
+#define QBLOCK_PROT_OPTIONS_UNION_SIZE (512)
+typedef struct QBlockLocationInfo {
+    QBlockProtocol prot_type;
+    union {
+        QBlockProtocolOptionsFile o_file;
+        uint64_t reserved[QBLOCK_PROT_OPTIONS_UNION_SIZE/8];
+    };
+} QBlockLocationInfo;
+
+
+/* format related options */
+typedef enum QBlockFormat {
+    QB_FMT_NONE = 0,
+    QB_FMT_COW,
+    QB_FMT_QED,
+    QB_FMT_QCOW,
+    QB_FMT_QCOW2,
+    QB_FMT_RAW,
+    QB_FMT_RBD,
+    QB_FMT_SHEEPDOG,
+    QB_FMT_VDI,
+    QB_FMT_VMDK,
+    QB_FMT_VPC,
+    QB_FMT_MAX
+} QBlockFormat;
+
+typedef struct QBlockFormatOptionsCOW {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+} QBlockFormatOptionsCOW;
+
+typedef struct QBlockFormatOptionsQED {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    QBlockFormat backing_fmt;
+    uint64_t cluster_size; /* unit is bytes */
+    uint64_t table_size; /* unit is clusters */
+} QBlockFormatOptionsQED;
+
+typedef struct QBlockFormatOptionsQCOW {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    bool encrypt;
+} QBlockFormatOptionsQCOW;
+
+/* "Compatibility level (0.10 or 1.1)" */
+typedef enum QBlockFormatOptionsQCOW2CompatLv {
+    QB_FMT_QCOW2_COMPAT_DEFAULT = 0,
+    QB_FMT_QCOW2_COMPAT_V0_10,
+    QB_FMT_QCOW2_COMPAT_V1_10,
+} QBlockFormatOptionsQCOW2CompatLv;
+
+/* off or metadata */
+typedef enum QBlockFormatOptionsQCOW2PreAlloc {
+    QB_FMT_QCOW2_PREALLOC_DEFAULT = 0,
+    QB_FMT_QCOW2_PREALLOC_OFF,
+    QB_FMT_QCOW2_PREALLOC_METADATA,
+} QBlockFormatOptionsQCOW2PreAlloc;
+
+typedef struct QBlockFormatOptionsQCOW2 {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    QBlockFormat backing_fmt;
+    bool encrypt;
+    uint64_t cluster_size; /* unit is bytes */
+    QBlockFormatOptionsQCOW2CompatLv cpt_lv;
+    QBlockFormatOptionsQCOW2PreAlloc pre_mode;
+} QBlockFormatOptionsQCOW2;
+
+typedef struct QBlockFormatOptionsRAW {
+    uint64_t virt_size;
+} QBlockFormatOptionsRAW;
+
+typedef struct QBlockFormatOptionsRBD {
+    uint64_t virt_size;
+    uint64_t cluster_size;
+} QBlockFormatOptionsRBD;
+
+/* off or full */
+typedef enum QBlockFormatOptionsSDPreAlloc {
+    QB_FMT_SD_PREALLOC_DEFAULT = 0,
+    QB_FMT_SD_PREALLOC_OFF,
+    QB_FMT_SD_PREALLOC_FULL,
+} QBlockFormatOptionsSDPreAlloc;
+
+typedef struct QBlockFormatOptionsSD {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    QBlockFormatOptionsSDPreAlloc pre_mode;
+} QBlockFormatOptionsSD;
+
+typedef enum QBlockFormatOptionsVDIPreAlloc {
+    QB_FMT_VDI_PREALLOC_DEFAULT = 0,
+    QB_FMT_VDI_PREALLOC_OFF,
+    QB_FMT_VDI_PREALLOC_METADATA,
+} QBlockFormatOptionsVDIPreAlloc;
+
+typedef struct QBlockFormatOptionsVDI {
+    uint64_t virt_size;
+    uint64_t cluster_size;
+    QBlockFormatOptionsVDIPreAlloc pre_mode;
+} QBlockFormatOptionsVDI;
+
+/* whether compact to vmdk verion 6 */
+typedef enum QBlockFormatOptionsVMDKCompatLv {
+    QB_FMT_VMDK_COMPAT_DEFAULT = 0,
+    QB_FMT_VMDK_COMPAT_VMDKV6_FALSE,
+    QB_FMT_VMDK_COMPAT_VMDKV6_TRUE,
+} QBlockFormatOptionsVMDKCompatLv;
+
+/* vmdk flat extent format, values:
+"{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse |
+twoGbMaxExtentFlat | streamOptimized} */
+typedef enum QBlockFormatOptionsVMDKSubfmt {
+    QB_FMT_VMDK_SUBFMT_DEFAULT = 0,
+    QB_FMT_VMDK_SUBFMT_MONOLITHIC_SPARSE,
+    QB_FMT_VMDK_SUBFMT_MONOLITHIC_FLAT,
+    QB_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_SPARSE,
+    QB_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_FLAT,
+    QB_FMT_VMDK_SUBFMT_STREAM_OPTIMIZED,
+} QBlockFormatOptionsVMDKSubfmt;
+
+typedef struct QBlockFormatOptionsVMDK {
+    uint64_t virt_size;
+    QBlockLocationInfo backing_loc;
+    QBlockFormatOptionsVMDKCompatLv cpt_lv;
+    QBlockFormatOptionsVMDKSubfmt subfmt;
+} QBlockFormatOptionsVMDK;
+
+/* "{dynamic (default) | fixed} " */
+typedef enum QBlockFormatOptionsVPCSubfmt {
+    QB_FMT_VPC_SUBFMT_DEFAULT = 0,
+    QB_FMT_VPC_SUBFMT_DYNAMIC,
+    QB_FMT_VPC_SUBFMT_FIXED,
+} QBlockFormatOptionsVPCSubfmt;
+
Quoted 8 lines

libqblock/libqblock-types.h line 211

Quoted 6 lines
libqblock/libqblock-types.h +6 -0
+typedef struct QBlockFormatOptionsVPC {
+    uint64_t virt_size;
+    QBlockFormatOptionsVPCSubfmt subfmt;
+} QBlockFormatOptionsVPC;
+
+#define QBLOCK_FMT_OPTIONS_UNION_SIZE (QBLOCK_PROT_OPTIONS_UNION_SIZE*2)

Why?

QBlockFormatInfo contains QBlockLocationInfo for backing file in some
formats, so make this structure twice size as QBlockLocationInfo.

Quoted 47 lines
Quoted 47 lines
libqblock/libqblock-types.h +41 -0
+
+/**
+ * struct QBlockFormatInfo: contains information about how to retrieve data
+ *  from the image
+ *
+ * @fmt_type: format type.
+ * @o_cow~@o_vdi: format related attributes.
+ * @reserved: reserved bytes for ABI.
+ */
+typedef struct QBlockFormatInfo {
+    QBlockFormat fmt_type;
+    union {
+        QBlockFormatOptionsCOW       o_cow;
+        QBlockFormatOptionsQED       o_qed;
+        QBlockFormatOptionsQCOW      o_qcow;
+        QBlockFormatOptionsQCOW2     o_qcow2;
+        QBlockFormatOptionsRAW       o_raw;
+        QBlockFormatOptionsRBD       o_rbd;
+        QBlockFormatOptionsSD        o_sd;
+        QBlockFormatOptionsVDI       o_vdi;
+        QBlockFormatOptionsVMDK      o_vmdk;
+        QBlockFormatOptionsVPC       o_vpc;
+        uint64_t reserved[QBLOCK_FMT_OPTIONS_UNION_SIZE/8];
+    };
+} QBlockFormatInfo;
+
+/**
+ * QBlockStaticInfo: information about the block image.
+ *
+ * @loc: location information.
+ * @fmt: format information.
+ * @sector_size: how many bytes in a sector, it is 512 usually.
+ */
+typedef struct QBlockStaticInfo {
+    QBlockLocationInfo loc;
+    QBlockFormatInfo fmt;
+    int sector_size;
+} QBlockStaticInfo;
+
+
+#endif
libqblock/libqblock.c +0 -0
index 4c18c41..e69de29 100644
@@ -1,6 +0,0 @@
Quoted 9 lines

libqblock/libqblock.c line 6

Quoted 6 lines
libqblock/libqblock.c +0 -6
-#include "libqblock.h"
-
-int libqb_test(void)
-{
-    return 0;
-}

Why?

This function is used in build system patch to verify final
link is OK, it should be removed in next API patch, my mistake.

Quoted 22 lines
Quoted 11 lines
libqblock/libqblock.h +0 -1
index b0f9daf..e69de29 100644
@@ -1 +0,0 @@
-__attribute__((visibility("default"))) int libqb_test(void);
tests/check-libqblock-qcow2.c +0 -0
index 50a4df3..6f5ccac 100644

tests/check-libqblock-qcow2.c line 4

Quoted 4 lines
tests/check-libqblock-qcow2.c +0 -1
@@ -1,6 +1,5 @@
  #include "libqblock.h"
  int main(int argc, char **argv)
  {
-    libqb_test();

Why?

Quoted 3 lines
tests/check-libqblock-qcow2.c +0 -0
      return 0;
  }
Signature · 3 lines
Best Regards

Wenchao Xia
#18 lore raw

Re: [Qemu-devel] [PATCH V10 6/7] libqblock API

In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini

Il 20/11/2012 10:46, Wenchao Xia ha scritto:

libqblock/libqblock.h

Quoted 4 lines
libqblock/libqblock.h +0 -0
index e69de29..8ca7d28 100644

Please move the creation of this file to the previous patch.

It is first created in 4/7 build system patch, should it be changed or
add API defines into that patch?

Quoted 2 lines

I dislike QBlockState and would prefer something like QBlockImage...

OK, QBlockImage seems good to me too.

Quoted 2 lines

Also, it would be nicer to use reference counting for QBlockImage, rather than just a new/delete pair.

OK, will add.

Quoted 2 lines

There are some spelling mistakes (openned->opened).

My mistake, will fix it.

Quoted 3 lines

But overall we're converging, it's good work that you've done. Thanks for persisting!

It is my pleasure, thank u for carefully reviewing the patch.

Quoted 10 lines

libqblock/libqblock.h

Quoted 9 lines
libqblock/libqblock.h +7 -0
+    byte_offset = offset & (~BDRV_SECTOR_MASK);
+    if (byte_offset != 0) {
+        /* the start sector is not alligned, need to read/write this sector. */
+        bd_ret = bdrv_read(bs, sector_start, temp_buf, 1);
+        if (bd_ret < 0) {
+            set_context_err(context, QB_ERR_INTERNAL_ERR,
+                           "QEMU internal block error.");
Quoted 2 lines

These are I/O errors, not internal errors.

OK.

Quoted 11 lines
Quoted 2 lines

+ if (length > 0x1000000000000) {

What is this magic number? I think, just remove the check.

Quoted 4 lines
libqblock/libqblock.h +4 -0
+        set_context_err(context, QB_ERR_INVALID_PARAM,
+                       "length is too big.");
+        goto out;
+    }

...

This check is done to avoid silent fail in translating bytes to
sector number used in API
bdrv_is_allocated(bs, sector_start, sector_num, &num)
sector_num is uint_32, so this length should be no larger than
uint32<<BDRV_SECTOR_MASK.
Sorry this section had some problem and lacks document, make it
looks joke.... Will fix the check with precise size.

Quoted 57 lines
Quoted 57 lines
libqblock/libqblock.h +53 -0
+            context->err_no = bd_ret;
+            return context->err_ret;
+        }
+        cp_len = BDRV_SECTOR_SIZE - byte_offset;
+        memcpy(p, temp_buf + byte_offset, cp_len);
+
+        remains -= cp_len;
+        p += cp_len;
+        sector_start++;
+    }
+
+    /* now start position is alligned. */
+    if (remains >= BDRV_SECTOR_SIZE) {
+        sector_num = remains >> BDRV_SECTOR_BITS;
+        bd_ret = bdrv_read(bs, sector_start, p, sector_num);
+        if (bd_ret < 0) {
+            set_context_err(context, QB_ERR_INTERNAL_ERR,
+                           "QEMU internal block error.");
+            context->err_no = bd_ret;
+            return context->err_ret;
+        }
+        remains -= sector_num << BDRV_SECTOR_BITS;
+        p += sector_num << BDRV_SECTOR_BITS;
+        sector_start += sector_num;
+    }
+
+    if (remains > 0) {
+        /* there is some request remains, less than 1 sector */
+        bd_ret = bdrv_read(bs, sector_start, temp_buf, 1);
+        if (bd_ret < 0) {
+            set_context_err(context, QB_ERR_INTERNAL_ERR,
+                           "QEMU internal block error.");
+            context->err_no = bd_ret;
+            return context->err_ret;
+        }
+        memcpy(p, temp_buf, remains);
+        remains -= remains;
+    }
+
 
 
 
+int qb_info_image_static_get(QBlockContext *context,
+                             QBlockState *qbs,
+                             QBlockStaticInfo **info)
+{
+    int ret = 0;
+    BlockDriverState *bs;
+    QBlockStaticInfo *info_tmp;
+    QBlockStaticInfoAddr *member_addr, addr;
+    const char *fmt_str;
+    uint64_t total_sectors;
+    char backing_filename[LIBQB_FILENAME_MAX];
+
+    if (qbs->filename == NULL) {
+        set_context_err(context, QB_ERR_INVALID_PARAM,
Quoted 9 lines

libqblock/libqblock.h

Quoted 6 lines
libqblock/libqblock.h +6 -0
+                       "Block Image was not openned.");
+        ret = context->err_ret;
+        goto out;
+    }
+
+    info_tmp = FUNC_CALLOC(1, sizeof(QBlockStaticInfo));

Please rename info to p_info and info_tmp to info.

OK.

Quoted 8 lines

libqblock/libqblock.h

Quoted 4 lines
libqblock/libqblock.h +4 -0
+    bs = qbs->bdrvs;
+
+    ret = filename2loc(context,
+                       &(info_tmp->loc),

Useless parentheses around & argument. This is very common, please remove them.

OK.

Quoted 11 lines

libqblock/libqblock.h

Quoted 10 lines
libqblock/libqblock.h +10 -0
+                       qbs->filename);
+    if (ret < 0) {
+        goto free;
+    }
+
+    fmt_str = bdrv_get_format_name(bs);
+    info_tmp->fmt.fmt_type = qb_str2fmttype(fmt_str);
+    /* we got the format type and basic location info now, setup the struct
+    pointer to the internal members */
+    memset(&addr, 0, sizeof(QBlockStaticInfoAddr));
Quoted 2 lines

Please move these memsets to qb_setup_info_addr.

OK.

Quoted 5 lines

libqblock/libqblock.h

Quoted 2 lines
libqblock/libqblock.h +2 -0
+    member_addr = &addr;
+    qb_setup_info_addr(info_tmp, member_addr);

Just use qb_setup_info_addr(info_tmp, &addr).

OK.

Quoted 8 lines

libqblock/libqblock.h

Quoted 4 lines
libqblock/libqblock.h +4 -0
+
+    assert(member_addr->virt_size != NULL);
+    bdrv_get_geometry(bs, &total_sectors);
+    *(member_addr->virt_size) = total_sectors * BDRV_SECTOR_SIZE;

virt_size is always valid, please move it out of the unions and in the main struct.

OK.

Quoted 25 lines
Quoted 24 lines
libqblock/libqblock.h +24 -0
+    if (member_addr->encrypt != NULL) {
+        *(member_addr->encrypt) = bdrv_is_encrypted(bs);
+    }
+    bdrv_get_full_backing_filename(bs, backing_filename,
+                                   sizeof(backing_filename));
+    if (backing_filename[0] != '\0') {
+        assert(member_addr->backing_loc != NULL);
+        ret = filename2loc(context,
+                           member_addr->backing_loc,
+                           backing_filename);
+        if (ret < 0) {
+            goto free;
+        }
+    }
+
+    info_tmp->sector_size = BDRV_SECTOR_SIZE;
+    *info = info_tmp;
+
+ out:
+    return ret;
+ free:
+    qb_info_image_static_delete(context, &info_tmp);
+    return ret;
+}
Signature · 3 lines
Best Regards

Wenchao Xia
#9 lore raw

Re: [Qemu-devel] [PATCH V10 4/7] libqblock build system

In reply to Wenchao Xia

Il 21/11/2012 04:03, Wenchao Xia ha scritto:

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

+libqblock="yes"

Please make the default the empty string, i.e. "build if and only if libtool is present".

Do you mean adding a probe section later that if libtool is present,
its default is "yes", else set it to "no"?

Here, you just do libqblock="".

Then --enable-libqblock and --disable-libqblock set it to yes or no.

Then, if $libqblock = yes, and no libtool, fail.

If $libqblock is empty, and no libtool, set it to no.

If $libqblock is empty, and libtool is there, set it to yes.

Paolo

#19 lore raw

Re: [Qemu-devel] [PATCH V10 6/7] libqblock API

In reply to Wenchao Xia

Il 21/11/2012 04:40, Wenchao Xia ha scritto:

Quoted 5 lines
Quoted 3 lines

Please move the creation of this file to the previous patch.

It is first created in 4/7 build system patch, should it be changed or
add API defines into that patch?

I mean add API defines in 5/7.

Paolo

#14 lore raw

Re: [Qemu-devel] [PATCH V10 5/7] libqblock type defines

In reply to Wenchao Xia

Il 21/11/2012 04:12, Wenchao Xia ha scritto:

Quoted 10 lines
Quoted 7 lines

libqblock/libqblock-internal.h line 28

Quoted 5 lines
libqblock/libqblock-internal.h new file +4 -0
+#define FUNC_FREE(p) g_free((p))
+#define FUNC_MALLOC(size) g_malloc((size))
+#define FUNC_CALLOC(nmemb, size) g_malloc0((nmemb)*(size))
+#define FUNC_STRDUP(p) g_strdup((p))

Why keep these?

This macro make it easy to switch mem related functions if we change
our mind in the future.

I don't like it particularly.

If you really want it, keep it, but please use g_malloc0_n for FUNC_CALLOC.

Paolo

Reviewed-by on v10 1/7
#2 lore raw

Re: [Qemu-devel] [PATCH V10 1/7] Buildsystem fix distclean error for pixman

In reply to Wenchao Xia
Quoted 4 lines · Wenchao Xia

Currently Makefile test if pixman have configure log, but the script directly
return error if that file do not exist. This patch fix it.

v2: print out the command.

We need this patch in 1.3 because otherwise 'distclean' barfs if you're using internal pixman. This would be clearer if it was a separate patch and not part of this libqblock series (which is not for 1.3 as far as I know).

Quoted 1 line

thanks
-- PMM

Quoted 20 lines
---
 Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -2
index 3e8d441..9ecbcbb 100644
@@ -286,7 +286,7 @@ distclean: clean
        for d in $(TARGET_DIRS) $(QEMULIBS); do \
        rm -rf $$d || exit 1 ; \
         done
-       test -f pixman/config.log && make -C pixman distclean
+       if test -f pixman/config.log; then make -C pixman distclean; fi
 
 KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  modifiers  no  pt-br  sv \
 ar      de     en-us  fi  fr-be  hr     it  lv  nl         pl  ru     th \
--

1.7.1

#10 lore raw

Re: [Qemu-devel] [PATCH V10 4/7] libqblock build system

In reply to Paolo Bonzini
Quoted 14 lines · Paolo Bonzini

Il 21/11/2012 04:03, Wenchao Xia ha scritto:

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

+libqblock="yes"

Please make the default the empty string, i.e. "build if and only if libtool is present".

Do you mean adding a probe section later that if libtool is present,
its default is "yes", else set it to "no"?

Here, you just do libqblock="".

Then --enable-libqblock and --disable-libqblock set it to yes or no.

Quoted 8 lines

Then, if $libqblock = yes, and no libtool, fail.

If $libqblock is empty, and no libtool, set it to no.

If $libqblock is empty, and libtool is there, set it to yes.

Paolo

got it, will change it as comments.

Signature · 3 lines
Best Regards

Wenchao Xia
#20 lore raw

Re: [Qemu-devel] [PATCH V10 6/7] libqblock API

In reply to Paolo Bonzini
Quoted 11 lines · Paolo Bonzini

Il 21/11/2012 04:40, Wenchao Xia ha scritto:

Quoted 5 lines
Quoted 3 lines

Please move the creation of this file to the previous patch.

It is first created in 4/7 build system patch, should it be changed or
add API defines into that patch?

I mean add API defines in 5/7.

Paolo

OK.

Signature · 3 lines
Best Regards

Wenchao Xia
#15 lore raw

Re: [Qemu-devel] [PATCH V10 5/7] libqblock type defines

In reply to Paolo Bonzini
Quoted 9 lines · Paolo Bonzini

Il 21/11/2012 04:12, Wenchao Xia ha scritto:

Quoted 8 lines
Quoted 7 lines

libqblock/libqblock-internal.h line 28

Quoted 5 lines
libqblock/libqblock-internal.h new file +4 -0
+#define FUNC_FREE(p) g_free((p))
+#define FUNC_MALLOC(size) g_malloc((size))
+#define FUNC_CALLOC(nmemb, size) g_malloc0((nmemb)*(size))
+#define FUNC_STRDUP(p) g_strdup((p))

Why keep these?

Quoted 9 lines
Quoted 2 lines

This macro make it easy to switch mem related functions if we change
our mind in the future.

I don't like it particularly.

If you really want it, keep it, but please use g_malloc0_n for FUNC_CALLOC.

Paolo

OK.

Signature · 3 lines
Best Regards

Wenchao Xia
#3 lore raw

Re: [Qemu-devel] [PATCH V10 1/7] Buildsystem fix distclean error for pixman

In reply to Peter Maydell
Quoted 33 lines · Peter Maydell
Quoted 4 lines · Wenchao Xia

Currently Makefile test if pixman have configure log, but the script directly
return error if that file do not exist. This patch fix it.

v2: print out the command.

We need this patch in 1.3 because otherwise 'distclean' barfs if you're using internal pixman. This would be clearer if it was a separate patch and not part of this libqblock series (which is not for 1.3 as far as I know).

Quoted 1 line

thanks
-- PMM

Quoted 15 lines
---
  Makefile |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
index 3e8d441..9ecbcbb 100644
@@ -286,7 +286,7 @@ distclean: clean
         for d in $(TARGET_DIRS) $(QEMULIBS); do \
         rm -rf $$d || exit 1 ; \
          done
-       test -f pixman/config.log && make -C pixman distclean
+       if test -f pixman/config.log; then make -C pixman distclean; fi
 
Quoted 6 lines
Quoted 5 lines
Makefile +0 -1
  KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  modifiers  no  pt-br  sv \
  ar      de     en-us  fi  fr-be  hr     it  lv  nl         pl  ru     th \
--

1.7.1

will sent a separate patch, thanks.

Signature · 3 lines
Best Regards

Wenchao Xia