Discussion:
[PATCH] Fix: check cache before dump it
Chengwei Yang
2013-04-24 08:21:50 UTC
Permalink
Signed-off-by: Chengwei Yang <chengwei.yang-***@public.gmane.org>
---
libkmod/libkmod.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
index 98cf15e..fd91469 100644
--- a/libkmod/libkmod.c
+++ b/libkmod/libkmod.c
@@ -882,9 +882,14 @@ KMOD_EXPORT int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type,
return -ENOENT;

if (ctx->indexes[type] != NULL) {
- DBG(ctx, "use mmaped index '%s'\n", index_files[type].fn);
- index_mm_dump(ctx->indexes[type], fd,
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname,
+ index_files[type].fn);
+ if (!is_cache_invalid(path, ctx->indexes_stamp[type])) {
+ DBG(ctx, "use mmaped index '%s'\n", index_files[type].fn);
+ index_mm_dump(ctx->indexes[type], fd,
index_files[type].prefix);
+ }
} else {
char fn[PATH_MAX];
struct index_file *idx;
--
1.7.9.5
Lucas De Marchi
2013-04-25 04:34:34 UTC
Permalink
Post by Chengwei Yang
---
libkmod/libkmod.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
index 98cf15e..fd91469 100644
--- a/libkmod/libkmod.c
+++ b/libkmod/libkmod.c
@@ -882,9 +882,14 @@ KMOD_EXPORT int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type,
return -ENOENT;
if (ctx->indexes[type] != NULL) {
- DBG(ctx, "use mmaped index '%s'\n", index_files[type].fn);
- index_mm_dump(ctx->indexes[type], fd,
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname,
+ index_files[type].fn);
+ if (!is_cache_invalid(path, ctx->indexes_stamp[type])) {
+ DBG(ctx, "use mmaped index '%s'\n", index_files[type].fn);
+ index_mm_dump(ctx->indexes[type], fd,
index_files[type].prefix);
+ }
why is this any different from the other functions that use the mmaped
index? If the user is not using kmod_validate_resources then it's
better to not call kmod_load_resources() and use the other
implementation that doesn't mmap the index.

Lucas De Marchi

Continue reading on narkive:
Loading...