]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Load and unload resources
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 8 Dec 2011 16:59:51 +0000 (14:59 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 8 Dec 2011 21:51:06 +0000 (19:51 -0200)
This call will mmap all the index files and in future some of the work
done in ctx creation can be put here.

libkmod/libkmod.c
libkmod/libkmod.h
libkmod/libkmod.sym

index 1fb832004d6130aabc7722c368027cf4142a5697..975b4b48c9018eb2a99f97b6ee3647204a53c0ca 100644 (file)
@@ -73,6 +73,7 @@ struct kmod_ctx {
        char *dirname;
        struct kmod_config *config;
        struct kmod_hash *modules_by_name;
+       struct index_mm *indexes[_KMOD_INDEX_LAST];
 };
 
 void kmod_log(const struct kmod_ctx *ctx,
@@ -257,11 +258,15 @@ KMOD_EXPORT struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx)
 
        if (--ctx->refcount > 0)
                return ctx;
+
        INFO(ctx, "context %p released\n", ctx);
+
+       kmod_unload_resources(ctx);
        kmod_hash_free(ctx->modules_by_name);
        free(ctx->dirname);
        if (ctx->config)
                kmod_config_free(ctx->config);
+
        free(ctx);
        return NULL;
 }
@@ -541,3 +546,42 @@ fail:
        *output = NULL;
        return -ENOMEM;
 }
+
+KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx)
+{
+       size_t i;
+
+       if (ctx == NULL)
+               return -ENOENT;
+
+       for (i = 0; i < ARRAY_SIZE(index_files); i++) {
+               if (ctx->indexes[i] == NULL) {
+                       const char *fn = index_files[i];
+
+                       ctx->indexes[i] = index_mm_open(ctx, fn, true);
+                       if (ctx->indexes[i] == NULL)
+                               goto fail;
+               }
+       }
+
+       return 0;
+
+fail:
+       kmod_unload_resources(ctx);
+       return -ENOMEM;
+}
+
+KMOD_EXPORT void kmod_unload_resources(struct kmod_ctx *ctx)
+{
+       size_t i;
+
+       if (ctx == NULL)
+               return;
+
+       for (i = 0; i < ARRAY_SIZE(index_files); i++) {
+               if (ctx->indexes[i] != NULL) {
+                       index_mm_close(ctx->indexes[i]);
+                       ctx->indexes[i] = NULL;
+               }
+       }
+}
index 11cd9b97e78f593ebfe18c051fecb45762af9607..4bff2a31fbc20e2d9e21ff1fc2fd7eb95a7a2475 100644 (file)
@@ -48,6 +48,8 @@ int kmod_get_log_priority(const struct kmod_ctx *ctx);
 void kmod_set_log_priority(struct kmod_ctx *ctx, int priority);
 void *kmod_get_userdata(const struct kmod_ctx *ctx);
 void kmod_set_userdata(struct kmod_ctx *ctx, const void *userdata);
+int kmod_load_resources(struct kmod_ctx *ctx);
+void kmod_unload_resources(struct kmod_ctx *ctx);
 
 /*
  * kmod_list
index 1b46c918359c1755b4a61bd22e7cefe63d2e011b..0487ff8ee86d87d72d13689c5986854d7057b908 100644 (file)
@@ -13,6 +13,9 @@ global:
        kmod_list_prev;
        kmod_loaded_get_list;
 
+       kmod_load_resources;
+       kmod_unload_resources;
+
        kmod_module_new_from_name;
        kmod_module_new_from_path;
        kmod_module_new_from_lookup;
@@ -21,7 +24,6 @@ global:
        kmod_module_unref_list;
        kmod_module_remove_module;
        kmod_module_insert_module;
-
        kmod_module_get_dependencies;
        kmod_module_get_module;
 
@@ -37,9 +39,7 @@ global:
        kmod_module_section_free_list;
        kmod_module_section_get_name;
        kmod_module_section_get_address;
-
        kmod_module_get_holders;
-
        kmod_module_get_size;
 local:
         *;