The criu log can't be flushed to disk when OS crash in storage environment, therefore, output high level msg to /dev/kmsg.
Conflict:NA Reference:https://gitee.com/src-openeuler/criu/pulls/21 Signed-off-by: fu.lin fulin10@huawei.com --- criu/Makefile.crtools | 1 + criu/include/log.h | 2 ++ criu/kmsg.c | 16 ++++++++++++++++ criu/log.c | 4 ++++ 4 files changed, 23 insertions(+) create mode 100644 criu/kmsg.c
diff --git a/criu/Makefile.crtools b/criu/Makefile.crtools index cda5b82..0bea576 100644 --- a/criu/Makefile.crtools +++ b/criu/Makefile.crtools @@ -92,6 +92,7 @@ obj-y += timens.o obj-y += devname.o obj-y += mnl.o obj-y += nftables.o +obj-y += kmsg.o obj-$(CONFIG_HAS_LIBBPF) += bpfmap.o obj-$(CONFIG_COMPAT) += pie-util-vdso-elf32.o CFLAGS_pie-util-vdso-elf32.o += -DCONFIG_VDSO_32 diff --git a/criu/include/log.h b/criu/include/log.h index 58d0123..9556d15 100644 --- a/criu/include/log.h +++ b/criu/include/log.h @@ -72,6 +72,8 @@ void flush_early_log_buffer(int fd); print_on_level(LOG_DEBUG, \ LOG_PREFIX fmt, ##__VA_ARGS__)
+void write_kmsg(const void *buf, size_t count); + #ifndef CR_NOGLIBC
#define pr_perror(fmt, ...) \ diff --git a/criu/kmsg.c b/criu/kmsg.c new file mode 100644 index 0000000..c956dfb --- /dev/null +++ b/criu/kmsg.c @@ -0,0 +1,16 @@ +#include <fcntl.h> +#include <unistd.h> + +#define SYSLOG_DEV "/dev/kmsg" + +void write_kmsg(const void *buf, size_t count) +{ + int fd; + + fd = open(SYSLOG_DEV, O_CLOEXEC | O_WRONLY); + if (fd < 0) + return; + + write(fd, buf, count); + close(fd); +} diff --git a/criu/log.c b/criu/log.c index 439a899..4254f72 100644 --- a/criu/log.c +++ b/criu/log.c @@ -379,6 +379,10 @@ static void vprint_on_level(unsigned int loglevel, const char *format, va_list p size += buf_off;
while (off < size) { + if (loglevel <= LOG_WARN) { + write_kmsg(buffer + off, size - off); + } + ret = write(fd, buffer + off, size - off); if (ret <= 0) break;