From 33bb69b94329646748d6d362c39387ddaad6b7d6 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Thu, 8 Dec 2011 14:59:51 -0200 Subject: [PATCH] Load and unload resources 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 | 44 ++++++++++++++++++++++++++++++++++++++++++++ libkmod/libkmod.h | 2 ++ libkmod/libkmod.sym | 6 +++--- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index 1fb83200..975b4b48 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -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; + } + } +} diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index 11cd9b97..4bff2a31 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -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 diff --git a/libkmod/libkmod.sym b/libkmod/libkmod.sym index 1b46c918..0487ff8e 100644 --- a/libkmod/libkmod.sym +++ b/libkmod/libkmod.sym @@ -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: *; -- 2.39.5