Skip to contentSkip to conversation

block: Fix libbz2 library dependency regresssion

PATCH Superseded Fam Zheng 1 participant 5 messages Aug 16, 2016 Block layer

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

v2 cover block: Fix libbz2 library dependency regresssion

v2: Rebase on top of Max's block-next tree, which has Colin's patches to
dynamically load block modules.
Two more tweaks to the module system is added.

v1 was submitted as a single patch:

https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg00508.html

Fam Zheng (3):
scripts: Allow block module to not define BlockDriver
module: Don't load the same module if requested multiple times
dmg: Move libbz2 code to dmg-bz2.so

 block/Makefile.objs             |  3 +-
 block/dmg-bz2.c                 | 62 ++++++++++++++++++++++++++++++++++++
 block/dmg.c                     | 69 ++++++++++-------------------------------
 block/dmg.h                     | 59 +++++++++++++++++++++++++++++++++++
 scripts/modules/module_block.py |  5 ---
 util/module.c                   | 19 ++++++++++--
 6 files changed, 157 insertions(+), 60 deletions(-)
 create mode 100644 block/dmg-bz2.c
 create mode 100644 block/dmg.h
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 1/3 scripts: Allow block module to not define BlockDriver

---
 scripts/modules/module_block.py | 5 -----
 1 file changed, 5 deletions(-)
scripts/modules/module_block.py +0 -5
index db4fb54..7efec00 100644
@@ -56,11 +56,6 @@ def process_file(fheader, filename):
                 format_name = ""
                 protocol_name = ""
 
-        if not found_something:
-            print("No BlockDriver struct found in " + filename + ". \
-                    Is this really a module?", file=sys.stderr)
-            sys.exit(1)
-
 def print_top(fheader):
     fheader.write('''/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
 /*
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v2 2/3 module: Don't load the same module if requested multiple times

In reply to Fam Zheng

Use a hash table to keep record of all loaded modules, and return early if the requested module is already loaded.

---
 util/module.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
util/module.c +17 -2
index a5f7fbd..63efad6 100644
@@ -163,14 +163,29 @@ void module_load_one(const char *prefix, const char *lib_name)
     char *fname = NULL;
     char *exec_dir;
     char *dirs[3];
+    char *module_name;
     int i = 0;
     int ret;
+    static GHashTable *loaded_modules;
 
     if (!g_module_supported()) {
         fprintf(stderr, "Module is not supported by system.\n");
         return;
     }
 
+    if (!loaded_modules) {
+        loaded_modules = g_hash_table_new(g_str_hash, g_str_equal);
+    }
+
+    module_name = g_strdup_printf("%s%s", prefix, lib_name);
+
+    if (g_hash_table_lookup(loaded_modules, module_name)) {
+        fprintf(stderr, "module is already loaded: %s\n", module_name);
+        g_free(module_name);
+        return;
+    }
+    g_hash_table_insert(loaded_modules, module_name, module_name);
+
     exec_dir = qemu_get_exec_dir();
     dirs[i++] = g_strdup_printf("%s", CONFIG_QEMU_MODDIR);
     dirs[i++] = g_strdup_printf("%s/..", exec_dir ? : "");
@@ -180,8 +195,8 @@ void module_load_one(const char *prefix, const char *lib_name)
     exec_dir = NULL;
 
     for (i = 0; i < ARRAY_SIZE(dirs); i++) {
-        fname = g_strdup_printf("%s/%s%s%s",
-                dirs[i], prefix, lib_name, HOST_DSOSUF);
+        fname = g_strdup_printf("%s/%s%s",
+                dirs[i], module_name, HOST_DSOSUF);
         ret = module_load_file(fname);
         g_free(fname);
         fname = NULL;
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v2 3/3 dmg: Move libbz2 code to dmg-bz2.so

In reply to Fam Zheng

dmg.o was moved to block-obj-m in 5505e8b76 to become a separate module, so that its reference to libbz2, since 6b383c08c, doesn't add an extra library to the main executable.

Until recently, commit 06e60f70a (blockdev: Add dynamic module loading for block drivers) moved it back to block-obj-y to simplify the design of dynamic loading of block modules. But we don't want to lose the feature of less library dependency on the main executable.

The solution here is to move only the bz2 related code to a separate DSO file, and load it when dmg_open is called.

dmg_probe doesn't depend on bz2 support to work, and is the only code in this file which can run before dmg_open.

---
 block/Makefile.objs |  3 ++-
 block/dmg-bz2.c     | 62 +++++++++++++++++++++++++++++++++++++++++++++++
 block/dmg.c         | 69 +++++++++++++----------------------------------------
 block/dmg.h         | 59 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 140 insertions(+), 53 deletions(-)
 create mode 100644 block/dmg-bz2.c
 create mode 100644 block/dmg.h
block/Makefile.objs +2 -1
index fa4d8b8..141dec5 100644
@@ -40,6 +40,7 @@ gluster.o-libs     := $(GLUSTERFS_LIBS)
 ssh.o-cflags       := $(LIBSSH2_CFLAGS)
 ssh.o-libs         := $(LIBSSH2_LIBS)
 archipelago.o-libs := $(ARCHIPELAGO_LIBS)
-dmg.o-libs         := $(BZIP2_LIBS)
+block-obj-$(if $(CONFIG_BZIP2),m,n) += dmg-bz2.o
+dmg-bz2.o-libs     := $(BZIP2_LIBS)
 qcow.o-libs        := -lz
 linux-aio.o-libs   := -laio
block/dmg-bz2.c new file +62 -0

62 lines not on this page · raw message

block/dmg.c +17 -52

115 lines not on this page · raw message

block/dmg.h new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#4 lore raw

Re: [Qemu-devel] [PATCH for-2.8 v2 3/3] dmg: Move libbz2 code to dmg-bz2.so

Quoted 19 lines · Fam Zheng
block/Makefile.objs +2 -1
index fa4d8b8..141dec5 100644
@@ -40,6 +40,7 @@ gluster.o-libs     := $(GLUSTERFS_LIBS)
 ssh.o-cflags       := $(LIBSSH2_CFLAGS)
 ssh.o-libs         := $(LIBSSH2_LIBS)
 archipelago.o-libs := $(ARCHIPELAGO_LIBS)
-dmg.o-libs         := $(BZIP2_LIBS)
+block-obj-$(if $(CONFIG_BZIP2),m,n) += dmg-bz2.o
+dmg-bz2.o-libs     := $(BZIP2_LIBS)
 qcow.o-libs        := -lz
 linux-aio.o-libs   := -laio
block/dmg-bz2.c new file +0 -0
new file mode 100644
index 0000000..a60e398

block/dmg-bz2.c line 5

Quoted 5 lines
block/dmg-bz2.c new file +5 -0
@@ -0,0 +1,62 @@
+/*
+ * DMG bzip2 uncompression
+ *
+ * Copyright (c) 2004 Johannes E. Schindelin
+ * Copyright (c) 2016 Red Hat, Int.

Apparently I forgot to address Max's comments on v1. :(

Fam