From e6c89531c9402107731e5b5ef5c34282ce5967a4 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 31 Jul 2010 19:09:31 +0300 Subject: [PATCH] sync with latest warm --- common/warm.c | 45 ++++++++++++++++++++++++++------------------- common/warm.h | 2 +- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/common/warm.c b/common/warm.c index 7cf22ac..c79c63e 100644 --- a/common/warm.c +++ b/common/warm.c @@ -42,12 +42,15 @@ #define WARM_CODE #include "warm.h" +#define PFX "wARM: " + /* provided by glibc */ extern long init_module(void *, unsigned long, const char *); extern long delete_module(const char *, unsigned int); static int warm_fd = -1; static int kernel_version; +static int module_inserted; static void sys_cacheflush(void *start, void *end) { @@ -93,7 +96,7 @@ static int manual_insmod_26(const char *fname, const char *opts) read_len = fread(buff, 1, len, f); if (read_len != len) { - fprintf(stderr, "failed to read module\n"); + fprintf(stderr, PFX "failed to read module\n"); goto fail1; } @@ -121,7 +124,7 @@ int warm_init(void) uname(&unm); if (strlen(unm.release) < 3 || unm.release[1] != '.') { - fprintf(stderr, "unexpected version string: %s\n", unm.release); + fprintf(stderr, PFX "unexpected version string: %s\n", unm.release); goto fail; } kernel_version = ((unm.release[0] - '0') << 4) | (unm.release[2] - '0'); @@ -136,20 +139,22 @@ int warm_init(void) /* try to insmod */ ret = system(buff2); if (ret != 0) { - fprintf(stderr, "system/insmod failed: %d %d\n", ret, errno); + fprintf(stderr, PFX "system/insmod failed: %d %d\n", ret, errno); if (kernel_version >= 0x26) { ret = manual_insmod_26(buff1, "verbose=1"); if (ret != 0) - fprintf(stderr, "manual insmod also failed: %d\n", ret); + fprintf(stderr, PFX "manual insmod also failed: %d\n", ret); } } + if (ret == 0) + module_inserted = 1; warm_fd = open("/proc/warm", O_RDWR); if (warm_fd >= 0) return 0; fail: - fprintf(stderr, "wARM: can't init, acting as sys_cacheflush wrapper\n"); + fprintf(stderr, PFX "can't init, acting as sys_cacheflush wrapper\n"); return -1; } @@ -164,20 +169,22 @@ void warm_finish(void) close(warm_fd); warm_fd = -1; - if (kernel_version < 0x26) { - struct utsname unm; - memset(&unm, 0, sizeof(unm)); - uname(&unm); - snprintf(name, sizeof(name), "warm_%s", unm.release); - } - else - strcpy(name, "warm"); - - snprintf(cmd, sizeof(cmd), "/sbin/rmmod %s", name); - ret = system(cmd); - if (ret != 0) { - fprintf(stderr, "system/rmmod failed: %d %d\n", ret, errno); - manual_rmmod(name); + if (module_inserted) { + if (kernel_version < 0x26) { + struct utsname unm; + memset(&unm, 0, sizeof(unm)); + uname(&unm); + snprintf(name, sizeof(name), "warm_%s", unm.release); + } + else + strcpy(name, "warm"); + + snprintf(cmd, sizeof(cmd), "/sbin/rmmod %s", name); + ret = system(cmd); + if (ret != 0) { + fprintf(stderr, PFX "system/rmmod failed: %d %d\n", ret, errno); + manual_rmmod(name); + } } } diff --git a/common/warm.h b/common/warm.h index a3fdd6b..1ef5df2 100644 --- a/common/warm.h +++ b/common/warm.h @@ -88,7 +88,7 @@ struct warm_change_cb unsigned long addr; unsigned long size; int cb; - int is_set; + int is_set; /* set (1) or clear (0) */ }; #define WARMC_CACHE_OP _IOW(WARM_IOCTL_BASE, 0, struct warm_cache_op) -- 2.39.5