Skip to contentSkip to conversation

libqblock qemu block layer library

PATCH Superseded Wenchao Xia 2 participants 18 messages Sep 18, 2012 – Sep 27, 2012 Kbuild

v3 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v3 cover libqblock qemu block layer library

This patch introduce libqblock API, make libqblock.la 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.

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.

Wenchao Xia (5):
libqblock build system
libqblock type defines
libqblock API
libqblock test build system
libqblock test example code

 .gitignore                       |    1 +
 Makefile                         |   14 +-
 Makefile.objs                    |    6 +
 block.c                          |    2 +-
 block.h                          |    1 +
 libqblock/Makefile               |   64 +++
 libqblock/libqblock-error.c      |   57 ++
 libqblock/libqblock-error.h      |   49 ++
 libqblock/libqblock-internal.h   |   56 ++
 libqblock/libqblock-types.h      |  268 +++++++++
 libqblock/libqblock.c            | 1140 ++++++++++++++++++++++++++++++++++++++
 libqblock/libqblock.h            |  297 ++++++++++
 tests/Makefile                   |    3 +
 tests/libqblock/Makefile         |   32 ++
 tests/libqblock/libqblock-test.c |  237 ++++++++
 15 files changed, 2225 insertions(+), 2 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 tests/libqblock/Makefile
 create mode 100644 tests/libqblock/libqblock-test.c
#1 lore raw

PATCH v3 1/5 libqblock build system

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.

---
 Makefile                    |   13 ++++++++-
 Makefile.objs               |    6 ++++
 libqblock/Makefile          |   64 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 1 deletions(-)
 create mode 100644 libqblock/Makefile
 create mode 100644 libqblock/libqblock-error.c
 create mode 100644 libqblock/libqblock.c
Makefile +12 -1
index 971e92f..b0b9b8d 100644
@@ -164,6 +164,17 @@ qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
+######################################################################
+# Support building shared library libqblock
+ifeq ($(LIBTOOL),)
+$(libqblock-lib-la):
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+$(libqblock-lib-la):
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" $(libqblock-lib-la),)
+endif
+###########################################################################
+
 vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) $(tools-obj-y) qemu-timer-common.o libcacard/vscclient.o
 	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
 
@@ -227,7 +238,7 @@ clean:
 	rm -rf qapi-generated
 	rm -rf qga/qapi-generated
 	$(MAKE) -C tests/tcg 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
Makefile.objs +6 -0
index 4412757..8a4c9fc 100644
@@ -248,3 +248,9 @@ nested-vars += \
 	common-obj-y \
 	extra-obj-y
 dummy := $(call unnest-vars)
+
+#############################################################################
+# libqblock
+
+libqblock-lib-la = libqblock.la
+libqblock-lib-path = libqblock
libqblock/Makefile new file +64 -0

64 lines not on this page · raw message

libqblock/libqblock-error.c new file +0 -0
new file mode 100644
index 0000000..e69de29
libqblock/libqblock.c new file +0 -0
new file mode 100644
index 0000000..e69de29
Signature · 1 line
1.7.1
#2 lore raw

Re: [Qemu-devel] [PATCH V3 1/5] libqblock build system

Il 18/09/2012 11:01, Wenchao Xia ha scritto:

Quoted 81 lines

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.

---
 Makefile                    |   13 ++++++++-
 Makefile.objs               |    6 ++++
 libqblock/Makefile          |   64 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 1 deletions(-)
 create mode 100644 libqblock/Makefile
 create mode 100644 libqblock/libqblock-error.c
 create mode 100644 libqblock/libqblock.c
Makefile +12 -1
index 971e92f..b0b9b8d 100644
@@ -164,6 +164,17 @@ qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
+######################################################################
+# Support building shared library libqblock
+ifeq ($(LIBTOOL),)
+$(libqblock-lib-la):
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+$(libqblock-lib-la):
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" $(libqblock-lib-la),)
+endif
+###########################################################################
+
 vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) $(tools-obj-y) qemu-timer-common.o libcacard/vscclient.o
 	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
 
@@ -227,7 +238,7 @@ clean:
 	rm -rf qapi-generated
 	rm -rf qga/qapi-generated
 	$(MAKE) -C tests/tcg 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
Makefile.objs +6 -0
index 4412757..8a4c9fc 100644
@@ -248,3 +248,9 @@ nested-vars += \
 	common-obj-y \
 	extra-obj-y
 dummy := $(call unnest-vars)
+
+#############################################################################
+# libqblock
+
+libqblock-lib-la = libqblock.la
+libqblock-lib-path = libqblock
libqblock/Makefile new file +13 -0
new file mode 100644
index 0000000..bf7abcc
@@ -0,0 +1,64 @@
+###########################################################################
+# libqblock Makefile
+# Todo:
+#    1 trace related files is generated in this directory, move
+#  them to the root directory.
+##########################################################################
+-include ../config-host.mak
+-include $(SRC_PATH)/Makefile.objs
+-include $(SRC_PATH)/rules.mak
+
+#############################################################################
+# Library settings
+#############################################################################

libqblock/Makefile line 23

Quoted 10 lines
libqblock/Makefile new file +10 -0
+$(call set-vpath, $(SRC_PATH))
+
+#expand the foldered vars,especially ./block
+dummy := $(call unnest-vars-1)
+
+#library objects
+tools-obj-y = $(oslib-obj-y) $(trace-obj-y) qemu-tool.o qemu-timer.o \
+	qemu-timer-common.o main-loop.o notify.o \
+	iohandler.o cutils.o iov.o async.o
+tools-obj-$(CONFIG_POSIX) += compatfd.o

Do you really need all of these?

(BTW, I posted recently a patch to move tools-obj-y to Makefile.objs. It doesn't apply anymore, I'll repost---but the conflicts are trivial).

libqblock/Makefile line 29

Quoted 5 lines
libqblock/Makefile new file +5 -0
+libqblock-y=libqblock.o libqblock-error.o
+libqblock-lib-y=$(patsubst %.o,%.lo,$(libqblock-y))
+
+QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
+QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))

What does this filter out?

Paolo

Quoted 42 lines
libqblock/Makefile new file +35 -0
+QEMU_OBJS_LIB=$(patsubst %.o, %.lo,$(QEMU_OBJS_FILTERED))
+
+QEMU_CFLAGS+= -I../ -I../include
+#adding magic macro define for symbol hiding and exposing
+QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
+
+#dependency libraries
+LIBS+=-lz $(LIBS_TOOLS)
+
+#################################################################
+# Runtime rules
+#################################################################
+clean:
+	rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp
+	rm -rf .libs block trace
+
+all: libqblock-test
+	@true
+
+help:
+	@echo type make libqblock-test at root dirtory, libtool is required
+
+#make dir block at runtime which would hold the output of block/*.c
+block:
+	@mkdir block
+
+ifeq ($(LIBTOOL),)
+$(libqblock-lib-la):
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+$(libqblock-lib-la): $(libqblock-lib-y) $(QEMU_OBJS_LIB)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
+endif
+
+.PHONY: libqblock.la
libqblock/libqblock-error.c new file +0 -0
new file mode 100644
index 0000000..e69de29
libqblock/libqblock.c new file +0 -0
new file mode 100644
index 0000000..e69de29
#3 lore raw

Re: [Qemu-devel] [PATCH V3 1/5] libqblock build system

Quoted 86 lines · Paolo Bonzini

Il 18/09/2012 11:01, Wenchao Xia ha scritto:

Quoted 85 lines

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.

---
  Makefile                    |   13 ++++++++-
  Makefile.objs               |    6 ++++
  libqblock/Makefile          |   64 +++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 82 insertions(+), 1 deletions(-)

create mode 100644 libqblock/Makefile
create mode 100644 libqblock/libqblock-error.c
create mode 100644 libqblock/libqblock.c

Makefile +12 -1
index 971e92f..b0b9b8d 100644
@@ -164,6 +164,17 @@ qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)
 
  qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
+######################################################################
+# Support building shared library libqblock
+ifeq ($(LIBTOOL),)
+$(libqblock-lib-la):
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+$(libqblock-lib-la):
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" $(libqblock-lib-la),)
+endif
+###########################################################################
+
  vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) $(tools-obj-y) qemu-timer-common.o libcacard/vscclient.o
  	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
 
@@ -227,7 +238,7 @@ clean:
  	rm -rf qapi-generated
  	rm -rf qga/qapi-generated
  	$(MAKE) -C tests/tcg 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
Makefile.objs +6 -0
index 4412757..8a4c9fc 100644
@@ -248,3 +248,9 @@ nested-vars += \
  	common-obj-y \
  	extra-obj-y
  dummy := $(call unnest-vars)
+
+#############################################################################
+# libqblock
+
+libqblock-lib-la = libqblock.la
+libqblock-lib-path = libqblock
libqblock/Makefile new file +17 -0
new file mode 100644
index 0000000..bf7abcc
@@ -0,0 +1,64 @@
+###########################################################################
+# libqblock Makefile
+# Todo:
+#    1 trace related files is generated in this directory, move
+#  them to the root directory.
+##########################################################################
+-include ../config-host.mak
+-include $(SRC_PATH)/Makefile.objs
+-include $(SRC_PATH)/rules.mak
+
+#############################################################################
+# Library settings
+#############################################################################
+$(call set-vpath, $(SRC_PATH))
+
+#expand the foldered vars,especially ./block
+dummy := $(call unnest-vars-1)
Quoted 9 lines

libqblock/Makefile line 23

Quoted 6 lines
libqblock/Makefile new file +6 -0
+
+#library objects
+tools-obj-y = $(oslib-obj-y) $(trace-obj-y) qemu-tool.o qemu-timer.o \
+	qemu-timer-common.o main-loop.o notify.o \
+	iohandler.o cutils.o iov.o async.o
+tools-obj-$(CONFIG_POSIX) += compatfd.o

Do you really need all of these?

I guess only some .o are needed, but not sure how to pick them out,
is there some tools which can help detect which object files are needed in final linkage?

Quoted 3 lines

(BTW, I posted recently a patch to move tools-obj-y to Makefile.objs. It doesn't apply anymore, I'll repost---but the conflicts are trivial).

greate, then I can use tools-obj-y directly.

Quoted 8 lines

libqblock/Makefile line 29

Quoted 5 lines
libqblock/Makefile new file +5 -0
+libqblock-y=libqblock.o libqblock-error.o
+libqblock-lib-y=$(patsubst %.o,%.lo,$(libqblock-y))
+
+QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
+QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))

What does this filter out?

$(block-obj-y) contains /block, which would cause trouble in building,
so filtered it out.

Quoted 45 lines

Paolo

Quoted 42 lines
libqblock/Makefile new file +35 -0
+QEMU_OBJS_LIB=$(patsubst %.o, %.lo,$(QEMU_OBJS_FILTERED))
+
+QEMU_CFLAGS+= -I../ -I../include
+#adding magic macro define for symbol hiding and exposing
+QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
+
+#dependency libraries
+LIBS+=-lz $(LIBS_TOOLS)
+
+#################################################################
+# Runtime rules
+#################################################################
+clean:
+	rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp
+	rm -rf .libs block trace
+
+all: libqblock-test
+	@true
+
+help:
+	@echo type make libqblock-test at root dirtory, libtool is required
+
+#make dir block at runtime which would hold the output of block/*.c
+block:
+	@mkdir block
+
+ifeq ($(LIBTOOL),)
+$(libqblock-lib-la):
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+$(libqblock-lib-la): $(libqblock-lib-y) $(QEMU_OBJS_LIB)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
+endif
+
+.PHONY: libqblock.la
libqblock/libqblock-error.c new file +0 -0
new file mode 100644
index 0000000..e69de29
libqblock/libqblock.c new file +0 -0
new file mode 100644
index 0000000..e69de29
Signature · 3 lines
Best Regards

Wenchao Xia
#4 lore raw

Re: [Qemu-devel] [PATCH V3 1/5] libqblock build system

Il 19/09/2012 08:35, Wenchao Xia ha scritto:

Quoted 8 lines
Quoted 6 lines

libqblock/Makefile line 29

Quoted 3 lines
libqblock/Makefile new file +2 -0
+QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
+QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))

What does this filter out?

$(block-obj-y) contains /block, which would cause trouble in building,
so filtered it out.

I think that's because you have to call unnest-vars, not unnest-vars-1.

Paolo

#5 lore raw

Re: [Qemu-devel] [PATCH V3 1/5] libqblock build system

Quoted 7 lines · Paolo Bonzini

Il 19/09/2012 08:35, Wenchao Xia ha scritto:

Quoted 6 lines
Quoted 6 lines

libqblock/Makefile line 29

Quoted 3 lines
libqblock/Makefile new file +2 -0
+QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
+QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))

What does this filter out?

Quoted 7 lines
Quoted 2 lines

$(block-obj-y) contains /block, which would cause trouble in building,
so filtered it out.

I think that's because you have to call unnest-vars, not unnest-vars-1.

Paolo

Tried with unnest-vars, it will create some unnessary directories in
./libqblock, unnest-vars-1 seems more reasonable.

Signature · 3 lines
Best Regards

Wenchao Xia
#6 lore raw

Re: [Qemu-devel] [PATCH V3 1/5] libqblock build system

Il 27/09/2012 04:15, Wenchao Xia ha scritto:

Quoted 12 lines
Quoted 11 lines · Paolo Bonzini

Il 19/09/2012 08:35, Wenchao Xia ha scritto:

Quoted 9 lines
Quoted 6 lines

libqblock/Makefile line 29

Quoted 3 lines
libqblock/Makefile new file +2 -0
+QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
+QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))

What does this filter out?

$(block-obj-y) contains /block, which would cause trouble in
building,
so filtered it out.

Quoted 6 lines
Quoted 4 lines

I think that's because you have to call unnest-vars, not unnest-vars-1.

Paolo

Tried with unnest-vars, it will create some unnessary directories in
./libqblock, unnest-vars-1 seems more reasonable.

Don't worry about unnecessary directories, worry about correctness.

Paolo

#7 lore raw

Re: [Qemu-devel] [PATCH V3 1/5] libqblock build system

In reply to Wenchao Xia

Il 18/09/2012 11:01, Wenchao Xia ha scritto:

Quoted 81 lines

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.

---
 Makefile                    |   13 ++++++++-
 Makefile.objs               |    6 ++++
 libqblock/Makefile          |   64 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 1 deletions(-)
 create mode 100644 libqblock/Makefile
 create mode 100644 libqblock/libqblock-error.c
 create mode 100644 libqblock/libqblock.c
Makefile +12 -1
index 971e92f..b0b9b8d 100644
@@ -164,6 +164,17 @@ qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
+######################################################################
+# Support building shared library libqblock
+ifeq ($(LIBTOOL),)
+$(libqblock-lib-la):
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+$(libqblock-lib-la):
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" $(libqblock-lib-la),)
+endif
+###########################################################################
+
 vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) $(tools-obj-y) qemu-timer-common.o libcacard/vscclient.o
 	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
 
@@ -227,7 +238,7 @@ clean:
 	rm -rf qapi-generated
 	rm -rf qga/qapi-generated
 	$(MAKE) -C tests/tcg 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
Makefile.objs +6 -0
index 4412757..8a4c9fc 100644
@@ -248,3 +248,9 @@ nested-vars += \
 	common-obj-y \
 	extra-obj-y
 dummy := $(call unnest-vars)
+
+#############################################################################
+# libqblock
+
+libqblock-lib-la = libqblock.la
+libqblock-lib-path = libqblock
libqblock/Makefile new file +13 -0
new file mode 100644
index 0000000..bf7abcc
@@ -0,0 +1,64 @@
+###########################################################################
+# libqblock Makefile
+# Todo:
+#    1 trace related files is generated in this directory, move
+#  them to the root directory.
+##########################################################################
+-include ../config-host.mak
+-include $(SRC_PATH)/Makefile.objs
+-include $(SRC_PATH)/rules.mak
+
+#############################################################################
+# Library settings
+#############################################################################

libqblock/Makefile line 23

Quoted 10 lines
libqblock/Makefile new file +10 -0
+$(call set-vpath, $(SRC_PATH))
+
+#expand the foldered vars,especially ./block
+dummy := $(call unnest-vars-1)
+
+#library objects
+tools-obj-y = $(oslib-obj-y) $(trace-obj-y) qemu-tool.o qemu-timer.o \
+	qemu-timer-common.o main-loop.o notify.o \
+	iohandler.o cutils.o iov.o async.o
+tools-obj-$(CONFIG_POSIX) += compatfd.o

Do you really need all of these?

(BTW, I posted recently a patch to move tools-obj-y to Makefile.objs. It doesn't apply anymore, I'll repost---but the conflicts are trivial).

libqblock/Makefile line 29

Quoted 5 lines
libqblock/Makefile new file +5 -0
+libqblock-y=libqblock.o libqblock-error.o
+libqblock-lib-y=$(patsubst %.o,%.lo,$(libqblock-y))
+
+QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
+QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))

What does this filter out?

Quoted 7 lines
libqblock/Makefile new file +7 -0
+QEMU_OBJS_LIB=$(patsubst %.o, %.lo,$(QEMU_OBJS_FILTERED))
+
+QEMU_CFLAGS+= -I../ -I../include
+#adding magic macro define for symbol hiding and exposing
+QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
+
+#dependency libraries

libqblock/Makefile line 46

Quoted 10 lines
libqblock/Makefile new file +10 -0
+LIBS+=-lz $(LIBS_TOOLS)
+
+#################################################################
+# Runtime rules
+#################################################################
+clean:
+	rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp
+	rm -rf .libs block trace
+
+all: libqblock-test

Do not put yet the libqblock-test rules in here, please.

Paolo

Quoted 25 lines
libqblock/Makefile new file +18 -0
+	@true
+
+help:
+	@echo type make libqblock-test at root dirtory, libtool is required
+
+#make dir block at runtime which would hold the output of block/*.c
+block:
+	@mkdir block
+
+ifeq ($(LIBTOOL),)
+$(libqblock-lib-la):
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+$(libqblock-lib-la): $(libqblock-lib-y) $(QEMU_OBJS_LIB)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
+endif
+
+.PHONY: libqblock.la
libqblock/libqblock-error.c new file +0 -0
new file mode 100644
index 0000000..e69de29
libqblock/libqblock.c new file +0 -0
new file mode 100644
index 0000000..e69de29
#8 lore raw

PATCH v3 2/5 libqblock type defines

In reply to Wenchao Xia

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

---
 libqblock/libqblock-internal.h |   56 +++++++++
 libqblock/libqblock-types.h    |  268 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 324 insertions(+), 0 deletions(-)
 create mode 100644 libqblock/libqblock-internal.h
 create mode 100644 libqblock/libqblock-types.h
libqblock/libqblock-internal.h new file +56 -0
new file mode 100644
index 0000000..87f32be
@@ -0,0 +1,56 @@
+/*
+ * 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 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 QBroker {
+    /* 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 */
+};
+
+#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 new file +268 -0

268 lines not on this page · raw message

Signature · 1 line
1.7.1
#9 lore raw

Re: [Qemu-devel] [PATCH V3 2/5] libqblock type defines

Il 18/09/2012 11:01, Wenchao Xia ha scritto:

Quoted 55 lines

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

---
 libqblock/libqblock-internal.h |   56 +++++++++
 libqblock/libqblock-types.h    |  268 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 324 insertions(+), 0 deletions(-)
 create mode 100644 libqblock/libqblock-internal.h
 create mode 100644 libqblock/libqblock-types.h
libqblock/libqblock-internal.h new file +38 -0
new file mode 100644
index 0000000..87f32be
@@ -0,0 +1,56 @@
+/*
+ * 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 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.

libqblock/libqblock-internal.h line 48

Quoted 10 lines
libqblock/libqblock-internal.h new file +10 -0
+    */
+    char *filename;
+} ;
+
+struct QBroker {
+    /* 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 */
+};

Sorry for keeping on bikeshedding---a better name for this is QBlockContext. "Context" is a well-known name for this kind of global object.

Otherwise looks good---thanks for putting up with us! :)

Paolo

Quoted 282 lines
libqblock/libqblock-internal.h new file +7 -0
+#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 new file +268 -0
new file mode 100644
index 0000000..3c548b8
@@ -0,0 +1,268 @@
+/*
+ * 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
+#else
+    #warning : gcc compiler version < 4, symbols can not be hidden.
+#endif
+
+/* this library is designed around this core struct. */
+typedef struct QBlockState QBlockState;
+
+/* every thread should have a broker. */
+typedef struct QBroker QBroker;
+
+/* 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 QBlockProtType {
+    QB_PROT_NONE = 0,
+    QB_PROT_FILE,
+    QB_PROT_MAX
+} QBlockProtType;
+
+typedef struct QBlockProtOptionFile {
+    const char *filename;
+} QBlockProtOptionFile;
+
+#define QBLOCK_PROT_OPTIONS_UNION_SIZE (512)
+typedef union QBlockProtOptionsUnion {
+    QBlockProtOptionFile o_file;
+    uint8_t reserved[QBLOCK_PROT_OPTIONS_UNION_SIZE];
+} QBlockProtOptionsUnion;
+
+/**
+ * struct QBlockProtInfo: contains information about how to find the image
+ *
+ * @prot_type: protocol type, now only support FILE.
+ * @prot_op: protocol related options.
+ */
+typedef struct QBlockProtInfo {
+    QBlockProtType prot_type;
+    QBlockProtOptionsUnion prot_op;
+} QBlockProtInfo;
+
+
+/* format related options */
+typedef enum QBlockFmtType {
+    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
+} QBlockFmtType;
+
+typedef struct QBlockFmtOptionCow {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+} QBlockFmtOptionCow;
+
+typedef struct QBlockFmtOptionQed {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    QBlockFmtType backing_fmt;
+    uint64_t cluster_size; /* unit is bytes */
+    uint64_t table_size; /* unit is clusters */
+} QBlockFmtOptionQed;
+
+typedef struct QBlockFmtOptionQcow {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    bool encrypt;
+} QBlockFmtOptionQcow;
+
+/* "Compatibility level (0.10 or 1.1)" */
+typedef enum QBlockFmtOptionQcow2CptLv {
+    QBO_FMT_QCOW2_CPT_NONE = 0,
+    QBO_FMT_QCOW2_CPT_V010,
+    QBO_FMT_QCOW2_CPT_V110,
+} QBlockFmtOptionQcow2CptLv;
+
+/* off or metadata */
+typedef enum QBlockFmtOptionQcow2PreAllocType {
+    QBO_FMT_QCOW2_PREALLOC_NONE = 0,
+    QBO_FMT_QCOW2_PREALLOC_OFF,
+    QBO_FMT_QCOW2_PREALLOC_METADATA,
+} QBlockFmtOptionQcow2PreAllocType;
+
+typedef struct QBlockFmtOptionQcow2 {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    QBlockFmtType backing_fmt;
+    bool encrypt;
+    uint64_t cluster_size; /* unit is bytes */
+    QBlockFmtOptionQcow2CptLv cpt_lv;
+    QBlockFmtOptionQcow2PreAllocType pre_mode;
+} QBlockFmtOptionQcow2;
+
+typedef struct QBlockFmtOptionRaw {
+    uint64_t virt_size;
+} QBlockFmtOptionRaw;
+
+typedef struct QBlockFmtOptionRbd {
+    uint64_t virt_size;
+    uint64_t cluster_size;
+} QBlockFmtOptionRbd;
+
+/* off or full */
+typedef enum QBlockFmtOptionSheepdogPreAllocType {
+    QBO_FMT_SD_PREALLOC_NONE = 0,
+    QBO_FMT_SD_PREALLOC_OFF,
+    QBO_FMT_SD_PREALLOC_FULL,
+} QBlockFmtOptionSheepdogPreAllocType;
+
+typedef struct QBlockFmtOptionSheepdog {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    QBlockFmtOptionSheepdogPreAllocType pre_mode;
+} QBlockFmtOptionSheepdog;
+
+typedef enum QBlockFmtOptionVdiPreAllocType {
+    QBO_FMT_VDI_PREALLOC_NONE = 0,
+    QBO_FMT_VDI_PREALLOC_FALSE,
+    QBO_FMT_VDI_PREALLOC_TRUE,
+} QBlockFmtOptionVdiPreAllocType;
+
+typedef struct QBlockFmtOptionVdi {
+    uint64_t virt_size;
+    uint64_t cluster_size;
+    QBlockFmtOptionVdiPreAllocType pre_mode;
+} QBlockFmtOptionVdi;
+
+/* whether compact to vmdk verion 6 */
+typedef enum QBlockFmtOptionVmdkCptLv {
+    QBO_FMT_VMDK_CPT_NONE = 0,
+    QBO_FMT_VMDK_CPT_VMDKV6_FALSE,
+    QBO_FMT_VMDK_CPT_VMDKV6_TRUE,
+} QBlockFmtOptionVmdkCptLv;
+
+/* vmdk flat extent format, values:
+"{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse |
+twoGbMaxExtentFlat | streamOptimized} */
+typedef enum QBlockFmtOptionVmdkSubfmtType {
+    QBO_FMT_VMDK_SUBFMT_MONOLITHIC_NONE = 0,
+    QBO_FMT_VMDK_SUBFMT_MONOLITHIC_SPARSE,
+    QBO_FMT_VMDK_SUBFMT_MONOLITHIC_FLAT,
+    QBO_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_SPARSE,
+    QBO_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_FLAT,
+    QBO_FMT_VMDK_SUBFMT_STREAM_OPTIMIZED,
+} QBlockFmtOptionVmdkSubfmtType;
+
+typedef struct QBlockFmtOptionVmdk {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    QBlockFmtOptionVmdkCptLv cpt_lv;
+    QBlockFmtOptionVmdkSubfmtType subfmt;
+} QBlockFmtOptionVmdk;
+
+/* "{dynamic (default) | fixed} " */
+typedef enum QBlockFmtOptionVpcSubfmtType {
+    QBO_FMT_VPC_SUBFMT_NONE = 0,
+    QBO_FMT_VPC_SUBFMT_DYNAMIC,
+    QBO_FMT_VPC_SUBFMT_FIXED,
+} QBlockFmtOptionVpcSubfmtType;
+
+typedef struct QBlockFmtOptionVpc {
+    uint64_t virt_size;
+    QBlockFmtOptionVpcSubfmtType subfmt;
+} QBlockFmtOptionVpc;
+
+#define QBLOCK_FMT_OPTIONS_UNION_SIZE (QBLOCK_PROT_OPTIONS_UNION_SIZE*2)
+typedef union QBlockFmtOptionsUnion {
+    QBlockFmtOptionCow       o_cow;
+    QBlockFmtOptionQed       o_qed;
+    QBlockFmtOptionQcow      o_qcow;
+    QBlockFmtOptionQcow2     o_qcow2;
+    QBlockFmtOptionRaw       o_raw;
+    QBlockFmtOptionRbd       o_rbd;
+    QBlockFmtOptionSheepdog  o_sheepdog;
+    QBlockFmtOptionVdi       o_vdi;
+    QBlockFmtOptionVmdk      o_vmdk;
+    QBlockFmtOptionVpc       o_vpc;
+    uint8_t reserved[QBLOCK_FMT_OPTIONS_UNION_SIZE];
+} QBlockFmtOptionsUnion;
+
+typedef struct QBlockFmtInfo {
+    QBlockFmtType fmt_type;
+    QBlockFmtOptionsUnion fmt_op;
+} QBlockFmtInfo;
+
+/**
+ * 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 property 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;
+    QBlockProtInfo *backing_loc;
+    bool *encrypt;
+} QBlockStaticInfoAddr;
+
+/**
+ * QBlockStaticInfo: information about the block image.
+ *
+ * @member_addr: contains pointer which can be used to access the structure.
+ * @loc: location information.
+ * @fmt: format information.
+ * @sector_size: how many bytes in a sector, it is 512 usually.
+ */
+typedef struct QBlockStaticInfo {
+    QBlockStaticInfoAddr *member_addr;
+    QBlockProtInfo loc;
+    QBlockFmtInfo fmt;
+    int sector_size;
+} QBlockStaticInfo;
+
+
+#endif
#10 lore raw

Re: [Qemu-devel] [PATCH V3 2/5] libqblock type defines

Quoted 72 lines

Il 18/09/2012 11:01, Wenchao Xia ha scritto:

Quoted 55 lines

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

---
  libqblock/libqblock-internal.h |   56 +++++++++
  libqblock/libqblock-types.h    |  268 ++++++++++++++++++++++++++++++++++++++++
  2 files changed, 324 insertions(+), 0 deletions(-)

create mode 100644 libqblock/libqblock-internal.h create mode 100644 libqblock/libqblock-types.h

libqblock/libqblock-internal.h new file +38 -0
new file mode 100644
index 0000000..87f32be
@@ -0,0 +1,56 @@
+/*
+ * 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 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.

libqblock/libqblock-internal.h line 48

Quoted 10 lines
libqblock/libqblock-internal.h new file +10 -0
+    */
+    char *filename;
+} ;
+
+struct QBroker {
+    /* 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 */
+};

Sorry for keeping on bikeshedding---a better name for this is QBlockContext. "Context" is a well-known name for this kind of global object.

Quoted 4 lines

Otherwise looks good---thanks for putting up with us! :)

Paolo

OK, will change the name to better ones, thank you for reviewing.

Quoted 284 lines
Quoted 282 lines
libqblock/libqblock-internal.h new file +7 -0
+#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 new file +268 -0
new file mode 100644
index 0000000..3c548b8
@@ -0,0 +1,268 @@
+/*
+ * 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
+#else
+    #warning : gcc compiler version < 4, symbols can not be hidden.
+#endif
+
+/* this library is designed around this core struct. */
+typedef struct QBlockState QBlockState;
+
+/* every thread should have a broker. */
+typedef struct QBroker QBroker;
+
+/* 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 QBlockProtType {
+    QB_PROT_NONE = 0,
+    QB_PROT_FILE,
+    QB_PROT_MAX
+} QBlockProtType;
+
+typedef struct QBlockProtOptionFile {
+    const char *filename;
+} QBlockProtOptionFile;
+
+#define QBLOCK_PROT_OPTIONS_UNION_SIZE (512)
+typedef union QBlockProtOptionsUnion {
+    QBlockProtOptionFile o_file;
+    uint8_t reserved[QBLOCK_PROT_OPTIONS_UNION_SIZE];
+} QBlockProtOptionsUnion;
+
+/**
+ * struct QBlockProtInfo: contains information about how to find the image
+ *
+ * @prot_type: protocol type, now only support FILE.
+ * @prot_op: protocol related options.
+ */
+typedef struct QBlockProtInfo {
+    QBlockProtType prot_type;
+    QBlockProtOptionsUnion prot_op;
+} QBlockProtInfo;
+
+
+/* format related options */
+typedef enum QBlockFmtType {
+    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
+} QBlockFmtType;
+
+typedef struct QBlockFmtOptionCow {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+} QBlockFmtOptionCow;
+
+typedef struct QBlockFmtOptionQed {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    QBlockFmtType backing_fmt;
+    uint64_t cluster_size; /* unit is bytes */
+    uint64_t table_size; /* unit is clusters */
+} QBlockFmtOptionQed;
+
+typedef struct QBlockFmtOptionQcow {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    bool encrypt;
+} QBlockFmtOptionQcow;
+
+/* "Compatibility level (0.10 or 1.1)" */
+typedef enum QBlockFmtOptionQcow2CptLv {
+    QBO_FMT_QCOW2_CPT_NONE = 0,
+    QBO_FMT_QCOW2_CPT_V010,
+    QBO_FMT_QCOW2_CPT_V110,
+} QBlockFmtOptionQcow2CptLv;
+
+/* off or metadata */
+typedef enum QBlockFmtOptionQcow2PreAllocType {
+    QBO_FMT_QCOW2_PREALLOC_NONE = 0,
+    QBO_FMT_QCOW2_PREALLOC_OFF,
+    QBO_FMT_QCOW2_PREALLOC_METADATA,
+} QBlockFmtOptionQcow2PreAllocType;
+
+typedef struct QBlockFmtOptionQcow2 {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    QBlockFmtType backing_fmt;
+    bool encrypt;
+    uint64_t cluster_size; /* unit is bytes */
+    QBlockFmtOptionQcow2CptLv cpt_lv;
+    QBlockFmtOptionQcow2PreAllocType pre_mode;
+} QBlockFmtOptionQcow2;
+
+typedef struct QBlockFmtOptionRaw {
+    uint64_t virt_size;
+} QBlockFmtOptionRaw;
+
+typedef struct QBlockFmtOptionRbd {
+    uint64_t virt_size;
+    uint64_t cluster_size;
+} QBlockFmtOptionRbd;
+
+/* off or full */
+typedef enum QBlockFmtOptionSheepdogPreAllocType {
+    QBO_FMT_SD_PREALLOC_NONE = 0,
+    QBO_FMT_SD_PREALLOC_OFF,
+    QBO_FMT_SD_PREALLOC_FULL,
+} QBlockFmtOptionSheepdogPreAllocType;
+
+typedef struct QBlockFmtOptionSheepdog {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    QBlockFmtOptionSheepdogPreAllocType pre_mode;
+} QBlockFmtOptionSheepdog;
+
+typedef enum QBlockFmtOptionVdiPreAllocType {
+    QBO_FMT_VDI_PREALLOC_NONE = 0,
+    QBO_FMT_VDI_PREALLOC_FALSE,
+    QBO_FMT_VDI_PREALLOC_TRUE,
+} QBlockFmtOptionVdiPreAllocType;
+
+typedef struct QBlockFmtOptionVdi {
+    uint64_t virt_size;
+    uint64_t cluster_size;
+    QBlockFmtOptionVdiPreAllocType pre_mode;
+} QBlockFmtOptionVdi;
+
+/* whether compact to vmdk verion 6 */
+typedef enum QBlockFmtOptionVmdkCptLv {
+    QBO_FMT_VMDK_CPT_NONE = 0,
+    QBO_FMT_VMDK_CPT_VMDKV6_FALSE,
+    QBO_FMT_VMDK_CPT_VMDKV6_TRUE,
+} QBlockFmtOptionVmdkCptLv;
+
+/* vmdk flat extent format, values:
+"{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse |
+twoGbMaxExtentFlat | streamOptimized} */
+typedef enum QBlockFmtOptionVmdkSubfmtType {
+    QBO_FMT_VMDK_SUBFMT_MONOLITHIC_NONE = 0,
+    QBO_FMT_VMDK_SUBFMT_MONOLITHIC_SPARSE,
+    QBO_FMT_VMDK_SUBFMT_MONOLITHIC_FLAT,
+    QBO_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_SPARSE,
+    QBO_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_FLAT,
+    QBO_FMT_VMDK_SUBFMT_STREAM_OPTIMIZED,
+} QBlockFmtOptionVmdkSubfmtType;
+
+typedef struct QBlockFmtOptionVmdk {
+    uint64_t virt_size;
+    QBlockProtInfo backing_loc;
+    QBlockFmtOptionVmdkCptLv cpt_lv;
+    QBlockFmtOptionVmdkSubfmtType subfmt;
+} QBlockFmtOptionVmdk;
+
+/* "{dynamic (default) | fixed} " */
+typedef enum QBlockFmtOptionVpcSubfmtType {
+    QBO_FMT_VPC_SUBFMT_NONE = 0,
+    QBO_FMT_VPC_SUBFMT_DYNAMIC,
+    QBO_FMT_VPC_SUBFMT_FIXED,
+} QBlockFmtOptionVpcSubfmtType;
+
+typedef struct QBlockFmtOptionVpc {
+    uint64_t virt_size;
+    QBlockFmtOptionVpcSubfmtType subfmt;
+} QBlockFmtOptionVpc;
+
+#define QBLOCK_FMT_OPTIONS_UNION_SIZE (QBLOCK_PROT_OPTIONS_UNION_SIZE*2)
+typedef union QBlockFmtOptionsUnion {
+    QBlockFmtOptionCow       o_cow;
+    QBlockFmtOptionQed       o_qed;
+    QBlockFmtOptionQcow      o_qcow;
+    QBlockFmtOptionQcow2     o_qcow2;
+    QBlockFmtOptionRaw       o_raw;
+    QBlockFmtOptionRbd       o_rbd;
+    QBlockFmtOptionSheepdog  o_sheepdog;
+    QBlockFmtOptionVdi       o_vdi;
+    QBlockFmtOptionVmdk      o_vmdk;
+    QBlockFmtOptionVpc       o_vpc;
+    uint8_t reserved[QBLOCK_FMT_OPTIONS_UNION_SIZE];
+} QBlockFmtOptionsUnion;
+
+typedef struct QBlockFmtInfo {
+    QBlockFmtType fmt_type;
+    QBlockFmtOptionsUnion fmt_op;
+} QBlockFmtInfo;
+
+/**
+ * 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 property 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;
+    QBlockProtInfo *backing_loc;
+    bool *encrypt;
+} QBlockStaticInfoAddr;
+
+/**
+ * QBlockStaticInfo: information about the block image.
+ *
+ * @member_addr: contains pointer which can be used to access the structure.
+ * @loc: location information.
+ * @fmt: format information.
+ * @sector_size: how many bytes in a sector, it is 512 usually.
+ */
+typedef struct QBlockStaticInfo {
+    QBlockStaticInfoAddr *member_addr;
+    QBlockProtInfo loc;
+    QBlockFmtInfo fmt;
+    int sector_size;
+} QBlockStaticInfo;
+
+
+#endif
Signature · 3 lines
Best Regards

Wenchao Xia
#11 lore raw

PATCH v3 3/5 libqblock API

In reply to Wenchao Xia

This patch contains the major APIs in the library.
Important APIs:
1 QBroker. These structure was used to retrieve errors, every thread must
create one first, later maybe thread related staff could be added into it.
2 QBlockState. It stands for an block image object.
3 QBlockStaticInfo. It contains static information such as location, backing
file, size.
4 ABI was kept with reserved members.
5 Sync I/O. It is similar to C file open, read, write and close operations.

---
 block.c                     |    2 +-
 block.h                     |    1 +
 libqblock/libqblock-error.c |   57 +++
 libqblock/libqblock-error.h |   49 ++
 libqblock/libqblock.c       | 1140 +++++++++++++++++++++++++++++++++++++++++++
 libqblock/libqblock.h       |  297 +++++++++++
 6 files changed, 1545 insertions(+), 1 deletions(-)
 create mode 100644 libqblock/libqblock-error.h
 create mode 100644 libqblock/libqblock.h
block.c +1 -1
index e78039b..d5321d3 100644
@@ -196,7 +196,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 +1 -0
index 2e2be11..e7da711 100644
@@ -405,4 +405,5 @@ typedef enum {
 #define BLKDBG_EVENT(bs, evt) bdrv_debug_event(bs, evt)
 void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event);
 
+int path_has_protocol(const char *path);
 #endif
libqblock/libqblock-error.c +57 -0

57 lines not on this page · raw message

libqblock/libqblock-error.h new file +49 -0

49 lines not on this page · raw message

libqblock/libqblock.c +1140 -0

1,140 lines not on this page · raw message

libqblock/libqblock.h new file +297 -0

297 lines not on this page · raw message

Signature · 1 line
1.7.1
#12 lore raw

PATCH v3 4/5 libqblock test build system

In reply to Wenchao Xia

Created a new directory in tests, make chekc-libqblock will build an
executable binrary, make clean will delete it.

---
 .gitignore                       |    1 +
 Makefile                         |    1 +
 tests/Makefile                   |    3 +++
 tests/libqblock/Makefile         |   32 ++++++++++++++++++++++++++++++++
 tests/libqblock/libqblock-test.c |    4 ++++
 5 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100644 tests/libqblock/Makefile
 create mode 100644 tests/libqblock/libqblock-test.c
.gitignore +1 -0
index 824c0d2..eccb637 100644
@@ -95,3 +95,4 @@ cscope.*
 tags
 TAGS
 *~
+tests/libqblock/*.bin
Makefile +1 -0
index b0b9b8d..de8ea17 100644
@@ -238,6 +238,7 @@ clean:
 	rm -rf qapi-generated
 	rm -rf qga/qapi-generated
 	$(MAKE) -C tests/tcg clean
+	$(MAKE) -C tests/libqblock clean
 	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; \
tests/Makefile +3 -0
index 26a67ce..69af1e2 100644
@@ -148,4 +148,7 @@ check-unit: $(patsubst %,check-%, $(check-unit-y))
 check-block: $(patsubst %,check-%, $(check-block-y))
 check: check-unit check-qtest
 
+check-libqblock:
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C tests/libqblock V="$(V)" TARGET_DIR="$*/" check-libqblock,)
+
 -include $(wildcard tests/*.d)
tests/libqblock/Makefile new file +32 -0
new file mode 100644
index 0000000..eb6947b
@@ -0,0 +1,32 @@
+-include ../../config-host.mak
+-include $(SRC_PATH)/Makefile.objs
+-include $(SRC_PATH)/rules.mak
+
+$(call set-vpath, $(SRC_PATH))
+
+#library test case objects
+libqblock-test-objs=libqblock-test.lo
+
+QEMU_CFLAGS+=-I $(SRC_PATH)/$(libqblock-lib-path)
+libqblock-la-path = $(SRC_PATH)/$(libqblock-lib-path)/$(libqblock-lib-la)
+
+##########################################################################
+#runtime rules:
+ifeq ($(LIBTOOL),)
+libqblock-test.bin:
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+libqblock-test.bin: $(libqblock-test-objs) $(libqblock-la-path)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -shared -rpath $(libdir) -o $@ $^,"  lt LINK $@")
+endif
+
+check-libqblock:
+	@echo "Building libqblock.la..."
+	$(call quiet-command,$(MAKE) -C $(SRC_PATH) $(libqblock-lib-la),)
+	@make libqblock-test.bin
+	@echo "Executing test binary..."
+	./libqblock-test.bin
+
+clean:
+	rm -f *.lo *.o *.d *.la *.bin
+	rm -rf .libs
tests/libqblock/libqblock-test.c new file +4 -0
new file mode 100644
index 0000000..c05c0c4
@@ -0,0 +1,4 @@
+int main(int argc, char **argv)
+{
+    return 0;
+}
Signature · 1 line
1.7.1
#13 lore raw

Re: [Qemu-devel] [PATCH V3 4/5] libqblock test build system

Il 18/09/2012 11:01, Wenchao Xia ha scritto:

Quoted 40 lines

Created a new directory in tests, make chekc-libqblock will build an
executable binrary, make clean will delete it.

---
 .gitignore                       |    1 +
 Makefile                         |    1 +
 tests/Makefile                   |    3 +++
 tests/libqblock/Makefile         |   32 ++++++++++++++++++++++++++++++++
 tests/libqblock/libqblock-test.c |    4 ++++
 5 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100644 tests/libqblock/Makefile
 create mode 100644 tests/libqblock/libqblock-test.c
.gitignore +1 -0
index 824c0d2..eccb637 100644
@@ -95,3 +95,4 @@ cscope.*
 tags
 TAGS
 *~
+tests/libqblock/*.bin
Makefile +1 -0
index b0b9b8d..de8ea17 100644
@@ -238,6 +238,7 @@ clean:
 	rm -rf qapi-generated
 	rm -rf qga/qapi-generated
 	$(MAKE) -C tests/tcg clean
+	$(MAKE) -C tests/libqblock clean
 	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; \
tests/Makefile +0 -0
index 26a67ce..69af1e2 100644

tests/Makefile check-unit: $(patsubst %,check-%, $(check-unit-y)) · line 152

Quoted 5 lines
tests/Makefile +2 -0
@@ -148,4 +148,7 @@ check-unit: $(patsubst %,check-%, $(check-unit-y))
 check-block: $(patsubst %,check-%, $(check-block-y))
 check: check-unit check-qtest
 
+check-libqblock:
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C tests/libqblock V="$(V)" TARGET_DIR="$*/" check-libqblock,)

Please just put everything in tests/Makefile. "make check" should run it if LIBTOOL is available.

tests/Makefile check-unit: $(patsubst %,check-%, $(check-unit-y)) · line 154

Quoted 2 lines
tests/Makefile +2 -0
+libqblock-test.bin: $(libqblock-test-objs) $(libqblock-la-path)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -shared -rpath $(libdir) -o $@ $^,"  lt LINK $@")

.bin looks so MS-DOS. :)

Paolo

#14 lore raw

Re: [Qemu-devel] [PATCH V3 4/5] libqblock test build system

Quoted 44 lines · Paolo Bonzini

Il 18/09/2012 11:01, Wenchao Xia ha scritto:

Quoted 43 lines

Created a new directory in tests, make chekc-libqblock will build an
executable binrary, make clean will delete it.

---
  .gitignore                       |    1 +
  Makefile                         |    1 +
  tests/Makefile                   |    3 +++
  tests/libqblock/Makefile         |   32 ++++++++++++++++++++++++++++++++
  tests/libqblock/libqblock-test.c |    4 ++++
  5 files changed, 41 insertions(+), 0 deletions(-)

create mode 100644 tests/libqblock/Makefile create mode 100644 tests/libqblock/libqblock-test.c

.gitignore +1 -0
index 824c0d2..eccb637 100644
@@ -95,3 +95,4 @@ cscope.*
  tags
  TAGS
  *~
+tests/libqblock/*.bin
Makefile +1 -0
index b0b9b8d..de8ea17 100644
@@ -238,6 +238,7 @@ clean:
  	rm -rf qapi-generated
  	rm -rf qga/qapi-generated
  	$(MAKE) -C tests/tcg clean
+	$(MAKE) -C tests/libqblock clean
  	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; \
tests/Makefile +0 -0
index 26a67ce..69af1e2 100644
@@ -148,4 +148,7 @@ check-unit: $(patsubst %,check-%, $(check-unit-y))
  check-block: $(patsubst %,check-%, $(check-block-y))
  check: check-unit check-qtest
 
Quoted 6 lines

tests/Makefile check-unit: $(patsubst %,check-%, $(check-unit-y)) · line 152

Quoted 2 lines
tests/Makefile +2 -0
+check-libqblock:
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C tests/libqblock V="$(V)" TARGET_DIR="$*/" check-libqblock,)

Please just put everything in tests/Makefile. "make check" should run it if LIBTOOL is available.

OK.

Quoted 8 lines

tests/Makefile check-unit: $(patsubst %,check-%, $(check-unit-y)) · line 154

Quoted 2 lines
tests/Makefile +2 -0
+libqblock-test.bin: $(libqblock-test-objs) $(libqblock-la-path)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -shared -rpath $(libdir) -o $@ $^,"  lt LINK $@")

.bin looks so MS-DOS. :)

Paolo

Signature · 3 lines
Best Regards

Wenchao Xia
#15 lore raw

PATCH v3 5/5 libqblock test example code

In reply to Wenchao Xia

In this example, user first create two qcow2 images, and then get the
backing file relationship information of them. Then does write and read sync IO on them.

---
 tests/libqblock/libqblock-test.c |  233 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 233 insertions(+), 0 deletions(-)
tests/libqblock/libqblock-test.c +233 -0
index c05c0c4..c0b7963 100644
@@ -1,4 +1,237 @@
+/*
+ * 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.
+ *
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libqblock.h"
+
+#define TEST_BUF_SIZE 1024
+static unsigned char buf_r[TEST_BUF_SIZE];
+static unsigned char buf_w[TEST_BUF_SIZE] = {0, 0, 0, 0};
+
+typedef struct VerifyData {
+    unsigned char *buf_r;
+    unsigned char *buf_w;
+    int len;
+} VerifyData;
+
+static void print_loc(QBlockProtInfo *loc)
+{
+    if (loc == NULL) {
+        printf("backing file is NULL.");
+        return;
+    }
+    switch (loc->prot_type) {
+    case QB_PROT_NONE:
+        printf("protocol type [none].");
+        break;
+    case QB_PROT_FILE:
+        printf("protocol type [file], filename [%s].",
+               loc->prot_op.o_file.filename);
+        break;
+    default:
+        printf("protocol type not supported.");
+        break;
+    }
+}
+
+static void print_info_image_static(QBlockStaticInfo *info)
+{
+    printf("=======image location:\n");
+    print_loc(&info->loc);
+    printf("\nvirtual_size %" PRId64 ", format type %d [%s]",
+           *(info->member_addr->virt_size),
+           info->fmt.fmt_type, qb_fmttype2str(info->fmt.fmt_type));
+    printf("\nbacking image location:\n");
+    print_loc(info->member_addr->backing_loc);
+    printf("\n");
+}
+
+static void test_check(VerifyData *vdata)
+{
+    int cmp;
+    cmp = memcmp(vdata->buf_r, vdata->buf_w, vdata->len);
+    if (cmp == 0) {
+        printf("compare succeed, %d.\n", vdata->buf_r[24]);
+    } else {
+        printf("!!! compare fail, %d.\n", vdata->buf_r[24]);
+        exit(1);
+    }
+}
+
 int main(int argc, char **argv)
 {
+    const char *filename1, *filename2;
+    QBroker *broker = NULL;
+    QBlockState *qbs = NULL;
+    QBlockProtInfo *ol = NULL;
+    QBlockFmtInfo *of = NULL;
+    QBlockStaticInfo *info_st = NULL;
+    int ret, flag;
+    int test_offset = 510;
+    int test_len = 520;
+    VerifyData vdata;
+    char err_str[1024];
+
+    vdata.buf_r = buf_r;
+    vdata.buf_w = buf_w;
+    vdata.len = test_len;
+
+    filename1 = "./qemu_image1";
+    filename2 = "./qemu_image2";
+    printf("qemu test, filename1 is %s, filename2 is %s.\n",
+                                       filename1, filename2);
+
+    ret = qb_broker_new(&broker);
+    if (ret < 0) {
+        goto free;
+    }
+
+    ret = qb_state_new(broker, &qbs);
+    if (ret < 0) {
+        goto free;
+    }
+
+    ret = qb_prot_info_new(broker, &ol);
+    if (ret < 0) {
+        goto free;
+    }
+
+    ret = qb_fmt_info_new(broker, &of);
+    if (ret < 0) {
+        goto free;
+    }
+
+    /* create a new image */
+
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename2;
+    of->fmt_type = QB_FMT_QCOW2;
+    of->fmt_op.o_qcow2.virt_size = 100 * 1024;
+    flag = 0;
+
+    ret = qb_create(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("create fail 1. %s.\n", err_str);
+        goto unlink;
+    }
+
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename1;
+    of->fmt_type = QB_FMT_QCOW2;
+    of->fmt_op.o_qcow2.backing_loc.prot_type = QB_PROT_FILE;
+    of->fmt_op.o_qcow2.backing_loc.prot_op.o_file.filename = filename2;
+    flag = 0;
+    ret = qb_create(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("create fail 2. %s.\n", err_str);
+        goto unlink;
+    }
+
+    /* get informations */
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename1;
+    of->fmt_type = QB_FMT_NONE;
+    flag = LIBQBLOCK_O_NO_BACKING;
+    ret = qb_open(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("info getting, open failed. %s.\n", err_str);
+        goto free;
+    }
+
+    while (1) {
+        ret = qb_info_image_static_get(broker, qbs, &info_st);
+        if (ret < 0) {
+            qb_error_get_human_str(broker, err_str, sizeof(err_str));
+            printf("info get error. %s.\n", err_str);
+            goto close;
+        }
+        print_info_image_static(info_st);
+        qb_close(broker, qbs);
+        if ((info_st->member_addr->backing_loc == NULL) ||
+            (info_st->member_addr->backing_loc->prot_type == QB_FMT_NONE)) {
+            break;
+        }
+        *ol = *(info_st->member_addr->backing_loc);
+        ret = qb_open(broker, qbs, ol, of, flag);
+        if (ret < 0) {
+            qb_error_get_human_str(broker, err_str, sizeof(err_str));
+            printf("info getting, open failed in backing file. %s.\n",
+                                                       err_str);
+            goto free;
+        }
+        qb_info_image_static_delete(broker, &info_st);
+    }
+    /* read and write the image */
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename1;
+    of->fmt_type = QB_FMT_NONE;
+    flag = LIBQBLOCK_O_RDWR;
+    ret = qb_open(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("open failed. %s.\n", err_str);
+        goto free;
+    }
+
+    buf_w[1] = 1;
+    buf_w[2] = 2;
+    buf_w[514] = 4;
+    memset(buf_r, 0, sizeof(buf_r));
+
+    ret = qb_write(broker, qbs, buf_w, test_len, test_offset);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("%s.\n", err_str);
+        goto close;
+    }
+
+    ret = qb_read(broker, qbs, buf_r, test_len, test_offset);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("%s.\n", err_str);
+        goto close;
+    }
+
+    test_check(&vdata);
+
+ close:
+    qb_close(broker, qbs);
+ unlink:
+    unlink(filename1);
+    unlink(filename2);
+ free:
+    if (info_st != NULL) {
+        qb_info_image_static_delete(broker, &info_st);
+    }
+    if (qbs != NULL) {
+        qb_state_delete(broker, &qbs);
+    }
+    if (ol != NULL) {
+        qb_prot_info_delete(broker, &ol);
+    }
+    if (of != NULL) {
+        qb_fmt_info_delete(broker, &of);
+    }
+    if (broker != NULL) {
+        qb_broker_delete(&broker);
+    }
     return 0;
 }
Signature · 1 line
1.7.1
#16 lore raw

Re: [Qemu-devel] [PATCH V3 5/5] libqblock test example code

Il 18/09/2012 11:01, Wenchao Xia ha scritto:

Quoted 3 lines

In this example, user first create two qcow2 images, and then get the
backing file relationship information of them. Then does write and read sync IO on them.

Please use gtest so that this can be easily extensible.

Paolo

Quoted 248 lines
---
 tests/libqblock/libqblock-test.c |  233 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 233 insertions(+), 0 deletions(-)
tests/libqblock/libqblock-test.c +233 -0
index c05c0c4..c0b7963 100644
@@ -1,4 +1,237 @@
+/*
+ * 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.
+ *
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libqblock.h"
+
+#define TEST_BUF_SIZE 1024
+static unsigned char buf_r[TEST_BUF_SIZE];
+static unsigned char buf_w[TEST_BUF_SIZE] = {0, 0, 0, 0};
+
+typedef struct VerifyData {
+    unsigned char *buf_r;
+    unsigned char *buf_w;
+    int len;
+} VerifyData;
+
+static void print_loc(QBlockProtInfo *loc)
+{
+    if (loc == NULL) {
+        printf("backing file is NULL.");
+        return;
+    }
+    switch (loc->prot_type) {
+    case QB_PROT_NONE:
+        printf("protocol type [none].");
+        break;
+    case QB_PROT_FILE:
+        printf("protocol type [file], filename [%s].",
+               loc->prot_op.o_file.filename);
+        break;
+    default:
+        printf("protocol type not supported.");
+        break;
+    }
+}
+
+static void print_info_image_static(QBlockStaticInfo *info)
+{
+    printf("=======image location:\n");
+    print_loc(&info->loc);
+    printf("\nvirtual_size %" PRId64 ", format type %d [%s]",
+           *(info->member_addr->virt_size),
+           info->fmt.fmt_type, qb_fmttype2str(info->fmt.fmt_type));
+    printf("\nbacking image location:\n");
+    print_loc(info->member_addr->backing_loc);
+    printf("\n");
+}
+
+static void test_check(VerifyData *vdata)
+{
+    int cmp;
+    cmp = memcmp(vdata->buf_r, vdata->buf_w, vdata->len);
+    if (cmp == 0) {
+        printf("compare succeed, %d.\n", vdata->buf_r[24]);
+    } else {
+        printf("!!! compare fail, %d.\n", vdata->buf_r[24]);
+        exit(1);
+    }
+}
+
 int main(int argc, char **argv)
 {
+    const char *filename1, *filename2;
+    QBroker *broker = NULL;
+    QBlockState *qbs = NULL;
+    QBlockProtInfo *ol = NULL;
+    QBlockFmtInfo *of = NULL;
+    QBlockStaticInfo *info_st = NULL;
+    int ret, flag;
+    int test_offset = 510;
+    int test_len = 520;
+    VerifyData vdata;
+    char err_str[1024];
+
+    vdata.buf_r = buf_r;
+    vdata.buf_w = buf_w;
+    vdata.len = test_len;
+
+    filename1 = "./qemu_image1";
+    filename2 = "./qemu_image2";
+    printf("qemu test, filename1 is %s, filename2 is %s.\n",
+                                       filename1, filename2);
+
+    ret = qb_broker_new(&broker);
+    if (ret < 0) {
+        goto free;
+    }
+
+    ret = qb_state_new(broker, &qbs);
+    if (ret < 0) {
+        goto free;
+    }
+
+    ret = qb_prot_info_new(broker, &ol);
+    if (ret < 0) {
+        goto free;
+    }
+
+    ret = qb_fmt_info_new(broker, &of);
+    if (ret < 0) {
+        goto free;
+    }
+
+    /* create a new image */
+
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename2;
+    of->fmt_type = QB_FMT_QCOW2;
+    of->fmt_op.o_qcow2.virt_size = 100 * 1024;
+    flag = 0;
+
+    ret = qb_create(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("create fail 1. %s.\n", err_str);
+        goto unlink;
+    }
+
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename1;
+    of->fmt_type = QB_FMT_QCOW2;
+    of->fmt_op.o_qcow2.backing_loc.prot_type = QB_PROT_FILE;
+    of->fmt_op.o_qcow2.backing_loc.prot_op.o_file.filename = filename2;
+    flag = 0;
+    ret = qb_create(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("create fail 2. %s.\n", err_str);
+        goto unlink;
+    }
+
+    /* get informations */
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename1;
+    of->fmt_type = QB_FMT_NONE;
+    flag = LIBQBLOCK_O_NO_BACKING;
+    ret = qb_open(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("info getting, open failed. %s.\n", err_str);
+        goto free;
+    }
+
+    while (1) {
+        ret = qb_info_image_static_get(broker, qbs, &info_st);
+        if (ret < 0) {
+            qb_error_get_human_str(broker, err_str, sizeof(err_str));
+            printf("info get error. %s.\n", err_str);
+            goto close;
+        }
+        print_info_image_static(info_st);
+        qb_close(broker, qbs);
+        if ((info_st->member_addr->backing_loc == NULL) ||
+            (info_st->member_addr->backing_loc->prot_type == QB_FMT_NONE)) {
+            break;
+        }
+        *ol = *(info_st->member_addr->backing_loc);
+        ret = qb_open(broker, qbs, ol, of, flag);
+        if (ret < 0) {
+            qb_error_get_human_str(broker, err_str, sizeof(err_str));
+            printf("info getting, open failed in backing file. %s.\n",
+                                                       err_str);
+            goto free;
+        }
+        qb_info_image_static_delete(broker, &info_st);
+    }
+    /* read and write the image */
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename1;
+    of->fmt_type = QB_FMT_NONE;
+    flag = LIBQBLOCK_O_RDWR;
+    ret = qb_open(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("open failed. %s.\n", err_str);
+        goto free;
+    }
+
+    buf_w[1] = 1;
+    buf_w[2] = 2;
+    buf_w[514] = 4;
+    memset(buf_r, 0, sizeof(buf_r));
+
+    ret = qb_write(broker, qbs, buf_w, test_len, test_offset);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("%s.\n", err_str);
+        goto close;
+    }
+
+    ret = qb_read(broker, qbs, buf_r, test_len, test_offset);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("%s.\n", err_str);
+        goto close;
+    }
+
+    test_check(&vdata);
+
+ close:
+    qb_close(broker, qbs);
+ unlink:
+    unlink(filename1);
+    unlink(filename2);
+ free:
+    if (info_st != NULL) {
+        qb_info_image_static_delete(broker, &info_st);
+    }
+    if (qbs != NULL) {
+        qb_state_delete(broker, &qbs);
+    }
+    if (ol != NULL) {
+        qb_prot_info_delete(broker, &ol);
+    }
+    if (of != NULL) {
+        qb_fmt_info_delete(broker, &of);
+    }
+    if (broker != NULL) {
+        qb_broker_delete(&broker);
+    }
     return 0;
 }
#17 lore raw

Re: [Qemu-devel] [PATCH V3 5/5] libqblock test example code

Quoted 9 lines · Paolo Bonzini

Il 18/09/2012 11:01, Wenchao Xia ha scritto:

Quoted 3 lines

In this example, user first create two qcow2 images, and then get the
backing file relationship information of them. Then does write and read sync IO on them.

Please use gtest so that this can be easily extensible.

Paolo

OK.

Quoted 250 lines
Quoted 248 lines
---
  tests/libqblock/libqblock-test.c |  233 ++++++++++++++++++++++++++++++++++++++
  1 files changed, 233 insertions(+), 0 deletions(-)
tests/libqblock/libqblock-test.c +233 -0
index c05c0c4..c0b7963 100644
@@ -1,4 +1,237 @@
+/*
+ * 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.
+ *
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libqblock.h"
+
+#define TEST_BUF_SIZE 1024
+static unsigned char buf_r[TEST_BUF_SIZE];
+static unsigned char buf_w[TEST_BUF_SIZE] = {0, 0, 0, 0};
+
+typedef struct VerifyData {
+    unsigned char *buf_r;
+    unsigned char *buf_w;
+    int len;
+} VerifyData;
+
+static void print_loc(QBlockProtInfo *loc)
+{
+    if (loc == NULL) {
+        printf("backing file is NULL.");
+        return;
+    }
+    switch (loc->prot_type) {
+    case QB_PROT_NONE:
+        printf("protocol type [none].");
+        break;
+    case QB_PROT_FILE:
+        printf("protocol type [file], filename [%s].",
+               loc->prot_op.o_file.filename);
+        break;
+    default:
+        printf("protocol type not supported.");
+        break;
+    }
+}
+
+static void print_info_image_static(QBlockStaticInfo *info)
+{
+    printf("=======image location:\n");
+    print_loc(&info->loc);
+    printf("\nvirtual_size %" PRId64 ", format type %d [%s]",
+           *(info->member_addr->virt_size),
+           info->fmt.fmt_type, qb_fmttype2str(info->fmt.fmt_type));
+    printf("\nbacking image location:\n");
+    print_loc(info->member_addr->backing_loc);
+    printf("\n");
+}
+
+static void test_check(VerifyData *vdata)
+{
+    int cmp;
+    cmp = memcmp(vdata->buf_r, vdata->buf_w, vdata->len);
+    if (cmp == 0) {
+        printf("compare succeed, %d.\n", vdata->buf_r[24]);
+    } else {
+        printf("!!! compare fail, %d.\n", vdata->buf_r[24]);
+        exit(1);
+    }
+}
+
  int main(int argc, char **argv)
  {
+    const char *filename1, *filename2;
+    QBroker *broker = NULL;
+    QBlockState *qbs = NULL;
+    QBlockProtInfo *ol = NULL;
+    QBlockFmtInfo *of = NULL;
+    QBlockStaticInfo *info_st = NULL;
+    int ret, flag;
+    int test_offset = 510;
+    int test_len = 520;
+    VerifyData vdata;
+    char err_str[1024];
+
+    vdata.buf_r = buf_r;
+    vdata.buf_w = buf_w;
+    vdata.len = test_len;
+
+    filename1 = "./qemu_image1";
+    filename2 = "./qemu_image2";
+    printf("qemu test, filename1 is %s, filename2 is %s.\n",
+                                       filename1, filename2);
+
+    ret = qb_broker_new(&broker);
+    if (ret < 0) {
+        goto free;
+    }
+
+    ret = qb_state_new(broker, &qbs);
+    if (ret < 0) {
+        goto free;
+    }
+
+    ret = qb_prot_info_new(broker, &ol);
+    if (ret < 0) {
+        goto free;
+    }
+
+    ret = qb_fmt_info_new(broker, &of);
+    if (ret < 0) {
+        goto free;
+    }
+
+    /* create a new image */
+
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename2;
+    of->fmt_type = QB_FMT_QCOW2;
+    of->fmt_op.o_qcow2.virt_size = 100 * 1024;
+    flag = 0;
+
+    ret = qb_create(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("create fail 1. %s.\n", err_str);
+        goto unlink;
+    }
+
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename1;
+    of->fmt_type = QB_FMT_QCOW2;
+    of->fmt_op.o_qcow2.backing_loc.prot_type = QB_PROT_FILE;
+    of->fmt_op.o_qcow2.backing_loc.prot_op.o_file.filename = filename2;
+    flag = 0;
+    ret = qb_create(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("create fail 2. %s.\n", err_str);
+        goto unlink;
+    }
+
+    /* get informations */
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename1;
+    of->fmt_type = QB_FMT_NONE;
+    flag = LIBQBLOCK_O_NO_BACKING;
+    ret = qb_open(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("info getting, open failed. %s.\n", err_str);
+        goto free;
+    }
+
+    while (1) {
+        ret = qb_info_image_static_get(broker, qbs, &info_st);
+        if (ret < 0) {
+            qb_error_get_human_str(broker, err_str, sizeof(err_str));
+            printf("info get error. %s.\n", err_str);
+            goto close;
+        }
+        print_info_image_static(info_st);
+        qb_close(broker, qbs);
+        if ((info_st->member_addr->backing_loc == NULL) ||
+            (info_st->member_addr->backing_loc->prot_type == QB_FMT_NONE)) {
+            break;
+        }
+        *ol = *(info_st->member_addr->backing_loc);
+        ret = qb_open(broker, qbs, ol, of, flag);
+        if (ret < 0) {
+            qb_error_get_human_str(broker, err_str, sizeof(err_str));
+            printf("info getting, open failed in backing file. %s.\n",
+                                                       err_str);
+            goto free;
+        }
+        qb_info_image_static_delete(broker, &info_st);
+    }
+    /* read and write the image */
+    ol->prot_type = QB_PROT_FILE;
+    ol->prot_op.o_file.filename = filename1;
+    of->fmt_type = QB_FMT_NONE;
+    flag = LIBQBLOCK_O_RDWR;
+    ret = qb_open(broker, qbs, ol, of, flag);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("open failed. %s.\n", err_str);
+        goto free;
+    }
+
+    buf_w[1] = 1;
+    buf_w[2] = 2;
+    buf_w[514] = 4;
+    memset(buf_r, 0, sizeof(buf_r));
+
+    ret = qb_write(broker, qbs, buf_w, test_len, test_offset);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("%s.\n", err_str);
+        goto close;
+    }
+
+    ret = qb_read(broker, qbs, buf_r, test_len, test_offset);
+    if (ret < 0) {
+        qb_error_get_human_str(broker, err_str, sizeof(err_str));
+        printf("%s.\n", err_str);
+        goto close;
+    }
+
+    test_check(&vdata);
+
+ close:
+    qb_close(broker, qbs);
+ unlink:
+    unlink(filename1);
+    unlink(filename2);
+ free:
+    if (info_st != NULL) {
+        qb_info_image_static_delete(broker, &info_st);
+    }
+    if (qbs != NULL) {
+        qb_state_delete(broker, &qbs);
+    }
+    if (ol != NULL) {
+        qb_prot_info_delete(broker, &ol);
+    }
+    if (of != NULL) {
+        qb_fmt_info_delete(broker, &of);
+    }
+    if (broker != NULL) {
+        qb_broker_delete(&broker);
+    }
      return 0;
  }
Signature · 3 lines
Best Regards

Wenchao Xia